Finding the Currently Focused Element

When doing accessibility audits (or even daily web use), too often I come across sites that are missing focus styles. When navigating via keyboard, it can be difficult to see which element you are currently on and hence, lose sight of where y…


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream

When doing accessibility audits (or even daily web use), too often I come across sites that are missing focus styles. When navigating via keyboard, it can be difficult to see which element you are currently on and hence, lose sight of where you are on a page.

To quickly find the currently focused element, we can use the activeElement read-only property of the Document interface. Despite its rather confusing name, it does return the focused element.

To use it, open the DevTools Console (cmd + i, then ESC, or click the Console tab) and type the following, short command:

document.activeElement;

This will give you an instant preview of the focused element name. Press Enter and Console will expand the output and return the currently focused element, including its content. You can then hover the Console output to see the highlighted element in the browser window.

The next time you are styling focusable elements, aka links, buttons or form fields, it‘s a great idea to take the extra time to add visible :focus styles. It can also look great and will show the care of your craft. It will make navigating pages more usable and enjoyable, especially when relying on visible focus styles for navigation.


This content originally appeared on foobartel.com :: Stream and was authored by foobartel.com :: Stream


Print Share Comment Cite Upload Translate Updates
APA

foobartel.com :: Stream | Sciencx (2022-01-02T23:00:00+00:00) Finding the Currently Focused Element. Retrieved from https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/

MLA
" » Finding the Currently Focused Element." foobartel.com :: Stream | Sciencx - Sunday January 2, 2022, https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/
HARVARD
foobartel.com :: Stream | Sciencx Sunday January 2, 2022 » Finding the Currently Focused Element., viewed ,<https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/>
VANCOUVER
foobartel.com :: Stream | Sciencx - » Finding the Currently Focused Element. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/
CHICAGO
" » Finding the Currently Focused Element." foobartel.com :: Stream | Sciencx - Accessed . https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/
IEEE
" » Finding the Currently Focused Element." foobartel.com :: Stream | Sciencx [Online]. Available: https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/. [Accessed: ]
rf:citation
» Finding the Currently Focused Element | foobartel.com :: Stream | Sciencx | https://www.scien.cx/2022/01/02/finding-the-currently-focused-element/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.