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 accesskey Attribute
Photo Credit to CodeToFun
🙋 Introduction
The accesskey
attribute is a valuable feature in HTML that provides a way to define keyboard shortcuts for accessing specific elements on a web page.
By assigning a key or combination of keys to an element, users can quickly navigate to that element, improving accessibility and user experience.
🎯 Purpose of accesskey
The primary purpose of the accesskey
attribute is to enhance the accessibility of a web page by allowing users to navigate to important elements using keyboard shortcuts.
This is particularly beneficial for users with mobility issues who may find it challenging to use a mouse for navigation.
💎 Values
The accesskey
attribute accepts single-character values, typically representing a letter or a number. These values are used as the access key that, when combined with a browser-specific modifier key, triggers the associated element.
📄 Example
Let's explore a simple example of how to use the accesskey
attribute in an HTML document:
<button accesskey="h">Home</button>
<button accesskey="a">About</button>
<button accesskey="c">Contact</button>
🧠 How it Works
In this example, each button is assigned a different access key: "h" for Home, "a" for About, and "c" for Contact. Users can activate these buttons by pressing the designated access key in combination with a browser-specific modifier key.
🔄 Dynamic Values with JavaScript
Similar to other HTML attributes, you can dynamically set the accesskey
attribute using JavaScript. This allows you to modify keyboard shortcuts based on user preferences or dynamic content changes. Here's a brief example:
<script>
// Dynamically set accesskey for an element
document.getElementById("dynamicElement").accessKey = "p";
</script>
🧠 How it Works
In this script, the accesskey
attribute is dynamically set to "p" for an element with the id "dynamicElement." This flexibility can be useful when you want to adapt keyboard shortcuts based on user interactions or changes in the content structure.
🏆 Best Practices
- Use the
accesskey
attribute thoughtfully, assigning keys that are intuitive and easy to remember. - Avoid using common keys that might conflict with browser or system shortcuts.
- Provide a clear indication of the assigned access keys, such as displaying them in tooltips or documentation.
- Be aware that the effectiveness of keyboard shortcuts may vary across different browsers, so it's essential to test and ensure consistent behavior.
🎉 Conclusion
The accesskey
attribute is a powerful tool for improving the accessibility and usability of web pages.
By incorporating keyboard shortcuts, you can make navigation more efficient for users, particularly those with disabilities or those who prefer using the keyboard over the mouse.
👨💻 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 accesskey Attribute), please comment here. I will help you immediately.