CSS Advanced Features

CSS Shapes

Master CSS shapes to control how text flows around elements. Create magazine-style layouts and organic text wrapping with shape-outside.

How do you make text wrap around a shape in CSS?

Float the element and give it a shape-outside: for example float: left; shape-outside: circle(50%); makes the following text wrap around a circle instead of a rectangle. shape-outside accepts basic shapes, images with transparency, and gradients, and shape-margin adds space around the shape.

.portrait {
  float: left;
  width: 200px; height: 200px;
  shape-outside: circle(50%);
  clip-path: circle(50%);
  shape-margin: 1rem;
}

Interactive CSS Shapes Demo

Code Editor

<div class="circle"></div>
<p>Text wraps around the circle because of <code>shape-outside</code>, not just around a rectangle. Keep adding text in the HTML tab to see the curve follow the shape all the way down the side of the float.</p>

Preview

Understanding CSS Shapes

Shape-Outside Property

/* Basic shape-outside syntax */ .shaped-element {
  float: left; /* Required for shape-outside to work */
  width: 200px;
  height: 200px;
  shape-outside: circle(50% at center);
  shape-margin: 20px; /* Space around the shape */
}

/* Different shape values */ .circle-shape {
  shape-outside: circle(100px at center);
}

.ellipse-shape {
  shape-outside: ellipse(100px 50px at center);
}

.polygon-shape {
  shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);
}

.inset-shape {
  shape-outside: inset(10px 20px 30px 40px round 15px);
}

Shape-outside defines the geometric shape around which inline content flows.

Basic Shapes

/* Circle with radius */ .circle {
  shape-outside: circle(80px);
}

/* Circle with percentage */ .circle-percent {
  shape-outside: circle(40%);
}

/* Positioned circle */ .circle-positioned {
  shape-outside: circle(60px at 30% 70%);
}

/* Ellipse */ .ellipse {
  shape-outside: ellipse(100px 60px);
}

/* Closest-side keyword */ .closest {
  shape-outside: circle(closest-side at 25% 25%);
}

Basic geometric shapes with various sizing options

Image-Based Shapes

/* Image URL shape */ .image-shape {
  float: left;
  shape-outside: url('path/to/image.png');
  shape-image-threshold: 0.5;
}

/* Gradient shape */ .gradient-shape {
  shape-outside: linear-gradient(
    45deg, transparent 40%, black 60%
  );
}

/* CSS mask as shape */ .mask-shape {
  shape-outside: url('#svg-mask');
}

/* Data URI shape */ .data-shape {
  shape-outside: url('data:image/svg+xml;...');
}

Use images and gradients to define complex shapes

Shape-Margin and Shape-Image-Threshold

Controlling Shape Behavior

/* Shape margin - adds space around the shape */ .shape-with-margin {
  shape-outside: circle(50%);
  shape-margin: 20px; /* Space between shape and text */
}

/* Variable margin */ .responsive-margin {
  shape-outside: polygon(0% 0%, 100% 0%, 50% 100%);
  shape-margin: clamp(10px, 2vw, 30px);
}

/* Image threshold - controls which parts of image define shape */ .image-threshold {
  shape-outside: url('transparent-image.png');
  shape-image-threshold: 0.3; /* 0.0 = transparent, 1.0 = opaque */
}

/* Fine-tuned threshold */ .precise-threshold {
  shape-outside: url('gradient-mask.png');
  shape-image-threshold: 0.7;
  shape-margin: 15px;
}

Fine-tune shape behavior with margin and threshold properties.

Margin Examples

/* No margin - text touches shape */ .no-margin {
  shape-outside: circle(50%);
  shape-margin: 0;
}

/* Comfortable reading space */ .comfortable {
  shape-outside: ellipse(40% 60%);
  shape-margin: 1.5em;
}

/* Large margin for emphasis */ .emphasis {
  shape-outside: polygon(20% 0%, 80% 0%, 100% 100%, 0% 100%);
  shape-margin: 3rem;
}

/* Responsive margin */ .responsive {
  shape-margin: calc(1rem + 2vw);
}

Control spacing between shapes and flowing text

Threshold Control

/* Low threshold - includes more transparent areas */ .inclusive {
  shape-outside: url('soft-edges.png');
  shape-image-threshold: 0.1;
}

/* Medium threshold - balanced */ .balanced {
  shape-outside: url('portrait.jpg');
  shape-image-threshold: 0.5;
}

/* High threshold - only solid areas */ .solid-only {
  shape-outside: url('high-contrast.png');
  shape-image-threshold: 0.9;
}

/* Dynamic threshold with CSS variables */ .dynamic {
  shape-image-threshold: var(--threshold, 0.5);
}

Adjust how image transparency affects shape boundaries

Practical Layout Applications

Magazine-Style Layouts

/* Drop cap styling */ .drop-cap {
  float: left;
  font-size: 4rem;
  line-height: 1;
  margin: 0.25rem 0.5rem 0 0;
  padding: 0.5rem;
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-radius: 8px;
  shape-outside: inset(0 round 8px);
  shape-margin: 8px;
}

/* Pull quote with custom shape */ .pull-quote {
  float: right;
  width: 300px;
  padding: 2rem;
  margin: 0 0 1rem 2rem;
  background: #f8f9fa;
  border-radius: 20px;
  clip-path: polygon(0% 0%, 90% 0%, 100% 30%, 100% 100%, 0% 100%);
  shape-outside: polygon(0% 0%, 90% 0%, 100% 30%, 100% 100%, 0% 100%);
  shape-margin: 20px;
}

Create sophisticated editorial layouts with shaped elements.

Image Integration

/* Text wrapping around portrait */ .portrait-wrap {
  float: left;
  width: 300px;
  height: 400px;
  margin: 0 2rem 1rem 0;
  shape-outside: url('portrait.png');
  shape-image-threshold: 0.3;
  shape-margin: 20px;
  clip-path: ellipse(40% 50% at center);
}

/* Organic shape from SVG */ .organic-shape {
  shape-outside: url('blob-shape.svg');
  clip-path: url('blob-shape.svg');
}

/* Product image cutout */ .product-cutout {
  shape-outside: url('product-silhouette.png');
  shape-image-threshold: 0.1;
}

Seamlessly integrate images with text flow

Responsive Considerations

/* Responsive shape sizing */ @media (min-width: 768px) {
  .responsive-shape {
    shape-outside: circle(120px);
    shape-margin: 30px;
  }
}

@media (max-width: 767px) {
  .responsive-shape {
    shape-outside: none;
    float: none;
    width: 100%;
    margin: 1rem 0;
  }
}

/* Container query approach */ @container (min-width: 500px) {
  .container-shape {
    shape-outside: polygon(...);
  }
}

Adapt shapes for different screen sizes and contexts

Browser Support & Best Practices

Best Practices

  • • Always use float with shape-outside
  • • Provide fallbacks for unsupported browsers
  • • Test with actual content lengths
  • • Use shape-margin for better readability
  • • Consider mobile layouts carefully
  • • Optimize image shapes for performance

Common Use Cases

  • • Editorial and magazine layouts
  • • Product showcases with text wrap
  • • Creative hero sections
  • • Blog post enhancements
  • • Testimonial and quote designs
  • • Portfolio and gallery layouts

CSS Shapes — step by step

1 / 4
1

shape-outside Property

shape-outside defines a geometric boundary that text wraps around on a floated element — circle(), ellipse(), polygon(), or inset() shapes.

1 of 4
🔍shape-outside Requires a Float
shape-outside only works on floated elements — it controls the float area that text wraps around. Set float: left or float: right and a width/height for the shape to take effect.

🎯 Quick Check

Which CSS property makes text wrap around a non-rectangular float shape?

CSS Shapes: summary

Key points

  • shape-outside only works on floated elements.
  • It changes how text wraps, not how the element looks; pair it with clip-path to match the visuals.
  • Using an image with an alpha channel for shape-outside lets text follow the outline of a cut-out photo.

Frequently asked questions

›Why is shape-outside not working?

The element must be floated and have a width and height. Images used as shapes must also come from the same origin or allow CORS.