Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for A11y tips: hide elements for all users
Carlos Espada
Carlos Espada

Posted on • Edited on

     

A11y tips: hide elements for all users

To hide content for all users (sighted, screen reader and keyboard) there are several techniques that we can use with some differences between them:

HTML attributehidden

The item and everything it contains is removed from view for the user, from the accessibility tree, and from the tab order.It's as if it doesn't exist in HTML: you can't see it, the screen reader doesn't announce anything, and you can't tab to it.

AsMonica Dinculescu points out, using thehidden attribute to hide an element can cause problems when interacting with our CSS, but at the same time she proposes a solution.

<div hidden>  <p>This content won't be shown</p></div>
Enter fullscreen modeExit fullscreen mode

CSSdisplay: none

It has the same effect as the previous one, with the only difference that herewe need the CSS to be loaded so that the element is hidden, while with thehidden attribute the element will never be shown no matter there is CSS.

<div>  <p>This content won't be shown</p></div>
Enter fullscreen modeExit fullscreen mode

CSSvisibility: hidden

The effect is the same as the previous ones with the difference that herethe element is hidden from sighted users but maintaining its dimensions (width andheight), with which an empty space appears that does not show anything, neither the element nor its content.

<div>  <p>This content won't be shown but it'll take up space</p></div>
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Front-end developer. Cyclist. Fan of trains, dinos and XIX century travels. Trying to do my part for making an accessible, light and fast internet for everyone.
  • Location
    Madrid, Spain
  • Work
    Front-end developer at Product Hackers
  • Joined

More fromCarlos Espada

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp