Accessible display:none Solutions

PHOTO EMBED

Wed Dec 28 2022 15:01:03 GMT+0000 (Coordinated Universal Time)

Saved by @sarah__codes #css #html

/* "The "clip pattern" accomplishes this task for you; hide the content visually, yet provide the content to screen readers." */

.visually-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

/* For a, button, and input elements use the following to select on focus */

.visually-hidden:not(:focus):not(:active) {
  /* ... */
}

/* If you need to toggle something with display:none, you can do so with the help of aria-hidden=true */

.my-component[aria-hidden="true"] {
  display: none;
}
content_copyCOPY

Notes from the article on the a11yproject website

https://www.a11yproject.com/posts/how-to-hide-content/