Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

Visually hiding a radio button with legacy `clip: rect(0 0 0 0)`

Learn how a legacy CSS clipping rule hides the native radio button’s appearance while preserving its semantics and keyboard behavior.

Version: Current CSS specifications; browser support varies by feature

Syntax

clip: rect(0 0 0 0); /* historical, space-separated form; support is optional */
clip: rect(0, 0, 0, 0); /* specified, comma-separated form */
/* For HTML, clip applies with position: absolute or position: fixed. */
clip-path: inset(50%); /* modern way to create an empty clipping region */

In older CSS, clip: rect(0 0 0 0) hides the native radio button by clipping the area the browser paints. On HTML elements, clip works only with absolute positioning (position: absolute or position: fixed). The legacy rect() arguments locate the top, right, bottom, and left edges in that order. Vertical coordinates are measured from the top of the box and horizontal coordinates from the left. Four zeros give the rectangle zero width and height without resizing the box itself.

The specification requires support for rect(0, 0, 0, 0). The historical space-only form is optional; do not mix separators. clip is deprecated. For new code, use clip-path: inset(50%), which moves each clipping edge halfway inward and leaves an empty region. Do not confuse the legacy rect() with the identically named basic-shape function used with clip-path.

Clipping does not disable the control. Keep native input[type="radio"] elements, a shared name within the group, and visible label elements linked via for and id. The label is the visible click target. Show selection on the label with :checked and keyboard focus with :focus-visible. Do not substitute display: none or add aria-hidden="true" to the control. Test keyboard and assistive-technology behavior in your target browsers.

Examples

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Radio clipping demo</title>
  <style>
    .choice {
      position: relative;
      margin-block: 0.5rem;
    }

    .choice > input[type="radio"] {
      position: absolute;
      top: 50%;
      left: 0;
      margin: 0;
      transform: translateY(-50%);
      clip: rect(0, 0, 0, 0);
      clip: rect(0 0 0 0);
    }

    .choice > label {
      display: inline-block;
      padding: 0.25rem 0.5rem 0.25rem 1.75rem;
      cursor: pointer;
    }

    .choice > input:checked + label {
      font-weight: 700;
      text-decoration: underline;
    }

    .choice > input:focus-visible + label {
      outline: 2px solid currentColor;
      outline-offset: 2px;
    }
  </style>
</head>
<body>
  <fieldset>
    <legend>Contact method</legend>
    <div class="choice">
      <input type="radio" id="email" name="contact" value="email" checked>
      <label for="email">Email</label>
    </div>
    <div class="choice">
      <input type="radio" id="phone" name="contact" value="phone">
      <label for="phone">Phone</label>
    </div>
  </fieldset>
</body>
</html>

Result

Expected on a fresh load in a browser supporting the comma-separated form of `clip`: both labels are visible, neither native radio circle is visible, and Email is bold and underlined. In a browser supporting `:focus-visible`, with browser and OS keyboard-navigation settings that let Tab reach native radio buttons, pressing Tab to enter the group focuses Email and outlines its label. With Email focused, pressing Down Arrow moves selection and keyboard focus to Phone; Phone becomes bold and underlined and receives the outline. Clicking Email selects it again.

The comma-separated declaration is the fallback if the browser rejects the space-separated form. Email starts selected. If your browser and OS settings let Tab reach native radio buttons, Tab into the group to focus Email. A browser that supports `:focus-visible` outlines the label. With Email focused, Down Arrow moves focus and selection to Phone.

Related lessons

  • CSS · Lesson 18 · Advanced · Version: 2

Sources