Skip to main content

CSS Accessibility Styling

Good accessibility means a website works for all users, people with disabilities included.

Through careful styling techniques, CSS can improve visual clarity, navigation and the overall user experience.


CSS Accessibility Styling Techniques

The techniques below will help you make your website more accessible.


1. Provide High Color Contrast

Text needs to stand out from its background to be readable, so keep the contrast between them strong. Users with visual impairments or color blindness depend on this most.

Good Color Contrast

Prompt
Create a page that demonstrates good color contrast by setting the body background to white (#ffffff) and text color to black (#000000). Include a heading and a paragraph of text.
Output: complete HTML page

Bad Color Contrast

Prompt
Create a page that demonstrates bad color contrast by setting the body background to light gray (#eeeeee) and text color to a slightly darker gray (#cccccc). Include a heading and a paragraph of text.
Output: complete HTML page

2. Provide Good Font, Font Size and Line Height

Choose an easily readable font, with a suitable size and line height. Set font-size in relative units (like rem) so that users can scale the text through their browser settings.

Good Font Example

Prompt
Create a page that demonstrates good font styling for accessibility. Set the body font-family to Arial, sans-serif, font-size to 1rem, and line-height to 1.6. Include a heading and a paragraph.
Output: complete HTML page

Bad Font Example

Prompt
Create a page that demonstrates bad font styling for accessibility. Set the body font to Georgia serif, font-size 12px, font-style italic, font-variant small-caps, and line-height 90%. Include a heading and a paragraph.
Output: complete HTML page

3. Have Visible Focus Indicators

Interactive elements (like links, buttons, input fields) should always show a clear visual style when focused, which is what the :focus pseudo-class is for.

With that style in place, keyboard users and screen readers can tell which element is currently active.

Example

Prompt
Create a page with a link, a button, and an input field. Use the :focus pseudo-class to give all three a 2px solid orange outline when focused.
Output: complete HTML page

4. Avoid Hiding Focus

Default focus outlines should only ever be removed if another visible focus style takes their place.

Bad Example

Prompt
Create a page with a button that has its focus outline removed using outline: none on the :focus pseudo-class. Include another button for comparison.
Output: complete HTML page

Good Example

Prompt
Create a page with a button that has a visible 2px solid orange outline on the :focus pseudo-class. Include another button for comparison.
Output: complete HTML page

5. Use CSS + Semantic HTML

Leave visual styling to CSS and give content its structure through semantic HTML elements, rather than reaching for non-semantic ones like <div> everywhere.

Example

styles.css
nav {
  background-color: #333333;
  color: white;
}

aside {
  background-color: #333333;
  color: white;
}

6. Respect User Preferences

Motion sensitivity leads some users to prefer websites with less animation. To check whether someone has asked to reduce motion, such as animations or transitions, CSS offers the prefers-reduced-motion media feature.

When that setting is active on their computer, this media query lets you turn off or tone down the animations and transitions.

Example

Prompt
Create a page that uses the prefers-reduced-motion media query to disable all animations and transitions when the user prefers reduced motion. Include a simple animated element to demonstrate.
Output: complete HTML page

Summary

  • Keep color contrast high
  • Choose fonts that are easy to read
  • Leave focus outlines visible
  • Structure pages with semantic HTML elements
  • Honor what users prefer