clip
Example
.sr-only {
position: absolute;
clip: rect(0 0 0 0);
}.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
clipdoes nothing because the element isn't absolutely positioned.
Key points
- New code uses
clip-pathinstead ofclip. - Visually hidden classes use
clip-path: inset(50%)instead ofclip: 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.