HTML Basic
HTML Reference
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Attributes
- accept
- accept-charset
- accesskey
- action
- align
- alt
- as
- async
- autocomplete
- autofocus
- autoplay
- bgcolor
- border
- charset
- checked
- cite
- class
- color
- cols
- colspan
- content
- contenteditable
- controls
- coords
- data
- data-*
- datetime
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- headers
- height
- hidden
- high
- href
- hreflang
- http-equiv
- id
- inert
- inputmode
- ismap
- kind
- label
- lang
- list
- loop
- low
- max
- maxlength
- media
- method
- min
- multiple
- muted
- name
- novalidate
- onabort
- onafterprint
- onbeforeprint
- onbeforeunload
- onblur
- oncanplay
- oncanplaythrough
- onchange
- onclick
- oncontextmenu
- oncopy
- oncuechange
- oncut
- ondblclick
- ondrag
- ondragend
- ondragenter
- ondragleave
- ondragover
- ondragstart
- ondrop
- ondurationchange
- onemptied
- onended
- onerror
- onfocus
- onhashchange
- oninput
- oninvalid
- onkeydown
- onkeypress
- onkeyup
- onload
- onloadeddata
- onloadedmetadata
- onloadstart
- onmousedown
- onmousemove
- onmouseout
- onmouseover
- onmouseup
- onmousewheel
- onoffline
- ononline
- onpagehide
- onpageshow
- onpaste
- onpause
- onplay
- onplaying
- onpopstate
- onprogress
- onratechange
- onreset
- onresize
- onscroll
- onsearch
- onseeked
- onseeking
- onselect
- onstalled
- onstorage
- onsubmit
- onsuspend
- ontimeupdate
- ontoggle
- onunload
- onvolumechange
- onwaiting
- onwheel
- open
- optimum
- pattern
- placeholder
- popover
- popovertarget
- popovertargetaction
- poster
- preload
- readonly
- rel
- required
- reversed
- rows
- rowspan
- sandbox
- scope
- selected
- shape
- size
- sizes
- span
- spellcheck
- src
- srcdoc
- srclang
- srcset
- start
- step
- style
- tabindex
- target
- title
- translate
- type
- usemap
- value
- width
- wrap
- HTML Global Attributes
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML scrolling Attribute
Photo Credit to CodeToFun
🙋 Introduction
The scrolling
attribute in HTML is used with the <iframe> element to control the scrollbar visibility. This attribute helps developers decide whether scrollbars should be visible or hidden within an iframe, thereby improving the user's viewing experience.
Although this attribute is considered obsolete in HTML5, it is still supported by some browsers for backward compatibility.
🎯 Purpose of scrolling
The scrolling
attribute specifies whether an <iframe> should have scrollbars. This can be particularly useful when embedding content that might be larger than the available viewing area within the iframe. By managing scrollbar visibility, you can control the layout and aesthetics of your embedded content.
💎 Values
The scrolling
attribute accepts the following values:
- yes: This value ensures that scrollbars are always visible in the iframe, regardless of whether they are needed to view the content.
- no: This value hides the scrollbars, even if the content within the iframe overflows the viewing area.
- auto: This value allows the browser to decide whether to show scrollbars based on the content's size. Scrollbars will appear only if the content overflows.
📄 Implementation Example:
Here's a simple example demonstrating how to use the scrolling
attribute in an HTML iframe:
<iframe src="https://example.com" width="600" height="400" scrolling="yes"></iframe>
🧠 How it Works
In this example, the scrolling
attribute is set to "yes," ensuring that scrollbars are always visible within the iframe.
🔄 Dynamic Values with JavaScript
You can dynamically set or change the scrolling
attribute using JavaScript. This can be useful for creating a more interactive user experience, where the scrollbar visibility can change based on user actions or other conditions. Here's how you can do it:
<script>
// Dynamically set scrolling for an iframe
document.getElementById("myIframe").setAttribute("scrolling", "auto");
</script>
🧠 How it Works
In this script, the scrolling
attribute is set to "auto" for an iframe with the id "myIframe." This allows the browser to decide the scrollbar visibility based on the content size dynamically.
🏆 Best Practices
- Although the
scrolling
attribute is still supported by some browsers, consider using CSS for controlling overflow and scrollbar behavior in modern web development. The CSS overflow property can provide more flexibility and is widely supported. - When using the
scrolling
attribute, ensure that the embedded content and the iframe dimensions are appropriately sized to provide a good user experience. - Test your iframes across different browsers to ensure consistent behavior, as support for obsolete attributes like scrolling can vary.
🎉 Conclusion
The scrolling
attribute is a useful tool for managing scrollbar visibility within iframes in HTML. While it is considered obsolete in HTML5, understanding its usage and how to control scrollbar behavior dynamically with JavaScript can still be beneficial for certain scenarios.
By applying best practices and considering modern alternatives like CSS, you can create better and more responsive web designs.
👨💻 Join our Community:
Author
For over eight years, I worked as a full-stack web developer. Now, I have chosen my profession as a full-time blogger at codetofun.com.
Buy me a coffee to make codetofun.com free for everyone.
Buy me a Coffee
If you have any doubts regarding this article (HTML scrolling Attribute), please comment here. I will help you immediately.