Every element on a web page is a rectangle. Most of the time that's exactly what you want, but designers often reach for diagonal section edges, circular photos, hexagon badges, text that fades out at the bottom, or duotone images. In the past, these effects meant editing images in a graphics program. Today CSS can create them on any element, and they stay sharp and editable.
Three groups of features make it possible. clip-path cuts an element to a shape, hiding everything outside it. Masks, using mask-image, hide parts of an element based on an image or gradient, which allows soft, faded edges. Blend modes, mix-blend-mode and background-blend-mode, combine the colours of overlapping layers the way photo-editing apps do.
In this lesson you'll learn the shape functions, how to animate a clip, how to fade content with gradient masks, and which blend modes are worth knowing. You'll also see where to be careful: clipped content can't be clicked outside its shape, and blended text must still be readable.
clip-path shapes
| Function | Example | Shape |
|---|---|---|
circle() | circle(50% at 50% 50%) | A circle with a radius and centre |
ellipse() | ellipse(50% 35% at center) | An oval |
inset() | inset(10px round 12px) | A rectangle pulled in from each side, optionally rounded |
polygon() | polygon(50% 0, 100% 100%, 0 100%) | Any shape from a list of x y points |
path() | path("M0 0 L100 0 ...") | An SVG path |
Points in polygon() are measured from the element's top-left corner, with percentages relative to its width and height. Tools such as Clippy (bennettfeely.com/clippy) let you drag points visually and copy the CSS.
Animating clip-path
clip-path can be animated with transitions as long as both shapes use the same function and the same number of points:
.reveal { clip-path: inset(0 100% 0 0); transition: clip-path 0.6s; }
.reveal.visible { clip-path: inset(0 0 0 0); }This "wipe" effect is popular for revealing images and headings. Unlike width animations, clipping doesn't change the layout, so nothing around it moves.
Masks with gradients
.fade-bottom {
mask-image: linear-gradient(to bottom, black 60%, transparent);
}A mask uses the transparency of an image or gradient: where the mask is opaque, the element shows; where it's transparent, the element is hidden; in between, it partly shows. That gives soft edges that clip-path can't, such as text fading into a "Read more" button, or a photo dissolving into the background. Masks can also use SVG or PNG images for shaped cut-outs.
Blend modes
| Property | Blends… |
|---|---|
mix-blend-mode | an element with whatever is behind it |
background-blend-mode | an element's own background layers with each other |
Common values are multiply (darkens, like layering ink), screen (lightens), overlay (boosts contrast), difference (inverts where layers overlap) and luminosity. Combining a photo with a colour using background-blend-mode: multiply creates a duotone effect that matches your brand without editing the image.
CSS clip-path Syntax
Shapes, masks and blending
.avatar { clip-path: circle(50%); }
.section { clip-path: polygon(0 0, 100% 0, 100% 85%, 0 100%); }
.card { clip-path: inset(0 round 16px); }
.excerpt { mask-image: linear-gradient(black 70%, transparent); }
.title { mix-blend-mode: difference; }
.hero { background: url(photo.jpg), #2563eb; background-blend-mode: multiply; }CSS clip-path Summary
clip-pathcuts an element to a shape:circle(),ellipse(),inset(),polygon()orpath().- Clip shapes animate smoothly when they use the same function and number of points.
mask-imagewith a gradient creates soft, faded edges.mix-blend-modeblends an element with what's behind it;background-blend-modeblends its own backgrounds.- Clipped elements keep their layout space, and only the visible part is clickable.
CSS clip-path Examples
Each example runs in the page. Edit the code and press Run to see what changes.
Shapes with clip-path
<div class="row">
<div class="shape circle">circle</div>
<div class="shape tri">polygon</div>
<div class="shape hex">hexagon</div>
<div class="shape rounded">inset</div>
</div>.row { display: flex; flex-wrap: wrap; gap: 12px; }
.shape {
width: 110px; height: 110px;
display: grid; place-items: center;
background: linear-gradient(135deg, #f97316, #db2777);
color: white; font: 600 13px sans-serif;
}
.circle { clip-path: circle(50%); }
.tri { clip-path: polygon(50% 0, 100% 100%, 0 100%); align-content: end; padding-bottom: 14px; box-sizing: border-box; }
.hex { clip-path: polygon(25% 5%, 75% 5%, 100% 50%, 75% 95%, 25% 95%, 0 50%); }
.rounded { clip-path: inset(12px round 20px); }Line-by-line explanation
- Line 9A circle with a radius of half the box.
- Line 10Three points make a triangle; the label moves down so it stays inside the shape.
- Line 11Six points make a hexagon.
- Line 12A rectangle pulled in 12px from each side, with rounded corners.
A slanted section and a wipe reveal
Hover over the photo to reveal it.
<section class="slant">
<h2>Spring collection</h2>
</section>
<div class="reveal-wrap">
<img class="reveal" src="https://picsum.photos/seed/clip/500/250" alt="Flower field" width="500" height="250">
</div>.slant {
clip-path: polygon(0 0, 100% 0, 100% 75%, 0 100%);
background: #16a34a;
color: white;
padding: 24px 20px 56px;
font-family: sans-serif;
}
.reveal { display: block; max-width: 100%; height: auto; border-radius: 10px; }
.reveal { clip-path: inset(0 70% 0 0); transition: clip-path 0.6s ease; }
.reveal-wrap:hover .reveal { clip-path: inset(0 0 0 0); }Line-by-line explanation
- Line 2The bottom edge slopes from 75% down on the right to 100% on the left.
- Line 10The photo starts with 70% hidden from the right.
- Line 11On hover the clip opens smoothly to show the whole image.
Fades and duotones
<div class="excerpt">
<p>The old harbour was rebuilt in 1820 after a storm destroyed the original wooden pier. Today it's home to fishing boats, a small museum and a café that serves the best crab sandwiches on the coast. Every summer the town holds a festival with music, food stalls and a boat race.</p>
</div>
<div class="duo"></div>.excerpt {
max-width: 420px;
max-height: 110px;
overflow: hidden;
font: 16px/1.6 Georgia, serif;
mask-image: linear-gradient(to bottom, black 50%, transparent);
}
.duo {
height: 160px;
max-width: 420px;
margin-top: 12px;
border-radius: 12px;
background: url("https://picsum.photos/seed/duo/800/320") center / cover, #2563eb;
background-blend-mode: multiply;
}Line-by-line explanation
- Line 6The text fades out towards the bottom, hinting there's more.
- Line 14A photo layered over a blue background colour.
- Line 15Multiply blends them into a blue duotone.
Common CSS clip-path Mistakes
Animating between different shape functions
.box { clip-path: circle(20%); transition: clip-path 0.4s; }
.box:hover { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); } /* jumps, no animation */.box { clip-path: circle(20%); transition: clip-path 0.4s; }
.box:hover { clip-path: circle(75%); }Clipping away important content
.badge { clip-path: polygon(50% 0, 100% 100%, 0 100%); } /* text in the corners is cut off */.badge { clip-path: polygon(50% 0, 100% 100%, 0 100%); padding-top: 40%; text-align: center; }Keep text inside the visible shape.
Unreadable blended text
h1 { mix-blend-mode: overlay; color: white; } /* nearly invisible on light photos */h1 { color: white; text-shadow: 0 2px 8px rgb(0 0 0 / 0.5); }Blend modes look striking, but always check text contrast.
CSS clip-path in Real Projects
Where you'll see these effects
Landing pages use slanted and wavy section edges made with clip-path. Portfolio sites reveal images with clip animations as you scroll. News sites fade long articles with a gradient mask above a "Continue reading" button. Brands like Spotify popularised duotone imagery, which background-blend-mode recreates in the browser.
CSS clip-path Exercises
Answer each one and check it instantly. If you get stuck, open the hint before the answer.
Clip the avatar into a circle.
.avatar {
clip-path: (50%);
}
circle(50%) uses half the box as the radius.What happens to the parts of an element outside its clip-path?
Which feature can make soft, faded edges?
What does background-blend-mode blend?
The box should be a triangle pointing up, and the excerpt should fade from black to transparent towards the bottom. Fix the CSS.
<div class="tri" style="width: 100px; height: 100px; background: teal"></div>
<p class="ex">Fading text</p>.tri { clip-path: polygon(50% 0 100% 100% 0 100%); }
.ex { mask-image: linear-gradient(transparent, black); }- Triangle clip is valid
- Mask fades out towards the bottom
CSS clip-path Quiz
5 questions to check what you learned.
Which clip-path function takes a list of points?
- circle()
- polygon()
- inset()
- ellipse()
What does inset(10px round 16px) create?
- A rectangle pulled in 10px on every side with 16px rounded corners
- A circle
- A shadow
- A border
When can clip-path animate smoothly?
- Always
- Never
- Only with JavaScript
- When both shapes use the same function and number of points
Which blend mode darkens, like layering ink?
- screen
- difference
- multiply
- normal
Can you click the hidden part of a clipped element?
- Yes, the whole box is clickable
- No, only the visible shape receives clicks
- Only with pointer-events: auto
- Only on touch screens
CSS clip-path Challenge
A hero banner with style
- Clip
.herowithpolygon(0 0, 100% 0, 100% 80%, 0 100%) - Give
.heroabackground-blend-modeofmultiply - Make
.photoa circle withclip-path: circle(50%) - Fade
.introwithmask-image: linear-gradient(black 60%, transparent)
<section class="hero" style="padding: 30px; background: url(https://picsum.photos/seed/hero2/800/300) center / cover, rgb(124, 58, 237)">
<img class="photo" src="https://picsum.photos/seed/me/200/200" alt="Host portrait" width="100" height="100">
<p class="intro">Join us every Friday for live music, board games and food from local kitchens.</p>
</section>- Slanted hero
- Duotone blend
- Circular photo
- Faded intro