#17 inaccessible cards

submitted on by Šime

Context: A list of linked cards, each with heading, image, and teaser text.

Bad code

<figure class="card" data-url="image1.html" style="background: url(image1.jpg)">
<h4>My heading</h4>
<figure class="card" data-url="image2.html" style="background: url(image2.jpg)"></figure>

Issues and how to fix them

  1. You might not need (so many) <section>s. Read Why You Should Choose HTML5 <article> Over <section> by Bruce Lawson for more details.
  2. Heading levels shouldn’t be skipped. Screen reader users rely on a sound document outline and hierarchy. It helps with navigation and understanding how the page is structured.
  3. The figure element represents content, optionally with a caption, that is self-contained, but in this example there’s no content, only a caption.
  4. The image in a card usually isn’t decorative, it conveys information. It should be part of the HTML document and not added via CSS. Background images are not accessible to everyone.
  5. The card is only linked via JavaScript. If there’s no proper HTML anchor (<a href="path/to/page">), the “link” is inaccessible to screen reader and keyboard users.
  6. The <h1> - <h6> elements represent introductory headings for their sections. The <h4> is flow content and thus technically allowed as a descendent of figcaption, but it’s better to use it to introduce the card as a whole.
  7. The article element represents a self-contained composition in a page or site. This could be a newspaper article, an essay or report, a blog or other social media post. For a simple paragraph use <p>.
  8. Making accessible cards where the whole card is clickable isn’t easy. Read the articles in the resources section for more information.

Good code

<article class="card">
<a href="image1.html"> My heading </a>
<img src="image1.jpg" alt="Description of image1" />
<article class="card"></article>