Understanding the CSS `clip` Property: Defining the Visible Area of Absolutely Positioned Elements

Learn how to use CSS's `clip` property to control the visible area of absolutely positioned elements. This tutorial explains the `clip` property's syntax, its use in creating rectangular clipping regions, and provides examples demonstrating how to reveal only a portion of an element while hiding the rest.



Understanding the CSS `clip` Property

The CSS `clip` property defines the visible area of an absolutely positioned element. It's a way to cut off parts of an element, showing only a rectangular region.

How `clip` Works

The `clip` property only works on absolutely positioned elements (those with `position: absolute;`). It essentially creates a rectangular "mask" that reveals only a portion of the element. Anything outside the rectangle is hidden.

Syntax

The syntax is:

clip: auto | rect(top, right, bottom, left) | initial | inherit;

Property Values

`auto`

(Default) No clipping occurs; the entire element is visible.

Test it Now

`rect(top, right, bottom, left)`

Specifies the visible area as a rectangle using four length values (top, right, bottom, left). These values define the boundaries of the clipping rectangle. For example, `clip: rect(10px, 50px, 30px, 20px);` would create a rectangle with the top edge 10px from the top, the right edge 50px from the right, the bottom edge 30px from the bottom, and the left edge 20px from the left.

Test it Now