On this page9 sections
Lecture 041: Clip-path & Shapes
| Category | 7: Advanced Styling |
| Lecture | 041 of 057 |
| Estimated video length | 10 min |
| Target | CSS3 · any modern browser |
| Level | Intermediate |
Every element is a rectangle, but it doesn't have to look like one.
clip-pathcuts an element into a circle, a triangle, a slanted banner or any polygon.shape-outsidemakes text flow around that shape.
Learning Objectives
- Clip elements with
circle(),ellipse(),inset()andpolygon() - Animate between shapes
- Wrap text around a shape with
shape-outside
1. Basic Shapes
Example
<style>
.s { display: inline-block; width: 110px; height: 110px; margin: 6px;
background: url('https://picsum.photos/id/1025/220/220') center / cover; }
</style>
<div class="s" style="clip-path: circle(50%);"></div>
<div class="s" style="clip-path: ellipse(50% 35%);"></div>
<div class="s" style="clip-path: inset(15% round 16px);"></div>
<div class="s" style="clip-path: polygon(50% 0, 100% 100%, 0 100%);"></div>
<div class="s" style="clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);"></div>
<div class="s" style="clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%);"></div>| Function | Shape |
|---|---|
circle(radius at x y) | Circle |
ellipse(rx ry at x y) | Ellipse |
inset(top right bottom left round r) | Rectangle cut in from the edges, optionally rounded |
polygon(x1 y1, x2 y2, …) | Any straight-edged shape |
Polygon points are percentages of the element's width and height, starting from the top left.
2. Slanted Sections
Example
<div style="background: linear-gradient(135deg, #364fc7, #12b886); color: white; padding: 40px 20px 70px;
clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%);">
<h2 style="margin: 0;">A hero section with a slanted bottom edge</h2>
</div>3. Animating Shapes
Shapes with the same number of points can animate between each other.
Example: hover over the shape:
<style>
.morph { width: 140px; height: 140px; background: #e64980; transition: clip-path 0.5s;
clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%); }
.morph:hover { clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%); }
.reveal { width: 240px; transition: clip-path 0.6s; clip-path: circle(20% at 50% 50%); }
.reveal:hover { clip-path: circle(75% at 50% 50%); }
</style>
<div class="morph"></div>
<br>
<img class="reveal" src="https://picsum.photos/id/1043/480/300" alt="Autumn forest">4. Text Around a Shape: shape-outside
shape-outside works on floated elements and tells text which outline to wrap around.
Example
<style>
.round { float: left; width: 130px; height: 130px; margin: 0 14px 6px 0; border-radius: 50%;
shape-outside: circle(50%); object-fit: cover; }
</style>
<p>
<img class="round" src="https://picsum.photos/id/1027/260/260" alt="Portrait">
Notice how these lines curve around the circular photo instead of stopping at a square
edge. That is shape-outside at work: the float still takes up a square, but the text
follows the circle. It's a small detail that makes a profile or article look like it came
out of a printed magazine. Add more text to see the curve continue down the side.
</p>Common Beginner Mistakes
1. Clipped parts are still there. clip-path only hides them; they still take up space in the layout.
2. Animating polygons with different point counts. It snaps instead of morphing.
3. shape-outside without float. It has no effect.
Practice Questions
- Clip an element into a circle.
- Write a polygon for a triangle pointing up.
- What does
inset(10% round 20px)make? - Why might a polygon animation snap instead of morph?
- Which property makes text wrap around a circle, and what else does the element need?
Practice Answers
clip-path: circle(50%);clip-path: polygon(50% 0, 100% 100%, 0 100%);- A rectangle cut 10% in from every edge, with 20px rounded corners.
- The two polygons have a different number of points.
shape-outside: circle(50%), and the element must be floated.
Key Takeaways
clip-pathshows only part of an element:circle,ellipse,inset,polygon.- Polygon points are percentages from the top left.
- Shapes with equal point counts animate smoothly.
shape-outside(on floats) wraps text around a shape.