HTML Topics
- HTML Intro
- HTML Basic
- HTML Editors
- HTML CSS
- HTML Tags
- HTML Deprecated Tags
- HTML Events
- HTML Event Attributes
- HTML Global Attributes
- HTML Attributes
- abbr
- accept
- accept-charset
- accesskey
- action
- align
- alt
- archive
- as
- async
- autocapitalize
- autocomplete
- autofocus
- autoplay
- axis
- bgcolor
- border
- cellpadding
- cellspacing
- char
- charoff
- charset
- checked
- cite
- class
- classid
- codebase
- codetype
- color
- cols
- colspan
- compact
- content
- contenteditable
- controls
- coords
- crossorigin
- data
- data-*
- datetime
- declare
- default
- defer
- dir
- dirname
- disabled
- download
- draggable
- enctype
- enterkeyhint
- for
- form
- formaction
- formenctype
- formmethod
- formnovalidate
- formtarget
- frame
- frameborder
- frameset
- headers
- height
- hidden
- high
- href
- hreflang
- hspace
- 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 Comments
- HTML Entity
- HTML Head
- HTML Form
- HTML IndexedDB
- HTML Drag & Drop
- HTML Geolocation
- HTML Canvas
- HTML Status Code
- HTML Language Code
- HTML Country Code
- HTML Charset
- MIME Types
HTML controls Attribute
Photo Credit to CodeToFun
🙋 Introduction
The controls
attribute is a valuable feature in HTML that allows developers to enhance the user interface and functionality of multimedia elements, such as audio and video.
By leveraging the controls
attribute, you can provide users with built-in playback controls, making it easier for them to interact with multimedia content embedded in your web pages.
🎯 Purpose of controls
The primary purpose of the controls
attribute is to enable or disable the default user interface controls for multimedia elements.
When the controls
attribute is present, users can play, pause, adjust volume, and perform other playback-related actions directly from the embedded media player.
💎 Values
The controls
attribute accepts a boolean value:
- controls="controls": This value enables the default user interface controls for the multimedia element.
- controls="false" or controls="": This value disables the default controls, allowing developers to implement custom controls using JavaScript or other methods.
📄 Example
Let's look at a simple example of how to use the controls
attribute for an HTML <video> element:
<video controls="controls" width="400" height="300">
<source src="example.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
🧠 How it Works
In this example, the controls
attribute is set to controls, enabling the default video player controls for better user interaction.
🔄 Dynamic Values with JavaScript
Similar to other HTML attributes, you can dynamically set the controls
attribute using JavaScript. For instance:
<script>
// Dynamically set controls for a video element
document.getElementById("dynamicVideo").controls = true;
</script>
🧠 How it Works
In this script, the controls
attribute is dynamically set to true for a video element with the id dynamicVideo.
This can be beneficial when you want to control the display of controls based on certain user interactions or conditions.
🏆 Best Practices
- Use the
controls
attribute when you want to provide users with a standard set of playback controls for multimedia elements. - Consider disabling default controls if you plan to implement a custom multimedia player with JavaScript.
- Always ensure your multimedia files are in widely supported formats to provide a consistent user experience across different browsers.
🎉 Conclusion
The controls
attribute is a valuable tool for enhancing the usability of multimedia elements in HTML.
By utilizing this attribute, you can provide users with a familiar and convenient way to interact with audio and video content embedded in your web pages.
👨💻 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 controls Attribute), please comment here. I will help you immediately.