102 of 313 menu

The clip-path property

The clip-path property defines the visible region of an element by clipping it to a specified shape. It accepts a clipping function or SVG path as a parameter.

Syntax

selector { clip-path: clipping-function; }

Values

Value Description
circle Clips the element to a circle. Parameters: radius and center position.
ellipse Clips the element to an ellipse. Parameters: X/Y radii and center position.
polygon Clips the element to a polygon. Parameters: comma-separated point coordinates.
url Uses an SVG path for clipping. Parameter: path ID in SVG.
path Clips the element to an SVG path using path data string. Parameter: SVG path string.
inset Clips the element to a rectangle with optional rounded corners. Parameters: top, right, bottom, left offsets and border radius.
margin-box Uses the element's margin box as the clipping area.
border-box Uses the element's border box as the clipping area.
padding-box Uses the element's padding box as the clipping area.
content-box Uses the element's content box as the clipping area.
none Disables clipping (default value).

Example

Clip an element to a hexagon:

<div id="hexagon"></div> #hexagon { width: 200px; height: 200px; background: #3498db; clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%); }

:

Example

Clip an element to a circle:

<div id="circle"></div> #circle { width: 200px; height: 200px; background: #2ecc71; clip-path: circle(40% at 50% 50%); }

:

Example

Clip an element to an ellipse:

<div id="ellipse"></div> #ellipse { width: 200px; height: 150px; background: #9b59b6; clip-path: ellipse(25% 40% at 50% 50%); }

:

Example

Clip an element with rounded corners:

<div id="inset"></div> #inset { width: 200px; height: 200px; background: #e67e22; clip-path: inset(20% 15% 10% 5% round 10px); }

:

Example

Clip an element to a circle:

<div id="path"></div> #path { width: 200px; height: 200px; background: #3498db; clip-path: path('M20,20 L180,20 L160,180 L40,180 Z'); }

:

Example

Using SVG path for complex clipping:

<svg width="0" height="0"> <clipPath id="star-path"> <path d="M50 0 L61 35 L98 35 L68 57 L79 92 L50 70 L21 92 L32 57 L2 35 L39 35 Z"/> </clipPath> </svg> <div id="star"></div> #star { width: 100px; height: 100px; background: #e74c3c; clip-path: url(#star-path); }

:

Example . Triangle

Clip to a triangle shape:

<div id="triangle"></div> #triangle { width: 200px; height: 200px; background: #e74c3c; clip-path: polygon(50% 0%, 0% 100%, 100% 100%); }

:

Example . Combined shapes

Creating a complex shape:

<div id="combined"></div> #combined { width: 250px; height: 250px; background: #2ecc71; clip-path: polygon( 0% 0%, 100% 0%, 100% 75%, 75% 75%, 75% 100%, 50% 75%, 0% 75% ); }

:

Example . Text clipping

Clip a text block:

<div id="text-clip"> <p>CSS clip-path creates amazing effects!</p> </div> #text-clip { width: 300px; padding: 20px; background: #3498db; color: white; font-size: 24px; clip-path: ellipse(120px 80px at 50% 50%); }

:

Example . Circular image clipping

Clip an image to a circle:

<div class="image-clip-circle"> <img src="img.png"> </div> .image-clip-circle img { width: 200px; height: 200px; clip-path: circle(50% at center); object-fit: cover; }

:

Example . Star-shaped image clipping

Clip an image to a five-pointed star:

<div class="image-clip-star"> <img src="img.png"> </div> .image-clip-star img { width: 200px; height: 200px; clip-path: polygon( 50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35% ); object-fit: cover; }

:

Example . Hexagonal image clipping

Clip an image to a hexagon:

<div class="image-clip-hexagon"> <img src="img.png"> </div> .image-clip-hexagon img { width: 200px; height: 200px; clip-path: polygon( 50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25% ); object-fit: cover; }

:

Example . Heart-shaped clipping

Clip an image to a heart shape:

<div class="image-clip-heart"> <img src="img.png"> </div> .image-clip-heart img { width: 200px; height: 180px; clip-path: polygon( 50% 15%, 35% 5%, 15% 15%, 10% 35%, 25% 60%, 50% 80%, 75% 60%, 90% 35%, 85% 15%, 65% 5% ); object-fit: cover; }

:

Example . Hover-based image clipping

Change clipping shape on hover:

<div class="image-clip"> <img src="img.png"> </div> .image-clip { display: inline-block; } .image-clip img { width: 200px; height: 200px; clip-path: circle(40% at 50% 50%); object-fit: cover; transition: clip-path 0.5s ease; } .image-clip:hover img { clip-path: polygon( 50% 0%, 90% 20%, 100% 60%, 75% 100%, 25% 100%, 0% 60%, 10% 20% ); }

:

See also

  • the clip property,
    which allows cropping a rectangle
  • mask property,
    which allows creating complex masks for elements
  • shape-outside property,
    defining text wrapping shapes
  • filter property,
    applying graphical effects to elements
trplenkkfr