Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Accessibility in CSS

Accessibility in CSS means designing presentation that preserves visible focus and accommodates user needs. It is a practice spanning multiple modules, not a property named accessibility.

Version: CSS modules; Chromium 152 is the scope of per-example verification, not a general compatibility guarantee.

Syntax

a:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
@media (prefers-reduced-motion: reduce) { a { transition: none; } }

accessibility is a design goal, not a CSS property or keyword. Styles should help people recognize interactive elements and operate an interface rather than remove cues supplied by the browser.

:focus identifies the element that has focus. :focus-visible matches it when the browser determines that a focus indicator should be shown; it does not mean keyboard use exclusively. Do not remove outlines with outline: none without providing a visible replacement. outline-offset separates the outline from the element.

@media (prefers-reduced-motion: reduce) detects a reported preference for reduced motion. In the example it disables both the transition and the hover displacement: transition: none alone would leave an abrupt jump. no-preference means no preference has been reported, not that animation was requested.

Also check the readability of colors and enlarged text; do not rely on color alone to distinguish links. forced-colors mode can enforce a user palette and does not necessarily indicate a preference for higher contrast. The example addresses only part of accessibility. CSSWG drafts describe mechanisms but do not establish that the example works in a particular browser.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CSS accessibility</title>
<style>
  body { font: 1rem/1.5 sans-serif; margin: 2rem; color: #111; background: #fff; }
  a { display: inline-block; padding: .5rem; color: #111; text-decoration: underline; transition: transform 150ms; }
  a:hover { transform: translateY(-2px); }
  a:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
  @media (prefers-reduced-motion: reduce) {
    a { transition: none; }
    a:hover { transform: none; }
  }
</style>
<a href="#details">Read details</a>
<h1 id="details">Details</h1>
<p>The link remains underlined without relying on color alone.</p>
</html>

Result

An underlined “Read details” link appears above “Details”. Keyboard focus shows a 3px outline offset by 3px. With prefers-reduced-motion: reduce active, hovering neither moves the link nor animates it; otherwise hover moves it upward by 2px with a 150ms transition.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources