Skip to content

Instantly share code, notes, and snippets.

@Lelith
Created May 7, 2021 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Lelith/b856e8fe36cb69d07f59029c70795baa to your computer and use it in GitHub Desktop.
Save Lelith/b856e8fe36cb69d07f59029c70795baa to your computer and use it in GitHub Desktop.
How to make images accessible.
// image with a descriptive alternative text, helps users to understand what is on the picture
<img src='cat.jpg' alt="a cat playful laying on its back" />
// image for decorative purpose which adds unnecessary information
// Screenreaders will read this as "image, Dashboard Logo, My Dashboard"
<div>
<img src="dashboard_black_24dp.svg" alt="Dashboard Logo" />My Dashboard
</div>
// just removing the alt-tag is not helpful either
// Screenreaders will read this as "Image without title, dashboard black 24p, My Dashbaord"
<div>
<img src="dashboard_black_24dp.svg" />My Dashboard
</div>
// Hide non-descriptive images via inline pasting or aria-attribute
<div>
<svg>...</svg> My Dashboard
</div>
<div>
<img src="dashboard_black_24dp.svg" aria-hidden="true" /> My Dashboard
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment