-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: decorative/informative img (#30)
* feat: adds decorative image section separate from informative - edits a few examples - renames filenames * feat: adds demo page for testing decorative img (this is only for the purposes of testing and deciding on if aria-hidden should be included in the write up. delete these files when we come to consensus). * fix: edit a couple sentences * feat: edits a bit of the entries and adds a demo for images decorative - removes src file svg hack role="img" as it is no longer needed https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html#:~:text=Updated%3A%20Image%20elements%20with%20SVG%20source%20exception - adds demo for image decorative - edits some wording in images decorative/informative * fix: a couple edits to markdown language * fix: edit decorative image demo entry and classes * Making edits to simplify and make extendable * Consolidated margin * Update _images.scss --------- Co-authored-by: charlietriplett <charlie@charliecharliecharlie.com>
- Loading branch information
Showing
8 changed files
with
159 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ CNAME | |
Icon[ | ||
] | ||
.DS_Store | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
--- | ||
layout: entry | ||
title: "Decorative image" | ||
description: "How to code and test accessible decorative images (jpg, gif, png, svg)" | ||
categories: main | ||
|
||
keyboard: | ||
arrow-keys: | | ||
Screenreader ignores the image completely | ||
mobile: | ||
swipe: | | ||
The screenreader ignores the image completely | ||
screenreader: | ||
role: | | ||
The image is ignored | ||
gherkin-keyboard: | ||
- when: | | ||
the arrow keys to browse to an image | ||
result: | | ||
the image is skipped and ignored | ||
gherkin-mobile: | ||
- when: | | ||
swipe to browse to an image | ||
wcag: | ||
- name: Perceivable | ||
list: | ||
- criteria: All non-text content that is purely for decoration or which repeats existing on-screen text nearby should be ignored and skipped over by screenreaders. | ||
--- | ||
|
||
## Decorative images | ||
|
||
There are times that images shouldn't be read because it would be repetitive or not add any value in addition to the existing page content. These types of images are generally included for purely stylistic purposes and don't impart any meaning to the rest of the content on the page. | ||
|
||
## Is this image decorative or informative? | ||
If the image conveys important meaning, and there's no other text on the page which explains the concept within it, then the image is likely informative. In this case, check out the [informative image checklist](/checklist-web/image) item instead. | ||
|
||
If your image contains text inside it, it should not! This is a violation of [WCAG AA 1.4.5 Images of Text](https://www.w3.org/WAI/WCAG21/Understanding/images-of-text.html). Exceptions exist for logos. | ||
|
||
## The alt attribute is still required | ||
|
||
- To have valid HTML, the `alt` attribute must still be present, even when set to the empty empty value of `alt`. Note that `alt` and `alt=""` (no space) are equivalent in HTML. | ||
- When the `alt` attribute is empty, the screen reader ignores it (and will not read anything). | ||
- When the `alt` attribute is missing, the screen reader will read the `src` name or filename of the image which is a very poor user experience. | ||
|
||
## Reinforce decorative images with aria-hidden | ||
|
||
- Use `aria-hidden="true"` as a backup and reinforcement to `alt`: | ||
- Backup: **developers often mistakenly omit the alt attribute entirely**, meaning that some screenreaders will read the entire filename without an alt attribute. Including `aria-hidden="true"` will act as a backup. | ||
- Reinforcement: using `aria-hidden="true"` ensures that screenreaders ignores the image. Screenreaders have been observed reading an image role even when the alt attribute is empty. | ||
|
||
<example> | ||
{% include /examples/image-decorative.html %} | ||
</example> | ||
|
||
{% highlight html %} | ||
{% include /examples/image-decorative.html %} | ||
{% endhighlight %} | ||
|
||
## Using inline SVG | ||
|
||
### Inline SVG that conveys meaning | ||
|
||
Inline SVGs require some special code to be hidden properly from screen readers: | ||
- `aria-hidden="true"` | ||
|
||
If you are using a `<use />` element, add `aria-hidden="true"`. | ||
|
||
### Inline SVG that is decorative | ||
{% highlight html %} | ||
<svg aria-hidden="true" focusable="false"> | ||
<use href="#svg-id" aria-hidden="true" /> | ||
<!-- if not using <use> then the child elements | ||
of the inline SVG would go here --> | ||
</svg> | ||
{% endhighlight %} | ||
|
||
## Further reading | ||
- This page owes a lot to this exhaustive blog post: [Contextually Marking up accessible images and SVGs by Scott O'Hara](https://www.scottohara.me/blog/2019/05/22/contextual-images-svgs-and-a11y.html) | ||
- [W3C Image decision tree](https://www.w3.org/WAI/tutorials/images/decision-tree/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
layout: demo | ||
title: "Decorative Image" | ||
--- | ||
|
||
{::nomarkdown} | ||
{% include /examples/image-decorative.html %} | ||
{:/} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h3 class="h-charlie decorated"> | ||
<img | ||
src="/assets/images/icons/icon-info.svg" | ||
aria-hidden="true" | ||
class="icon" | ||
alt /> | ||
Note: Your plan might be changing soon. | ||
</h3> | ||
<a | ||
href="tel:8888888888" | ||
class="decorated"> | ||
<img | ||
src="/assets/images/icons/icon-phone.svg" | ||
aria-hidden="true" | ||
class="icon" | ||
alt /> | ||
Call us: 888-888-8888 | ||
</a> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.