CKTIS / CSS
Legacy CSS `clip`: visually hiding text with `rect()`
Learn how the deprecated `clip` property uses a zero-area `rect()` to hide text visually and how it differs from modern `clip-path`.
Version: Current CSS specifications; browser support varies by feature
Syntax
clip: auto;
clip: rect(<top>, <right>, <bottom>, <left>);
/* Each rect() argument is a <length> or auto. */
/* Modern alternative for a zero-area clip: */
clip-path: inset(50%);“Historyczne clip” means legacy CSS clip, a property that limits where an element is painted. For HTML elements it works only with position: absolute or position: fixed. The initial value, clip: auto, does not clip. Learn it to read older stylesheets, but use clip-path for clipping in new code.
The legacy rect(top, right, bottom, left) takes four comma-separated lengths (not percentages) or auto values. An auto argument aligns that clipping edge with the corresponding edge of the element’s box. top and bottom share a top origin, and right and left share a left origin. They are not insets from four different sides. rect(0, 0, 0, 0) has zero width and height, so nothing is visible.
Clipping does not remove text from the DOM and, unlike display: none, does not by itself hide it from screen readers. Do not leave an invisible control in the tab order: if it needs to be reachable by keyboard, reveal it when it receives focus. Test with your target browsers and screen readers.
Modern clip-path: inset(50%) also creates a zero-area clip by moving each edge inward by 50%. clip-path itself does not require absolute positioning. Do not copy the old comma-separated rect() unchanged: the modern <basic-shape> function rect() has different syntax.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Example</title>
<style>
.legacy-hidden {
position: absolute;
clip: rect(0, 0, 0, 0);
}
</style>
</head>
<body>
<p>Visible text</p>
<p class="legacy-hidden">Hidden note</p>
</body>
</html>Result
Expected in a browser that supports `clip`: only “Visible text” is shown. “Hidden note” remains in the DOM but is not painted. Disabling only the `clip` declaration makes “Hidden note” visible without changing its positioning.
In a browser that supports `clip`, only “Visible text” is shown. “Hidden note” stays in the DOM and appears when you disable just the `clip` declaration.
Related lessons
- CSS · Lesson 34 · Intermediate · Version: 2