CSS clip-path Property

The clip-path property defines a clipping region that determines which parts of an element remain visible.

Content inside the clipping region is displayed, while content outside it is hidden. The property supports geometric shapes such as rectangles, circles, ellipses, and polygons, along with SVG clipping paths and additional shape functions.

Unlike the deprecated clip property, clip-path does not require absolute positioning and supports more complex shapes. It is commonly used for decorative effects, image cropping, custom interface elements, and animated transitions.

clip-path Syntax

The clip-path property accepts a basic shape, a geometry box, an SVG clipping path reference, or the keyword none.

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

General Syntax

selector {
  clip-path: none | <clip-source> | [<basic-shape> || <geometry-box>];
}

The syntax above summarizes the common forms. The specification also defines additional geometry-box options and shape functions.

Rectangular Clipping

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

Circular Clipping

.element {
  clip-path: circle(45%);
}

Elliptical Clipping

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

Polygon Clipping

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

SVG Clipping Path

.element {
  clip-path: url("#custom-clip");
}

Remove Clipping

.element {
  clip-path: none;
}

CSS-Wide Keywords

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

Property Values

The clip-path property supports several types of clipping regions.

Value Description
none Does not apply a clipping path. This is the initial value.
inset() Defines a rectangular clipping region using inset distances.
circle() Defines a circular clipping region.
ellipse() Defines an elliptical clipping region.
polygon() Defines a clipping region using connected coordinate points.
path() Defines a clipping path using SVG path commands.
shape() Defines a custom shape using CSS shape commands. Browser support is limited.
rect() Defines a rectangle using modern CSS shape syntax. Support varies.
xywh() Defines a rectangle using an x-position, y-position, width, and height. Support varies.
url() References an SVG <clipPath> element.
<geometry-box> Specifies the reference box used to calculate clipping coordinates.

CSS-Wide Keywords

Value Description
inherit Uses the computed value from the parent element.
initial Resets the property to none.
unset Resets the property to none 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 none
Inherited No
Applies to All elements, with SVG-specific considerations
Computed value As specified, with URLs made absolute
Animation type Depends on the specified shape and compatible interpolation
Percentages Relative to the applicable reference box
Initial reference box Border box for HTML elements
Primary use Clipping visible content into geometric or custom shapes

How It Works

The browser creates a clipping region from the value of clip-path and paints only the portions of the element that fall inside that region.

Step 1: Create an Element

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

Step 2: Define Its Dimensions

.shape-box {
  width: 200px;
  height: 200px;
  background-color: #1769aa;
}

Step 3: Apply a Clipping Shape

.shape-box {
  width: 200px;
  height: 200px;
  background-color: #1769aa;
  clip-path: circle(45%);
}

The visible portion becomes circular, while the original element remains 200 pixels wide and 200 pixels tall.

Step 4: Understand Layout

Clipping changes what is painted, not the space the element occupies in normal layout. Surrounding elements still use its original box dimensions.

Step 5: Understand Pointer Interaction

For pointer hit testing, clipped-out regions generally do not receive pointer events. The visible clipping region determines which portions can be targeted.

Step 6: Understand Stacking Contexts

A computed clip-path value other than none creates a stacking context, similar to the behavior of certain other visual effects.

inset() Clipping

The inset() function defines a rectangular clipping region using distances measured inward from the reference box edges.

Equal Insets

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

All four sides are inset by 20 pixels.

Two Values

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

The first value applies to the top and bottom. The second applies to the right and left.

Four Values

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

The values follow the order top, right, bottom, left.

Percentage Insets

.element {
  clip-path: inset(10% 15%);
}

Rounded Corners

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

Different Corner Radii

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

Common Use

Use inset() for rectangular image cropping, content reveals, and animated clipping effects.

circle() Clipping

The circle() function creates a circular clipping region using a radius and an optional center position.

Centered Circle

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

Circle with Pixel Radius

.element {
  clip-path: circle(75px);
}

Custom Center

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

Circle at Top Left

.element {
  clip-path: circle(50% at top left);
}

Circle at Center

.element {
  clip-path: circle(closest-side at center);
}

Farthest Side

.element {
  clip-path: circle(farthest-side at center);
}

Circular Avatar

.avatar {
  width: 150px;
  height: 150px;
  object-fit: cover;
  clip-path: circle(50%);
}

For simple circular avatars, border-radius: 50% is also a practical option. The circle() function provides additional control over the clipping radius and center.

ellipse() Clipping

The ellipse() function creates an elliptical clipping region with separate horizontal and vertical radii.

Centered Ellipse

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

Pixel Radii

.element {
  clip-path: ellipse(100px 60px);
}

Custom Center

.element {
  clip-path: ellipse(40% 30% at 60% 45%);
}

Ellipse at Bottom

.element {
  clip-path: ellipse(50% 40% at center bottom);
}

Closest-Side Radii

.element {
  clip-path: ellipse(closest-side closest-side at center);
}

Wide Elliptical Shape

.element {
  clip-path: ellipse(50% 25%);
}

The first radius controls the horizontal size and the second controls the vertical size.

Elliptical clipping is useful for decorative image treatments and curved visual sections.

polygon() Clipping

The polygon() function creates a clipping region by connecting a series of coordinate points.

Triangle

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

Diamond

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

Hexagon

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

Diagonal Edge

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

Arrow Shape

.arrow {
  clip-path: polygon(0 20%, 70% 20%, 70% 0, 100% 50%, 70% 100%, 70% 80%, 0 80%);
}

Fill Rules

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

The optional fill rule determines which regions count as inside the polygon when paths overlap or intersect. The default is nonzero.

Polygon Coordinates

Each point contains an x-coordinate followed by a y-coordinate. Percentages are calculated relative to the reference box.

Use polygon() for custom image shapes, diagonal sections, decorative backgrounds, and geometric interface elements.

path() Clipping

The path() function defines a clipping shape using SVG path data.

Triangle Path

.element {
  clip-path: path("M 100 0 L 200 200 L 0 200 Z");
}

Curved Path

.element {
  clip-path: path("M 0 0 H 200 V 150 Q 100 200 0 150 Z");
}

Path Commands

Command Purpose
M Moves to a starting position.
L Draws a straight line.
H Draws a horizontal line.
V Draws a vertical line.
C Draws a cubic Bézier curve.
Q Draws a quadratic Bézier curve.
Z Closes the current path.

Important Limitation

Coordinates in path() are not responsive percentages. A path defined with fixed coordinates may not scale automatically with the element.

For shapes that should adapt to different element sizes, consider polygon() with percentages or the newer shape() function where supported.

shape() Clipping

The shape() function defines a custom clipping path using CSS commands and supports CSS lengths, percentages, and calculations.

It provides a more flexible alternative to fixed SVG path coordinates, although browser support remains limited.

Triangle Shape

.element {
  clip-path: shape(from 50% 0, line to 100% 100%, line to 0 100%, close);
}

Responsive Coordinates

.element {
  clip-path: shape(from 0 0, line to 100% 0, line to 80% 100%, line to 0 100%, close);
}

Curved Shape

.element {
  clip-path: shape(from 0 0, line to 100% 0, line to 100% 70%, curve to 0 70% with 50% 100%, close);
}

Feature Detection

.element {
  clip-path: polygon(0 0, 100% 0, 80% 100%, 0 100%);
}
@supports (clip-path: shape(from 0 0, line to 100% 0, line to 100% 100%, close)) {
  .element {
    clip-path: shape(from 0 0, line to 100% 0, line to 80% 100%, line to 0 100%, close);
  }
}

Use a widely supported basic shape as a fallback when experimenting with shape().

Geometry Boxes

A geometry box determines the reference area used to calculate the clipping shape.

Common Geometry Boxes

Value Description
border-box Uses the element's border box.
padding-box Uses the element's padding box.
content-box Uses the element's content box.
margin-box Uses the element's margin box.
fill-box Uses the object's bounding box, primarily for SVG elements.
stroke-box Uses the stroke bounding box, primarily for SVG elements.
view-box Uses the nearest SVG viewport's view box.

Border Box

.element {
  clip-path: border-box circle(45%);
}

Content Box

.element {
  clip-path: content-box circle(45%);
}

Padding Box

.element {
  clip-path: padding-box inset(10px);
}

Geometry Box Only

.element {
  clip-path: content-box;
}

When a geometry box is specified without a basic shape, the box itself defines the clipping region, including any applicable corner rounding.

Default Reference Box

For ordinary HTML elements, the default reference box for basic shapes is the border box.

Support for individual geometry-box values may differ, so test less common values before relying on them.

SVG Clipping Paths

The clip-path property can reference an SVG <clipPath> element to define more complex clipping regions.

Define an SVG Clipping Path

<svg width="0" height="0" aria-hidden="true">
  <defs>
    <clipPath id="custom-clip">
      <circle cx="100" cy="100" r="90"></circle>
    </clipPath>
  </defs>
</svg>

Reference the Path

.element {
  clip-path: url("#custom-clip");
}

SVG Polygon

<svg width="0" height="0" aria-hidden="true">
  <defs>
    <clipPath id="polygon-clip">
      <polygon points="100,0 200,200 0,200"></polygon>
    </clipPath>
  </defs>
</svg>
.element {
  clip-path: url("#polygon-clip");
}

External SVG Reference

.element {
  clip-path: url("shapes.svg#custom-clip");
}

External SVG references can be subject to browser restrictions and resource-loading requirements. Test them in the intended environment.

When to Use SVG

SVG clipping paths are useful when a design requires complex vector shapes or clipping geometry already defined in an SVG document.

Animating clip-path

The clip-path property can be animated when the starting and ending clipping shapes support compatible interpolation.

Circle Reveal

.reveal {
  clip-path: circle(0% at center);
  transition: clip-path 0.5s ease;
}
.reveal:hover {
  clip-path: circle(75% at center);
}

Inset Reveal

.reveal {
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.5s ease;
}
.reveal:hover {
  clip-path: inset(0);
}

Polygon Animation

.shape {
  clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
  transition: clip-path 0.4s ease;
}
.shape:hover {
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

Polygon interpolation generally requires compatible fill rules and matching numbers of points.

Keyframe Animation

@keyframes circle-reveal {
  from {
    clip-path: circle(0% at center);
  }
  to {
    clip-path: circle(75% at center);
  }
}
.animated-element {
  animation: circle-reveal 1s ease forwards;
}

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .reveal,
  .shape {
    transition: none;
  }
  .animated-element {
    animation: none;
    clip-path: circle(75% at center);
  }
}

Respect reduced-motion preferences and avoid making important content dependent on an animation completing.

clip-path vs. clip

The clip-path property replaces the deprecated clip property for modern clipping effects.

Feature clip clip-path
Status Deprecated Modern CSS property
Supported shapes Rectangles only Rectangles, circles, ellipses, polygons, and more
Positioning requirement Absolute or fixed positioning No absolute-positioning requirement
Primary syntax rect() inset(), circle(), polygon(), and others
Recommended for new projects No Yes

Legacy Clipping

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

Modern Equivalent

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

The modern declaration uses inset distances instead of the edge coordinates used by the legacy rect() function.

clip-path vs. overflow

Both properties can hide content, but they are designed for different purposes.

Feature clip-path overflow
Purpose Defines a visible clipping shape Controls content extending beyond a box
Custom shapes Yes No
Scrolling Does not create scrolling Can create scroll containers
Typical use Visual effects and custom shapes Overflow management and scrolling

clip-path Example

.element {
  clip-path: circle(45%);
}

overflow Example

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

Use clip-path to define the visible shape of an element. Use overflow to manage content that extends outside its container.

Accessibility

Clipping can affect what users see without necessarily changing the underlying document or accessibility tree.

Avoid Hiding Essential Content

Important text, instructions, or controls should not become inaccessible because of decorative clipping.

Keyboard Focus

Clipped content may still contain focusable elements. A keyboard user can potentially focus an element that is not visibly displayed.

Visible Focus Indicators

.clipped-button:focus-visible {
  outline: 3px solid #1769aa;
  outline-offset: 3px;
}

Remember that a clipping path can also clip an element's outline. Test the focus indicator to ensure it remains visible.

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .animated-shape {
    animation: none;
    transition: none;
  }
}

Pointer Interaction

Areas outside the clipping region generally do not respond to pointer interaction. Ensure interactive targets remain large enough to use comfortably.

Screen Reader Content

Clipping an element visually does not automatically remove it from the accessibility tree. Use appropriate HTML semantics and accessibility attributes when content should be hidden from assistive technologies.

Use decorative clipping without compromising readability, keyboard navigation, or access to important content.

Practical Uses

The clip-path property can create a variety of visual effects without requiring separate image files for every shape.

Circular Profile Image

.profile-image {
  width: 150px;
  height: 150px;
  object-fit: cover;
  clip-path: circle(50%);
}

Hexagonal Image

.hexagon-image {
  clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);
}

Diagonal Section

.diagonal-section {
  background-color: #1769aa;
  clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%);
}

Rounded Inset

.rounded-panel {
  clip-path: inset(10px round 20px);
}

Triangle Badge

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

Hover Reveal

.hover-reveal {
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.4s ease;
}
.hover-reveal:hover {
  clip-path: inset(0);
}

Decorative Image Crop

.decorative-image {
  clip-path: ellipse(48% 40% at center);
}

For straightforward rectangular cropping, overflow: hidden or object-fit may be more appropriate. Choose clip-path when the clipping shape itself is important to the design.

clip-path Example

The following example demonstrates four clipping shapes: circle, ellipse, polygon, and inset. Each shape uses the same box dimensions so their differences are easy to compare.

<div class="clip-path-demo">
  <div class="shape-item">
    <div class="shape-box circle-shape">Circle</div>
    <p>circle(45%)</p>
  </div>
  <div class="shape-item">
    <div class="shape-box ellipse-shape">Ellipse</div>
    <p>ellipse(48% 35%)</p>
  </div>
  <div class="shape-item">
    <div class="shape-box polygon-shape">Polygon</div>
    <p>polygon()</p>
  </div>
  <div class="shape-item">
    <div class="shape-box inset-shape">Inset</div>
    <p>inset(15px round 15px)</p>
  </div>
</div>
.clip-path-demo {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 20px;
}
.clip-path-demo .shape-item {
  text-align: center;
}
.clip-path-demo .shape-box {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 150px;
  height: 150px;
  color: #ffffff;
  background-color: #1769aa;
  font-weight: bold;
}
.clip-path-demo .circle-shape {
  clip-path: circle(45%);
}
.clip-path-demo .ellipse-shape {
  clip-path: ellipse(48% 35%);
}
.clip-path-demo .polygon-shape {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.clip-path-demo .inset-shape {
  clip-path: inset(15px round 15px);
}
.clip-path-demo .shape-item p {
  margin-top: 10px;
  font-size: 14px;
}
Browser Result
Circle

circle(45%)

Ellipse

ellipse(48% 35%)

Polygon

polygon()

Inset

inset(15px round 15px)

Each element retains its original 150 by 150 pixel layout box, but only the portion inside its clipping shape is visible.

The circle and ellipse create curved boundaries, the polygon creates a triangle, and the inset creates a smaller rectangle with rounded corners.

Important Considerations

Keep the following points in mind when using clip-path:

  • Purpose: Defines the visible clipping region of an element.
  • Initial value: none.
  • Inheritance: The property is not inherited.
  • Layout: Clipping does not change the element's layout dimensions.
  • Shapes: Supports rectangles, circles, ellipses, polygons, and other defined shapes.
  • Positioning: Absolute positioning is not required.
  • Percentages: Shape percentages are calculated relative to the applicable reference box.
  • Reference box: The border box is the default for HTML elements.
  • Geometry boxes: Values such as content-box and padding-box can change the clipping reference area.
  • SVG: Clipping paths can reference SVG <clipPath> elements.
  • Animation: Compatible shapes can be animated or transitioned.
  • Stacking context: A computed value other than none creates a stacking context.
  • Pointer interaction: Clipped-out regions generally do not receive pointer events.
  • Accessibility: Visually clipped content may remain in the accessibility tree.
  • Focus indicators: Outlines can be clipped, so test keyboard focus visibility.
  • Browser support: Common basic shapes are widely supported, but newer functions have varying availability.
  • Modern replacement: Use clip-path instead of the deprecated clip property.
  • Responsive design: Percentage-based shapes generally adapt more easily to changing element dimensions.
  • Fallbacks: Use supported basic shapes when experimenting with newer clipping functions.

Use clip-path when a design requires a custom visible shape. For ordinary overflow management, use the appropriate overflow property instead.

Browser Support

The clip-path property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

Common basic shapes such as inset(), circle(), ellipse(), and polygon() have broad support. Newer features, including shape() and certain geometry-box values, have more limited availability.

Widely Supported Example

.element {
  clip-path: circle(45%);
}

Feature Detection

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

Fallback for Newer Shapes

.element {
  clip-path: polygon(0 0, 100% 0, 80% 100%, 0 100%);
}
@supports (clip-path: shape(from 0 0, line to 100% 0, line to 100% 100%, close)) {
  .element {
    clip-path: shape(from 0 0, line to 100% 0, line to 80% 100%, line to 0 100%, close);
  }
}

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

Specifications

The clip-path property is defined in CSS Masking Module Level 1. Related basic shape functions are defined in CSS Shapes Module Level 1 and later specifications.

CSS Masking Module Level 1

CSS Shapes Module Level 1

CSS Shapes Module Level 2

These specifications define clipping behavior, reference boxes, shape functions, and related rendering rules.