On this page9 sections
  1. Learning Objectives
  2. 1. Basic Shapes
  3. 2. Slanted Sections
  4. 3. Animating Shapes
  5. 4. Text Around a Shape: shape-outside
  6. Common Beginner Mistakes
  7. Practice Questions
  8. Practice Answers
  9. Key Takeaways

Lecture 041: Clip-path & Shapes

Category7: Advanced Styling
Lecture041 of 057
Estimated video length10 min
TargetCSS3 · any modern browser
LevelIntermediate

Every element is a rectangle, but it doesn't have to look like one. clip-path cuts an element into a circle, a triangle, a slanted banner or any polygon. shape-outside makes text flow around that shape.


Learning Objectives

  • Clip elements with circle(), ellipse(), inset() and polygon()
  • Animate between shapes
  • Wrap text around a shape with shape-outside

1. Basic Shapes

Example

html
<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>
FunctionShape
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

html
<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:

html
<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

html
<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

  1. Clip an element into a circle.
  2. Write a polygon for a triangle pointing up.
  3. What does inset(10% round 20px) make?
  4. Why might a polygon animation snap instead of morph?
  5. Which property makes text wrap around a circle, and what else does the element need?

Practice Answers

  1. clip-path: circle(50%);
  2. clip-path: polygon(50% 0, 100% 100%, 0 100%);
  3. A rectangle cut 10% in from every edge, with 20px rounded corners.
  4. The two polygons have a different number of points.
  5. shape-outside: circle(50%), and the element must be floated.

Key Takeaways

  • clip-path shows 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.