Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Legacy `clip: rect(0 0 0 0)` in `.sr-only`

Four zero offsets in legacy `clip: rect(0 0 0 0)` leave no visible area. An `.sr-only` utility uses that effect to hide text visually while keeping it available to screen readers.

Version: Current CSS specifications; browser support varies by feature

Syntax

/* Historical form: accepted by some browsers for compatibility */
clip: rect(0 0 0 0);
/* Standard syntax for the deprecated property */
clip: rect(0, 0, 0, 0);
/* Modern clipping property */
clip-path: inset(50%);

“Legacy clip with rect(0 0 0 0) in an .sr-only class” refers to the legacy clip declaration in a screen-reader-only utility. .sr-only is a class name, not a built-in CSS feature. It hides text visually while keeping it available to assistive technology. Do not substitute display: none or visibility: hidden if screen readers still need access to the text.

In HTML, the deprecated clip property applies to position: absolute or position: fixed, not position: relative. Its legacy rect() lists the edges in top, right, bottom, left order. Top and bottom are measured from the top of the box; right and left from its left edge. Four zeros give the rectangle zero width and height, so nothing is visible. clip: auto does not clip.

The space-separated rect(0 0 0 0) is a compatibility form browsers are not required to accept. Use commas in legacy code: rect(0, 0, 0, 0). Do not mix separators. The legacy rect() for clip is distinct from the modern <basic-shape> function named rect().

For new code, use clip-path: inset(50%): each edge moves inward by half the corresponding dimension, leaving no area. In the example, clip is a separate fallback declaration, while the 1px dimensions and overflow: hidden constrain the box and its overflow. Do not hide an entire focusable control this way unless you reveal it on :focus, as with a skip link to the main content.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Visually hidden button text</title>
  <style>
    .sr-only {
      position: absolute;
      width: 1px;
      height: 1px;
      overflow: hidden;
      white-space: nowrap;
      clip: rect(0, 0, 0, 0);
      clip-path: inset(50%);
    }
  </style>
</head>
<body>
  <button type="button">Save<span class="sr-only"> current draft</span></button>
  <script>
    const button = document.querySelector('button');
    const suffix = button.querySelector('.sr-only');
    const style = getComputedStyle(suffix);
    const legacyClip = style.position === 'absolute' &&
      style.clip === 'rect(0px, 0px, 0px, 0px)';
    const modernClip = style.clipPath === 'inset(50%)';

    if (!legacyClip && !modernClip) {
      throw new Error('The button suffix has no zero-area clip.');
    }

    const visibleText = button.firstChild.textContent.trim();
    // The expected name comes from the button's contents, not the accessibility tree.
    const expectedName = button.textContent.replace(/\s+/g, ' ').trim();
    console.log(`Visible button text: ${visibleText}\nExpected accessible name: ${expectedName}`);
  </script>
</body>
</html>

Result

Visible button text: Save
Expected accessible name: Save current draft

The button shows only “Save”, but its expected accessible name is “Save current draft”. Inspect the button’s name in the browser’s accessibility panel; appearance alone cannot confirm it.

Related lessons

  • CSS · Lesson 24 · Advanced · Version: 2

Sources