🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
đŸ’ŧ Servicesâ„šī¸ Aboutâœ‰ī¸ ContactView Pricing Plansfrom $10

CSS Shapes: clip-path, shape-outside, and Radius

Web StylesđŸŸĸ Free Lesson

CSS Shapes: clipPath, shape-outside, and Radius

Rectangles are the default contract of the web: every box, image, and button paints to its border box. CSS gives you at least three independent ways to break that contract, each with a different effect on layout. clip-path cuts the painted output to a shape — the box still occupies its rectangular slot, but what you see is a circle, a polygon, or a path. shape-outside changes how text wraps around a floated element's contour, moving the line boxes themselves rather than the paint. And border-radius, the quiet veteran, rounds corners — or, when pushed into percentage pairs and animated keyframes, morphs blobs. Knowing which of the three you are reaching for decides whether your neighbors notice a change, whether the element is still clickable outside its visual edge, and whether you need a fallback.

clipPath: cutting paint without moving layout

clip-path accepts basic shapes — circle(), ellipse(), inset(), polygon() — plus url() references to SVG clip paths and the path() function for arbitrary curves. Coordinates in basic shapes can be percentages of the reference box, which makes them resolution-independent. The reference box itself is controlled by clip-path's box value (border-box by default, also content-box, fill-box, and others), so knowing which box the percentages resolve against matters when padding or borders shift the geometry:

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

.bubble-chart {
  clip-path: ellipse(50% 45% at 50% 50%);
}

.inset-card {
  clip-path: inset(8px round 12px);
}

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

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

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

.star {
  clip-path: polygon(
    50% 0%, 61% 35%, 98% 35%, 68% 57%,
    79% 91%, 50% 70%, 21% 91%, 32% 57%,
    2% 35%, 39% 35%
  );
}

Polygons are lists of x/y pairs — percentages of the reference box or absolute lengths — connected in order. Ten points give a star; three give a triangle; six, a hexagon. The clip happens at paint time, so a clipped image still reserves its full rectangular footprint in layout, and crucially the clipped-away regions do not receive pointer events — a circle-clipped card ignores clicks in the corners. That behavioral detail is often exactly what you want for avatars and icon tiles, and occasionally a surprise when a rounded-looking button loses its corner hit areas.

The progressive-enhancement pattern matters here: without clip-path support (or before it applies), content is unclipped — a rectangle instead of a star. For decorative shapes that is fine. For content that must stay inside its shape, layer a border-radius fallback underneath and let clip-path override it where supported.

shape-outside: moving text, not pixels

shape-outside does something clipPath cannot: it affects the layout of surrounding inline content. It only applies to floated elements — floats reserve a line-box contour — and the values reuse the same basic shapes: circle(), ellipse(), inset(), polygon(), plus url() for SVG shapes and gradients. A paragraph flowing beside a circular float wraps to the circle's edge rather than the float's bounding box, which is the magazine effect the specification was built for:

.article-figure {
  float: inline-start;
  width: 14rem;
  height: 14rem;
  margin-block-end: 1rem;
  margin-inline-end: 1.5rem;
  shape-outside: circle(50%);
  shape-margin: 1rem;
  clip-path: circle(50%);
}

.article-figure.is-diagonal {
  float: inline-end;
  clip-path: none;
  shape-outside: polygon(0 0, 100% 0, 100% 60%, 0 100%);
}

shape-margin adds breathing room between the contour and the text — without it, glyphs crowd the curve. Note the deliberate combination in the example: clip-path shapes the image itself while shape-outside shapes the wrap; you can use either alone (an unclipped image with a curved text contour looks wrong; a clipped square with rectangular text flow looks unremarkable), and using both with matching geometry makes the two systems agree. shape-image-threshold sets the alpha level at which a gradient or image's shape takes effect, analogous to a transparency cutoff.

border-radius: still the workhorse

Rounding corners is one declaration: one value for all corners, two for top-left/bottom-right and top-right/bottom-left, four in clockwise order from top-left, or longhands (border-start-start-radius and friends, which follow writing mode). Mixing units and per-corner values gets you tags, folded cards, and speech-bubble-ready shapes. Percentage radii resolve against each axis independently, so border-radius: 50% on a square is a circle and on a rectangle an ellipse. The spec even supports a slash syntax for elliptical radii — border-radius: 10px / 40px sets horizontal then vertical radii — and overlapping curves are scaled down proportionally if adjacent radii exceed the side length:

.pill { border-radius: 9999px; }

.notch {
  border-radius: 4px 4px 4px 32px;
}

.speech {
  position: relative;
  background: #ffffff;
  border: 2px solid #cbd5e1;
  border-radius: 14px;
  padding: 1rem 1.25rem;
}

.speech::after {
  content: "";
  position: absolute;
  top: -11px;
  left: 24px;
  width: 0;
  height: 0;
  border: 11px solid transparent;
  border-block-end-color: #cbd5e1;
}

.speech::before {
  content: "";
  position: absolute;
  top: -7px;
  left: 26px;
  width: 0;
  height: 0;
  border: 9px solid transparent;
  border-block-end-color: #ffffff;
  z-index: 1;
}

.card-hover:hover {
  border-radius: 16px 16px 48% 48% / 16px 16px 12% 12%;
}

The speech bubble is the canonical pseudo-element + border-triangle technique: a zero-size element with colored transparent borders forms the arrow, and a second inner triangle masks the bubble's border line. One longhand worth remembering is overflow: clip paired with radii — images inside a rounded container need either overflow: hidden on the parent or their own radii, or their square corners peek past the curve.

Morphing blobs and conic donuts

Two gradients deserve a mention because they produce shapes no border or polygon reaches easily. Animating border-radius between elliptical value sets gives the popular morphing-blob background: the values interpolate per corner, so keyframes can drift through four different radius sets for organic movement. conic-gradient produces pie and donut visuals: fill a circle with a conic gradient covering a sweep (for example solid to 270 degrees, then a second color), then punch out the middle with a radial gradient or a pseudo-element — the result is a progress donut in pure CSS, no SVG:

.blob {
  width: 12rem;
  height: 12rem;
  background: #2563eb;
  animation: morph 9s ease-in-out infinite;
}

@keyframes morph {
  0%, 100% { border-radius: 30% 70% 70% 30% / 30% 30% 70% 70%; }
  33%      { border-radius: 58% 42% 75% 25% / 76% 46% 54% 24%; }
  66%      { border-radius: 50% 50% 33% 67% / 55% 27% 73% 45%; }
}

.donut {
  width: 6rem;
  height: 6rem;
  border-radius: 50%;
  background: conic-gradient(#2563eb 0deg 270deg, #e2e8f0 270deg 360deg);
  -webkit-mask: radial-gradient(circle, transparent 55%, #000 56%);
  mask: radial-gradient(circle, transparent 55%, #000 56%);
}

The mask version is cleaner than the pseudo-element hole because it scales with one gradient and leaves the box model untouched.

Support, selection, and honest limits

All three features are baseline-supported in modern browsers, but the escape hatches still matter. clip-path and shape-outside degrade to rectangles — usually harmless. A clipped element's invisible corners cannot be clicked or focused, so never rely on the clipped region for interaction targets. shape-outside requires floats, which means it does not participate in flex or grid item layout — the float must live inside a block formatting context with flowing text beside it. And clipPath percentages resolve against the reference box, not the viewport, so shapes stay proportional to their element rather than the screen — scale the element, not the percentages.

SVG paths, path(), and reusing geometry

Polygon vertices are perfect for straight-edged shapes, but curves need either the built-in circle and ellipse helpers or real path data. clip-path: path("M 0 0 ...") accepts an SVG path string with absolute coordinates — the catch is that those coordinates are absolute pixels in the reference box's coordinate space, with no percentage scaling, so a path authored at 100×100 renders at exactly that size regardless of element dimensions. For resolution-independent curves, reference an inline SVG clip path instead: define clipPath with clipPathUnits="objectBoundingBox" and normalized coordinates from 0 to 1, then point clip-path: url(#blob) at it. The shape scales with the element at any size.

.icon-shape {
  clip-path: url("#blob-clip");
}

.custom-cut {
  clip-path: path("M 10 0 L 90 0 Q 100 0 100 10 L 100 90 Q 100 100 90 100 L 10 100 Q 0 100 0 90 L 0 10 Q 0 0 10 0 Z");
}

A practical workflow: draw the shape once in a vector tool, export the path data, and choose the mechanism by whether you need scaling. Interactive icons, logos, and masks that appear at many sizes want the url() reference with object bounding box units. One-off decorative cuts at a known size are fine with path(). Keep the inline clipPath definition in the document once and reference it from every element — the same geometry then governs a hero cutout, a thumbnail mask, and a hover variant without duplicating coordinate lists across the stylesheet.

Common Mistakes

Corners of a circle-clipped button are unclickable

Fix: clipPath removes pointer events outside the shape — keep interactive targets rectangular or enlarge the shape so its full area covers the hit region

shape-outside has no visible effect

Fix: It only applies to floated elements with inline content flowing beside them; static or flex/grid children are ignored — set a float and enough text to wrap

Image corners peek out of a rounded container

Fix: Set overflow: hidden or clip on the container, or give the image matching border-radius values

Speech bubble arrow sits under the bubble border

Fix: Layer two triangles — an outer one matching the border color slightly larger, and an inner one matching the background — with the inner at a higher z-index

Best Practices

  • Provide border-radius or other fallbacks before clipPath for content that must stay inside its shape
  • Pair shape-outside with shape-margin so text does not crowd the contour
  • Use conic-gradient plus mask for donut progress visuals instead of hand-built pseudo-element stacks
  • Keep polygons percentage-based so shapes scale with their element
  • Test click targets after clipping — invisible regions do not receive pointer events

Interview Questions

Q1: What is the difference between clipPath and shape-outside?

clipPath clips the element's painted output to a shape while the box keeps its rectangular layout footprint and no surrounding content changes. shape-outside affects the layout of inline content around a floated element, changing where line boxes break, but does not clip the element itself. They solve different problems and can be combined.

Q2: How does a CSS-only speech bubble work?

A rounded rectangle for the bubble plus two zero-size pseudo-elements with transparent borders whose colored edge forms a triangle. The outer triangle matches the border color and sits slightly larger; the inner triangle matches the bubble background and masks the border line where the arrow meets the box, producing a seamless tail.

Q3: Why do percentages in clipPath resolve against the element rather than the screen?

Basic shapes resolve against the reference box — border-box by default — so circle(50%) is always half the element's own size, keeping the shape proportional at any element size. Changing the box keyword (content-box, fill-box) changes which box is referenced when padding or strokes are involved.

Key Takeaways

  • clipPath cuts paint without changing layout, and clipped-away regions stop receiving pointer events
  • shape-outside reflows text around a float's contour and pairs with shape-margin for spacing
  • border-radius handles corners per side with unit mixing and slash syntax for ellipses
  • Pseudo-element border triangles build speech bubbles; animating border-radius builds blobs
  • conic-gradient plus mask renders donuts and pie charts in pure CSS
  • All three degrade to rectangles — layer fallbacks for content that must stay inside its shape
CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-12

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Web Development Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement