Logo of the site

My cheatsheet

A11Y cheatsheet

This is a quick reference cheat sheet for understanding and writing A11Y files.

# Accessibility

Accessibility Overview

Accessibility ensures digital content is usable by individuals with disabilities or sensory impairments. It follows standards like the Web Content Accessibility Guidelines (WCAG) 2.1.

  • Screen readers to parse and vocalize web content for visually impaired users.
  • Closed captions for videos to support hearing-impaired users.
  • Descriptive alt attributes for images to convey meaning without visuals.
  • Full keyboard navigation (e.g., using the Tab key) for users unable to operate a mouse.

Contrast

Proper contrast improves page navigation, draws user attention, and ensures accessibility for users with vision impairments.

To enhance accessibility through contrast, focus on:

  • Headings: Distinguish sections clearly with size, weight, and spacing.
  • Font choices: Use readable, high-clarity fonts with strong foreground-background separation.
  • Color: Ensure sufficient color contrast ratios, following WCAG 2.1 guidelines.

Headings

HTML defines six heading elements (<h1> to <h6>), decreasing in importance and size from h1 to h6.

Purpose

  • Divide content into structured sections.
  • Create visual contrast for better readability.
  • Provide navigation and context to browsers, plugins, and assistive technologies (e.g., screen readers).

Best Practices

  • Use heading elements in logical order without skipping levels.
  • Each page should have exactly one <h1> that defines the page’s main purpose.
  • Place important keywords inside <h1> to improve SEO relevance.
  • Use <h2> for sibling sections of the page content.

Font Accessibility

Accessible websites use real text, ensure high contrast, and choose legible font sizes to optimize readability and compatibility with assistive technologies.

Real Text vs Text in Images

  • Screen readers can interpret real text.
  • Users can scale text without loss of quality.
  • Faster loading compared to image-based text.

Contrast Ratios

Follow WCAG 2.1 guidelines:

  • Minimum 4.5:1 contrast ratio for standard text.
  • Minimum 3:1 contrast ratio for large text (24px or larger).
  • Use tools like the WebAIM Contrast Checker to verify compliance.

Font Sizes

  • Default browser font size: 16px (recommended for body text).
  • Smaller fonts only for nonessential or aesthetic content.

Color Accessibility

Choosing accessible color combinations ensures that content remains readable and understandable for users with vision impairments or color vision deficiencies.

High Contrast

Maximum contrast (e.g., black #000000 on white #ffffff) improves readability but can cause eye strain over time. Moderate contrast is often preferable for prolonged reading.

Color Blindness

Red-green color blindness is the most common, but blue-yellow deficiency and total color blindness also exist. Colors can appear differently or become indistinguishable.

Best Practices

  • Choose highly contrasting colors (opposites on a color wheel).
  • Use brightness variation within the same color family (e.g., light blue vs dark blue).
  • Pair color with other indicators (text, icons) — never rely on color alone to convey essential information.

Use tools like the Toptal Color Blind Web Page Filter to test your designs for different types of color blindness.

Accessibility: Best Practices

Design trends should never compromise accessibility. Always prioritize clarity, contrast, and compatibility with assistive technologies.

Text Over Images

Overlaying white text on images often fails contrast standards. Use a dark transparent overlay behind the text to improve legibility.

Input Labels

Do not rely on placeholder text alone to identify input fields. Labels are essential for screen readers and users with low vision. Placeholder text is often low contrast and may not be read aloud.

Buttons and Links

Flat/minimal designs can reduce clarity. Ensure buttons and links are visually distinct with borders, icons, or underlines — not color alone — to ensure clickability is clear for all users.

Semantic HTML Elements

Using semantic elements helps screen reader users understand and navigate a web page more efficiently. For example, wrap a navigation bar in a <header> instead of a generic <div> with a class.

<header>
<nav>
...
</nav>
</header>

# ARIA

Role

The role attribute provides additional context to web elements, affecting how screen readers announce them

ARIA role

Role: presentation

Some elements, such as <ol> and <div>, are used solely for organizing content. Setting role="presentation" instructs screen readers to skip announcing the element’s name, allowing users to focus directly on the meaningful content.

<ol role="presentation">
<li>List Item 1</li>
<li>List Item 2</li>
</ol>

In the example below, the container’s role prevents unnecessary announcements:

<div id="container" role="presentation">
<p>I'm content you want to hear!</p>
</div>

ARIA role

Role: complementary

The complementary role signals that the content supports the primary information on the page.

<div id="code-editor" role="complementary">
...
</div>

ARIA role

Property: aria-label

Gives screen readers extra information without affecting the visual layout

<img src="#" alt="A painting of the Shenandoah Valley" />
<p aria-label="Artist">Armand Cabrera, 2010</p>

This enhances the relationship between the image and its caption. For a full list of ARIA properties, see the ARIA Techniques.

ARIA property

Alt Attribute

The alt attribute is vital for accessibility, providing a text alternative to images. Screen readers announce this text, and it is displayed if the image fails to load.

<img src="#" alt="a kitten snuggling a puppy" />
  • Concise Description: Summarize the image content in a few words.
  • Linked Images: For images serving as links, describe the target destination.
  • Decorative Images: For non-informative images, use an empty alt="".
  • Avoid Redundancy: If an adjacent text already describes the image, leave the alt attribute empty.
  • Character Limit: Keep the alt text under 150 characters.

Screen Readers

Screen readers convert on-screen text into speech or braille, making it accessible for visually impaired users. Common examples include:

  • (OS X) VoiceOver: Built into Macs, activated with Command-F5.
  • (Windows) NVDA: A free screen reader for Windows.
  • (Google Chrome) ChromeVox: Developed using web technologies for modern web apps and supports W3C ARIA for enhanced accessibility.