CSS clip Property

The clip property defines a rectangular region that limits the visible portion of an absolutely positioned element.

Content outside the clipping rectangle is hidden from view without changing the element's dimensions or layout position. The property uses the legacy rect() function to specify the rectangle's top, right, bottom, and left edges.

Deprecated: The clip property is deprecated and should not be used in new projects. Use clip-path for modern clipping effects, including rectangles, circles, polygons, and other shapes.

clip Syntax

The clip property accepts the keyword auto or a rectangular clipping region defined with rect().

selector {
  clip: rect(10px, 150px, 100px, 20px);
}

The general syntax is:

selector {
  clip: auto | rect(top, right, bottom, left);
}

Automatic Clipping

.element {
  clip: auto;
}

Rectangular Clipping

.element {
  position: absolute;
  clip: rect(10px, 150px, 100px, 20px);
}

Space-Separated Legacy Syntax

.element {
  position: absolute;
  clip: rect(10px 150px 100px 20px);
}

The legacy rect() function permits both comma-separated and space-separated arguments.

Automatic Rectangle Edges

.element {
  position: absolute;
  clip: rect(auto, 150px, auto, 20px);
}

CSS-Wide Keywords

.element {
  clip: inherit;
}
.element {
  clip: initial;
}
.element {
  clip: unset;
}
.element {
  clip: revert;
}
.element {
  clip: revert-layer;
}

The clip property does not accept percentages or modern clipping functions such as circle(), polygon(), or inset().

Property Values

The clip property supports two principal values.

Value Description
auto Does not impose a clipping rectangle. This is the initial value.
rect() Defines a rectangular clipping region using top, right, bottom, and left coordinates.

rect() Arguments

Argument Description
top Distance from the element's top border edge to the rectangle's top edge.
right Distance from the element's left border edge to the rectangle's right edge.
bottom Distance from the element's top border edge to the rectangle's bottom edge.
left Distance from the element's left border edge to the rectangle's left edge.

Each coordinate accepts a length or auto. The auto keyword selects the corresponding border-box edge.

CSS-Wide Keywords

Value Description
inherit Uses the computed value from the parent element.
initial Resets the property to auto.
unset Resets the property to auto because it is not inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited No
Applies to Absolutely positioned elements
Computed value auto or a rectangle with computed lengths and preserved auto values
Animation type Rectangle coordinates, when compatible
Percentages Not supported
Status Deprecated
Recommended replacement clip-path

How It Works

The clip property limits which parts of an absolutely positioned element are painted.

Step 1: Create an Element

<div class="clipped-box">Clipped Content</div>

Step 2: Position the Element

.clipped-box {
  position: absolute;
  width: 200px;
  height: 150px;
}

Legacy clipping requires absolute positioning. The position: fixed value also establishes absolute positioning for this purpose.

Step 3: Define the Clipping Rectangle

.clipped-box {
  position: absolute;
  width: 200px;
  height: 150px;
  clip: rect(20px, 170px, 120px, 30px);
}

The visible rectangle begins 20 pixels from the top and 30 pixels from the left. Its right and bottom edges are located 170 and 120 pixels from the corresponding coordinate origins.

Step 4: Understand the Visible Area

In this example, the visible region is 140 pixels wide and 100 pixels tall:

/* Width: 170px - 30px = 140px */
/* Height: 120px - 20px = 100px */

Step 5: Preserve the Original Dimensions

Clipping hides painted content outside the rectangle. It does not resize the element or change its declared width and height.

The rect() Function

The legacy rect() function specifies the four edges of a rectangular clipping region.

.element {
  clip: rect(10px, 180px, 120px, 20px);
}

Coordinate Order

The order is always top, right, bottom, left, following the clockwise order used by many CSS four-value properties.

Coordinates Are Not Dimensions

The second and third values represent edge positions, not the rectangle's width and height.

Comma-Separated Arguments

.element {
  clip: rect(0px, 150px, 100px, 0px);
}

Space-Separated Arguments

.element {
  clip: rect(0px 150px 100px 0px);
}

Using auto

.element {
  clip: rect(auto, 150px, auto, 0px);
}

The top and bottom edges follow their corresponding border-box edges, while the left and right edges use specified coordinates.

Negative Coordinates

.element {
  clip: rect(-10px, 200px, 160px, -10px);
}

Negative coordinates can extend the clipping rectangle beyond the element's border box. They do not create additional content outside the element.

Legacy Function Only

The rect() syntax used by clip is not interchangeable with the modern inset() function used by clip-path.

clip: auto

The auto value means that the clip property does not impose a clipping rectangle.

.element {
  clip: auto;
}

Default Behavior

Because auto is the initial value, an element does not need a clip declaration unless a clipping rectangle is required.

Remove Existing Clipping

.clipped-element {
  clip: rect(0px, 100px, 100px, 0px);
}
.clipped-element.show-all {
  clip: auto;
}

The second rule removes the clipping rectangle for an element with both classes.

Other Clipping May Still Apply

Setting clip: auto does not override clipping caused by overflow, clip-path, or other rendering constraints.

Absolute Positioning

The clip property only affects absolutely positioned elements.

Supported Positioning

.absolute-box {
  position: absolute;
  clip: rect(0px, 100px, 100px, 0px);
}

Fixed Positioning

.fixed-box {
  position: fixed;
  clip: rect(0px, 100px, 100px, 0px);
}

Static Positioning

.static-box {
  position: static;
  clip: rect(0px, 100px, 100px, 0px);
}

The clipping declaration does not produce the intended effect on a statically positioned element.

Relative Positioning

.relative-box {
  position: relative;
  clip: rect(0px, 100px, 100px, 0px);
}

Relative positioning does not satisfy the absolute-positioning requirement for the legacy clip property.

Modern Alternative

.relative-box {
  position: relative;
  clip-path: inset(0 50px 50px 0);
}

The modern clip-path property does not require absolute positioning.

Clipping Coordinates

The rectangle coordinates are measured relative to the element's border box.

Example Dimensions

.element {
  position: absolute;
  width: 200px;
  height: 150px;
  clip: rect(25px, 175px, 125px, 25px);
}

Visible Width

The visible width is calculated by subtracting the left coordinate from the right coordinate.

/* 175px - 25px = 150px */

Visible Height

The visible height is calculated by subtracting the top coordinate from the bottom coordinate.

/* 125px - 25px = 100px */

Clip the Top Portion

.element {
  clip: rect(0px, 200px, 75px, 0px);
}

Clip the Bottom Portion

.element {
  clip: rect(75px, 200px, 150px, 0px);
}

Clip the Left Portion

.element {
  clip: rect(0px, 100px, 150px, 0px);
}

Clip the Right Portion

.element {
  clip: rect(0px, 200px, 150px, 100px);
}

These examples assume a 200-pixel-wide and 150-pixel-tall border box. Actual results depend on the element's rendered dimensions.

clip vs. overflow

Both clip and overflow can hide content, but they work differently.

Feature clip overflow
Primary purpose Defines a rectangular clipping region Controls content extending beyond an element's box
Positioning requirement Absolute or fixed positioning No absolute-positioning requirement
Custom clipping coordinates Yes, using rect() No
Scrolling Does not create a scroll container Can provide scrolling with auto or scroll
Modern recommendation Deprecated Supported for overflow management

Legacy clip

.element {
  position: absolute;
  clip: rect(0px, 150px, 100px, 0px);
}

overflow: hidden

.container {
  width: 150px;
  height: 100px;
  overflow: hidden;
}

The first example clips an absolutely positioned element to specified coordinates. The second clips overflowing content to the container's clipping boundary.

Use overflow when managing content that extends outside a container, rather than as a direct replacement for every clipping effect.

clip vs. clip-path

The clip-path property is the modern replacement for legacy clipping.

Feature clip clip-path
Status Deprecated Modern CSS property
Shapes Rectangles only Rectangles, circles, ellipses, polygons, and other supported shapes
Positioning Requires absolute positioning Works without absolute positioning
Syntax rect() inset(), circle(), polygon(), and others
Recommended for new code No Yes

Legacy Rectangle

.element {
  position: absolute;
  width: 200px;
  height: 150px;
  clip: rect(20px, 170px, 120px, 30px);
}

Equivalent Modern Rectangle

.element {
  width: 200px;
  height: 150px;
  clip-path: inset(20px 30px 30px 30px);
}

For this 200 by 150 pixel border box, the inset() values specify distances inward from the top, right, bottom, and left edges.

Unlike rect(), inset() uses inset distances rather than absolute edge coordinates.

Modern Alternative

Use clip-path for new clipping effects. It supports multiple shapes and does not require an absolutely positioned element.

Rectangular Clipping

.element {
  clip-path: inset(20px 30px);
}

Circular Clipping

.element {
  clip-path: circle(40% at center);
}

Elliptical Clipping

.element {
  clip-path: ellipse(45% 35% at center);
}

Polygon Clipping

.element {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}

Rounded Rectangle

.element {
  clip-path: inset(10px round 12px);
}

Migration from clip

When converting existing rect() declarations, calculate the corresponding inset distances using the rendered border-box dimensions.

For a rectangle that begins 20 pixels from the top and left and ends 20 pixels before the right and bottom edges:

.element {
  width: 200px;
  height: 150px;
  clip-path: inset(20px);
}

The clip-path property is generally more flexible and easier to maintain than the deprecated clip property.

Legacy Accessibility Techniques

The clip property has historically been used in visually hidden text techniques, especially for labels intended to remain available to assistive technologies.

Legacy Visually Hidden Class

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

This older pattern hides content visually while generally leaving it in the accessibility tree.

Modern Clipping Version

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

Example Label

<label for="site-search" class="visually-hidden">Search the website</label>
<input type="search" id="site-search" placeholder="Search">

Important Accessibility Considerations

Visually hidden content can remain available to screen readers, but CSS clipping alone does not guarantee that an element is accessible or correctly labeled.

Avoid visually hiding interactive controls that keyboard users can still focus unless those controls become visible when focused.

For new projects, use a tested visually hidden utility based on modern CSS and appropriate accessibility practices.

Practical Uses

Although deprecated, clip may still appear in existing stylesheets and older interface components.

Legacy Image Cropping

.legacy-image {
  position: absolute;
  clip: rect(20px, 180px, 120px, 20px);
}

Legacy Content Reveal

.hidden-panel {
  position: absolute;
  clip: rect(0px, 0px, 0px, 0px);
}
.visible-panel {
  clip: auto;
}

This technique can be found in older components, but modern visibility and clipping techniques are preferable.

Legacy Visually Hidden Text

.screen-reader-text {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

Modern Image Cropping

.modern-image {
  clip-path: inset(20px);
}

Modern Circular Image

.avatar {
  clip-path: circle(50%);
}

Modern Custom Shape

.custom-shape {
  clip-path: polygon(0 0, 100% 0, 80% 100%, 20% 100%);
}

When maintaining existing code, understand how clip works before replacing it. For new effects, use clip-path or another property suited to the intended result.

clip Example

The following example demonstrates a rectangular clipping region on an absolutely positioned element. The original box is 240 pixels wide and 140 pixels tall, but only its central portion is visible.

<div class="clip-demo">
  <div class="clip-box">
    <span>Clipped Content</span>
  </div>
</div>
.clip-demo {
  position: relative;
  height: 170px;
  border: 1px dashed #999999;
  background-color: #f5f5f5;
}
.clip-demo .clip-box {
  position: absolute;
  top: 15px;
  left: 15px;
  width: 240px;
  height: 140px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background-color: #1769aa;
  clip: rect(20px, 200px, 120px, 40px);
}
.clip-demo .clip-box span {
  font-weight: bold;
}
Browser Result
Clipped Content

The clipping rectangle begins 20 pixels below the box's top edge and 40 pixels from its left edge. The right and bottom edges are positioned at 200 and 120 pixels.

The visible region is 160 pixels wide and 100 pixels tall. The remainder of the box is hidden, while its original dimensions remain unchanged.

Modern Equivalent

.clip-demo .clip-box {
  clip-path: inset(20px 40px);
}

For the same 240 by 140 pixel box, this clip-path declaration produces the equivalent rectangular clipping region without relying on the deprecated property.

Important Considerations

Keep the following points in mind when working with clip:

  • Deprecated: The property should not be used in new projects.
  • Initial value: auto.
  • Inheritance: The property is not inherited.
  • Positioning: Clipping requires an absolutely positioned element, including elements using position: fixed.
  • Shape: Only rectangular clipping regions are supported.
  • Function: Uses the legacy rect() function.
  • Coordinate order: Top, right, bottom, left.
  • Coordinate meaning: Values describe edge positions rather than rectangle dimensions.
  • Units: Length values and auto are supported.
  • Percentages: Percentage values are not supported.
  • Dimensions: Clipping does not change the element's width or height.
  • Layout: Clipping affects visibility rather than the element's layout position.
  • Overflow: Other clipping or overflow rules can still affect the rendered result.
  • Accessibility: Visually clipped content is not necessarily removed from the accessibility tree.
  • Browser support: Legacy support remains widespread, but the property is deprecated.
  • Modern replacement: Use clip-path for new clipping effects.
  • Migration: Convert edge coordinates to inset distances when replacing rect() with inset().

Retain clip only when necessary for existing code. Prefer clip-path for modern, maintainable clipping effects.

Browser Support

The clip property has long-standing support in major browsers, including Chrome, Edge, Firefox, and Safari. However, it is deprecated and may be removed from future browser implementations.

For new projects, use the widely supported clip-path property instead.

Legacy Example

.legacy-element {
  position: absolute;
  clip: rect(0px, 150px, 100px, 0px);
}

Modern Replacement

.modern-element {
  clip-path: inset(0 50px 50px 0);
}

The modern example assumes a 200-pixel-wide and 150-pixel-tall border box.

Feature Detection

@supports (clip-path: inset(10px)) {
  .modern-element {
    clip-path: inset(10px);
  }
}

For current compatibility details, visit Can I Use? and search for clip.

Specifications

The legacy clip property was defined in CSS 2.1 and is retained for compatibility in later CSS specifications.

CSS 2.2 - Clipping

CSS Masking Module Level 1

Modern clipping is defined through the clip-path property in CSS Masking Module Level 1.