Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

clip — legacy rectangular clipping

The CSS `clip` property limits the visible part of an element to a rectangle without changing its dimensions. It is deprecated: prefer `clip-path` for new code, and learn `clip` mainly for maintaining older stylesheets.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

clip: auto;
clip: rect(<top>, <right>, <bottom>, <left>);
/* Each coordinate is a <length> or auto. */

clip clips an element's painting, including its background, borders, and descendants, without shrinking its layout box. In HTML, it applies to absolutely positioned elements, meaning position: absolute or position: fixed, not relative or static. It is not inherited, and its initial value is auto.

In rect(top, right, bottom, left), top and bottom are coordinates measured from the border box's top edge; right and left are measured from its left edge. They are not four insets from the corresponding sides. Use commas. Each coordinate accepts a length or auto; negative lengths are allowed, but percentages are not.

clip: auto introduces no clipping through this property. By contrast, rect(auto, auto, auto, auto) clips to the border box: each auto inside rect() means that box's corresponding edge. Ancestor clipping can still restrict visibility.

clip is deprecated; choose clip-path for new code. Do not transfer numbers directly to inset(), which measures insets from the corresponding sides. SVG has additional applicability rules for clip, covering elements establishing a new viewport and pattern and mask elements.

Examples

<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>clip demo</title>
<style>
  body { margin: 0; background: white; }
  .box {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 160px;
    height: 100px;
    background: #0066cc;
    clip: rect(10px, 130px, 80px, 30px);
  }
</style>
<div class="box"></div>
</html>

Result

Expected rendering: a blue rectangle 100 CSS px wide and 70 CSS px high, with its top-left corner 50 CSS px from the viewport's left edge and 30 CSS px from its top edge, on a white background.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources