clip

Term side of the Card.
Topic: Visibility
Unit title: clip
Categories: Property
Explanation side of the Card

Explanation: The deprecated property that clipped an absolutely positioned element to a rectangle set with `rect()`. Browsers still support it, but the standard replaced it with `clip-path`, which works on any element and with any shape.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

Wrongcss
.sr-only {
  position: absolute;
  clip: rect(0 0 0 0);
}
Rightcss
.sr-only {
  position: absolute;
  clip-path: inset(50%);
}

clip-path: inset(50%) hides the box like the deprecated clip and works without the positioning rule.

Common mistakes

  • clip does nothing because the element isn't absolutely positioned.

Key points

  • New code uses clip-path instead of clip.
  • Visually hidden classes use clip-path: inset(50%) instead of clip: rect(0 0 0 0).

Interview questions

Does clip still work in browsers?

Yes, browsers still support it for compatibility, but it is deprecated and only applies to absolutely positioned elements.

How do I convert clip: rect() to clip-path?

Use clip-path: inset() with distances from each edge; rect() in clip uses offsets from the top and left edges instead.

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy