CSS shape-outside Property

The CSS shape-outside property defines a shape around which inline content flows when an element is floated.

Instead of wrapping text around a rectangular box, shape-outside allows text to follow circles, ellipses, polygons, image transparency, and other supported shapes. It is commonly used to create more flexible layouts around illustrations, photographs, and decorative elements.

shape-outside Syntax

The shape-outside property accepts a basic shape, a reference box, an image, or the keyword none.

Basic Syntax

selector {
  shape-outside: circle(50%);
}

Common Values

.shape {
  shape-outside: none;
}
.shape {
  shape-outside: circle(50%);
}
.shape {
  shape-outside: ellipse(50% 40%);
}
.shape {
  shape-outside: inset(10px);
}
.shape {
  shape-outside: polygon(50% 0, 100% 100%, 0 100%);
}
.shape {
  shape-outside: margin-box;
}
.shape {
  shape-outside: url("/img/transparent-shape.png");
}

Combining a Shape With a Reference Box

.shape {
  shape-outside: circle(45%) content-box;
}

The reference box determines the coordinate system used to calculate the shape.

CSS-Wide Keywords

.shape {
  shape-outside: initial;
}
.shape {
  shape-outside: inherit;
}
.shape {
  shape-outside: unset;
}
.shape {
  shape-outside: revert;
}
.shape {
  shape-outside: revert-layer;
}

To affect text wrapping, the element must be floated and have dimensions that establish a usable shape area.

Property Values

Value Description
none Uses normal rectangular float wrapping. This is the initial value.
circle() Defines a circular wrapping shape.
ellipse() Defines an elliptical wrapping shape.
inset() Defines an inset rectangular shape, optionally with rounded corners.
polygon() Defines a shape using a series of coordinate points.
path() Defines a shape using SVG path data, subject to browser support.
shape() Defines a shape using CSS shape commands, where supported.
<image> Defines the wrapping shape using image transparency.
margin-box Uses the element's margin box as the wrapping shape.
border-box Uses the element's border box as the reference shape.
padding-box Uses the element's padding box as the reference shape.
content-box Uses the element's content box as the reference shape.
initial Resets the property to none.
inherit Uses the computed value from the parent element.
unset Resets the property to none because it is not inherited.
revert Reverts the property according to CSS cascade origin rules.
revert-layer Reverts the property according to CSS cascade layer rules.

Property Characteristics

Characteristic Value
Initial value none
Inherited No
Applies to Floats
Computed value As specified, with URLs made absolute
Animation type By computed value type
Percentages Relative to the selected reference box
Related properties shape-margin, shape-image-threshold, float
Specification CSS Shapes Module Level 1 and related CSS Shapes specifications

Valid Examples

.shape {
  shape-outside: circle(45%);
}
.shape {
  shape-outside: ellipse(50% 35%);
}
.shape {
  shape-outside: inset(10% round 20px);
}
.shape {
  shape-outside: polygon(50% 0, 100% 100%, 0 100%);
}
.shape {
  shape-outside: circle(40%) border-box;
}
.shape {
  shape-outside: linear-gradient(90deg, black 50%, transparent 50%);
}

Invalid Examples

.shape {
  shape-outside: round;
}
.shape {
  shape-outside: 20px;
}
.shape {
  shape-outside: auto;
}
.shape {
  shape-outside: circle;
}
.shape {
  shape-outside: circle(50%) ellipse(40%);
}

The property requires a supported shape, image, reference box, or CSS-wide keyword. A standalone length or an incomplete shape function is invalid.

How It Works

Normally, text wraps around the rectangular margin box of a floated element. The shape-outside property replaces that rectangular wrapping boundary with a calculated shape.

Step 1: Float an Element

.shape {
  float: left;
  width: 180px;
  height: 180px;
}

The float allows surrounding inline content to flow beside the element.

Step 2: Define a Shape

.shape {
  shape-outside: circle(45%);
}

The browser calculates a circular wrapping boundary.

Step 3: Add Spacing

.shape {
  shape-margin: 10px;
}

The additional margin expands the calculated shape's exclusion area.

Step 4: Allow Text to Wrap

Text follows the shape boundary wherever sufficient space remains in the containing block.

Complete Example

.shape {
  float: left;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background-color: #2563eb;
  shape-outside: circle(45%);
  shape-margin: 10px;
}

Important Consideration

The property changes text wrapping, not the visible outline of the element. Use properties such as border-radius or clip-path when the element's appearance also needs to match the wrapping shape.

Basic Shapes

Basic shape functions define wrapping boundaries using geometric coordinates.

circle()

.circle-shape {
  float: left;
  width: 180px;
  height: 180px;
  shape-outside: circle(45%);
}

The circle() function creates a circular wrapping boundary.

ellipse()

.ellipse-shape {
  float: left;
  width: 220px;
  height: 160px;
  shape-outside: ellipse(50% 40%);
}

The ellipse() function allows different horizontal and vertical radii.

inset()

.inset-shape {
  float: left;
  width: 200px;
  height: 180px;
  shape-outside: inset(15px round 20px);
}

The inset() function defines a rectangular shape inset from the reference box, with optional rounded corners.

polygon()

.polygon-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: polygon(50% 0, 100% 100%, 0 100%);
}

The polygon() function creates a shape from a sequence of points.

path()

.path-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: path("M 100 0 L 200 200 L 0 200 Z");
}

The path() function uses SVG path commands. Support for this function with shape-outside should be checked before relying on it.

shape()

.custom-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: shape(from 50% 0%, line to 100% 100%, line to 0% 100%, close);
}

The shape() function provides CSS-based shape commands. Browser support for this newer syntax may be limited.

Important Consideration

The shape functions define wrapping geometry. They do not automatically draw, clip, or color the element.

Reference Boxes

Reference boxes determine which part of an element's box model is used to calculate the shape.

margin-box

.shape {
  shape-outside: margin-box;
}

Uses the margin box, including its rounded corners where applicable.

border-box

.shape {
  shape-outside: border-box;
}

Uses the border box as the wrapping shape.

padding-box

.shape {
  shape-outside: padding-box;
}

Uses the padding box as the wrapping shape.

content-box

.shape {
  shape-outside: content-box;
}

Uses the content box as the wrapping shape.

Combining a Basic Shape With a Reference Box

.shape {
  shape-outside: circle(45%) content-box;
}

The circle is calculated relative to the content box rather than the default margin-box reference.

Reference Box Comparison

Reference Box Includes
content-box Content area
padding-box Content and padding
border-box Content, padding, and border
margin-box Content, padding, border, and margin area

Important Consideration

When a basic shape is supplied without an explicit reference box, the margin box is used as its reference.

Image-Based Shapes

The shape-outside property can use an image's alpha channel to calculate an irregular wrapping boundary.

Transparent PNG

.image-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: url("/img/transparent-shape.png");
}

The browser uses the image's transparency to determine the wrapping shape.

CSS Gradient

.gradient-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: radial-gradient(circle, black 40%, transparent 75%);
}

The gradient's alpha values define the shape without requiring an external image.

Linear Gradient

.gradient-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: linear-gradient(135deg, black 50%, transparent 50%);
}

The opaque portion of the gradient contributes to the wrapping boundary.

Controlling the Alpha Threshold

.image-shape {
  shape-outside: url("/img/transparent-shape.png");
  shape-image-threshold: 0.5;
}

Only pixels with alpha values greater than the threshold contribute to the shape.

Image Security Restrictions

Image-based shapes must satisfy browser security requirements. Cross-origin images may require CORS permission before their alpha data can be used.

Important Consideration

The image used by shape-outside defines the wrapping boundary but is not automatically displayed. Use an image element or a background image when the shape should also be visible.

Using shape-margin

The shape-margin property expands the calculated wrapping boundary, adding space between the shape and surrounding text.

Without Additional Spacing

.shape {
  shape-outside: circle(40%);
  shape-margin: 0;
}

Text follows the original circular boundary.

With Additional Spacing

.shape {
  shape-outside: circle(40%);
  shape-margin: 15px;
}

Text wraps around an expanded version of the circle.

Percentage Spacing

.shape {
  shape-outside: ellipse(45% 35%);
  shape-margin: 3%;
}

The margin uses a percentage of the containing block's width.

Important Consideration

The expanded shape cannot extend beyond the floated element's margin box. Increasing shape-margin beyond that limit does not create additional wrapping space.

Using shape-image-threshold

The shape-image-threshold property controls which image alpha values are included when calculating an image-based wrapping shape.

Low Threshold

.image-shape {
  shape-outside: radial-gradient(circle, black 30%, transparent 80%);
  shape-image-threshold: 0.2;
}

More partially transparent pixels contribute to the shape.

Medium Threshold

.image-shape {
  shape-outside: radial-gradient(circle, black 30%, transparent 80%);
  shape-image-threshold: 0.5;
}

Only pixels more than half opaque contribute to the shape.

High Threshold

.image-shape {
  shape-outside: radial-gradient(circle, black 30%, transparent 80%);
  shape-image-threshold: 0.8;
}

Only pixels with relatively high opacity contribute to the shape.

Combining All Three Shape Properties

.image-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: radial-gradient(circle, black 30%, transparent 80%);
  shape-image-threshold: 0.5;
  shape-margin: 15px;
}

The gradient defines the shape, the threshold selects its contributing pixels, and the margin adds spacing around the resulting boundary.

Important Consideration

The threshold affects image-based shapes, not geometric basic shapes such as circle() or polygon().

shape-outside vs. clip-path

The shape-outside and clip-path properties can use similar shape functions, but they serve different purposes.

shape-outside

.shape {
  float: left;
  shape-outside: circle(50%);
}

Controls how surrounding text wraps around the floated element.

clip-path

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

Controls which parts of the element are visibly rendered.

Combining Both Properties

.shape {
  float: left;
  width: 180px;
  height: 180px;
  background-color: #2563eb;
  clip-path: circle(45%);
  shape-outside: circle(45%);
  shape-margin: 10px;
}

The visible element is clipped to a circle, and surrounding text follows a matching circular shape with additional spacing.

Property Comparison

Feature shape-outside clip-path
Primary purpose Controls text wrapping Controls visible clipping
Requires a float Yes, for its wrapping effect No
Changes visible shape No Yes
Affects text flow Yes No
Supports basic shapes Yes Yes

Important Consideration

Use shape-outside for text flow and clip-path for visual clipping. They can be combined when both effects are needed.

Practical Examples

Text Around a Circle

.circle-shape {
  float: left;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  shape-outside: circle(50%);
  shape-margin: 12px;
}

Wraps text around a circular element.

Text Around an Ellipse

.ellipse-shape {
  float: right;
  width: 220px;
  height: 160px;
  border-radius: 50%;
  shape-outside: ellipse(50% 50%);
  shape-margin: 10px;
}

Wraps text around an elliptical element floated to the right.

Triangular Text Wrapping

.triangle-shape {
  float: left;
  width: 180px;
  height: 180px;
  background-color: #2563eb;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  shape-outside: polygon(50% 0, 100% 100%, 0 100%);
}

Creates a visible triangle with a matching text wrapping boundary.

Rounded Rectangle

.rounded-shape {
  float: left;
  width: 200px;
  height: 150px;
  border-radius: 25px;
  shape-outside: inset(0 round 25px);
  shape-margin: 10px;
}

Allows text to follow a rounded rectangular boundary.

Transparent Image

.image-shape {
  float: left;
  width: 200px;
  height: 200px;
  shape-outside: url("/img/transparent-shape.png");
  shape-image-threshold: 0.5;
  shape-margin: 10px;
}

Uses image transparency to determine an irregular text wrapping boundary.

Gradient-Based Shape

.gradient-shape {
  float: left;
  width: 200px;
  height: 200px;
  background: radial-gradient(circle, #2563eb 30%, transparent 75%);
  shape-outside: radial-gradient(circle, black 30%, transparent 75%);
  shape-image-threshold: 0.5;
}

Uses a gradient's alpha channel to create a wrapping shape.

Responsive Shape

.shape {
  float: left;
  width: 180px;
  height: 180px;
  shape-outside: circle(45%);
}
@media (max-width: 600px) {
  .shape {
    float: none;
    shape-outside: none;
  }
}

Disables custom text wrapping on smaller screens.

Resetting the Shape

.shape {
  shape-outside: none;
}

Returns to normal rectangular float wrapping.

shape-outside Example

This example compares text wrapping around a circle, ellipse, and triangle. Each shape uses shape-outside to control the text boundary and a matching visual style to display the shape.

HTML Example

<div class="shape-outside-demo">
  <div class="shape-panel">
    <h3>Circle</h3>
    <div class="demo-shape circle"></div>
    <p>Text wraps around the circular shape rather than following the rectangular box. The curved boundary allows words to flow closer to the circle near its top and bottom edges.</p>
  </div>
  <div class="shape-panel">
    <h3>Ellipse</h3>
    <div class="demo-shape ellipse"></div>
    <p>Text wraps around an elliptical shape with different horizontal and vertical dimensions. The wrapping boundary follows the curve instead of the rectangular float.</p>
  </div>
  <div class="shape-panel">
    <h3>Triangle</h3>
    <div class="demo-shape triangle"></div>
    <p>Text wraps around a triangular shape defined by polygon coordinates. The available text space changes as the triangle becomes wider toward its bottom edge.</p>
  </div>
</div>

CSS Example

.shape-outside-demo {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr));
  gap: 15px;
}
.shape-outside-demo .shape-panel {
  min-height: 320px;
  padding: 15px;
  border: 1px solid #cbd5e1;
  background-color: #f8fafc;
  display: flow-root;
}
.shape-outside-demo .shape-panel h3 {
  margin-top: 0;
  font-size: 1rem;
}
.shape-outside-demo .demo-shape {
  float: left;
  width: 150px;
  height: 150px;
  background-color: #2563eb;
  shape-margin: 10px;
}
.shape-outside-demo .circle {
  border-radius: 50%;
  shape-outside: circle(50%);
}
.shape-outside-demo .ellipse {
  width: 160px;
  height: 120px;
  border-radius: 50%;
  shape-outside: ellipse(50% 50%);
}
.shape-outside-demo .triangle {
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  shape-outside: polygon(50% 0, 100% 100%, 0 100%);
}
Browser Result

Circle

Text wraps around the circular shape rather than following the rectangular box. The curved boundary allows words to flow closer to the circle near its top and bottom edges.

Ellipse

Text wraps around an elliptical shape with different horizontal and vertical dimensions. The wrapping boundary follows the curve instead of the rectangular float.

Triangle

Text wraps around a triangular shape defined by polygon coordinates. The available text space changes as the triangle becomes wider toward its bottom edge.

The circle and ellipse demonstrate curved text wrapping, while the triangle demonstrates wrapping around a polygon with straight edges.

Comparing the Shapes

Shape Function Wrapping Boundary
Circle circle() Circular
Ellipse ellipse() Elliptical
Triangle polygon() Three straight edges

Increasing Shape Spacing

.shape-outside-demo .demo-shape {
  shape-margin: 20px;
}

Text wraps farther away from the calculated shape boundaries, within the available margin-box limits.

Changing the Circle Size

.shape-outside-demo .circle {
  shape-outside: circle(35%);
}

The wrapping boundary becomes smaller while the visible circle retains its original dimensions.

Returning to Rectangular Wrapping

.shape-outside-demo .demo-shape {
  shape-outside: none;
}

Text returns to normal rectangular float wrapping.

Accessibility Considerations

CSS Shapes can improve visual presentation, but text readability and document structure should remain priorities.

Maintain Readable Line Lengths

Large shapes can leave narrow areas for text. Ensure enough horizontal space remains for comfortable reading.

Provide Adequate Spacing

Use shape-margin to prevent text from appearing crowded against irregular boundaries.

Preserve Logical Reading Order

The property changes visual wrapping without changing the HTML source order. Keep content in a meaningful sequence.

Provide Alternative Text

Informative images should include appropriate alternative text. Decorative images can use empty alternative text.

Test Text Zoom

Verify that text remains readable when users enlarge fonts or zoom the page.

Responsive Layouts

Consider removing complex shapes on narrow screens when they leave insufficient room for text.

@media (max-width: 600px) {
  .shape {
    float: none;
    shape-outside: none;
  }
}

Avoid Essential Information in Decorative Shapes

Shapes should enhance the presentation of content rather than communicate information that is unavailable to assistive technologies.

Common Mistakes

Forgetting to Float the Element

.shape {
  width: 180px;
  height: 180px;
  shape-outside: circle(50%);
}

Without a float, the property does not produce its intended text wrapping effect.

Expecting the Shape to Be Visible

The property defines text wrapping only. Use border-radius, clip-path, or another visual styling method to display the intended shape.

Using an Invalid Shape Value

.shape {
  shape-outside: round;
}

Use a supported shape function or reference box.

Forgetting Element Dimensions

Floated elements need a usable size for shape calculations. Specify appropriate dimensions when necessary.

Confusing shape-outside With clip-path

The former controls text wrapping, while the latter controls visible clipping.

Ignoring the Margin Box

The wrapping shape is constrained by the floated element's margin box.

Using an Opaque Image Without Considering Transparency

Image-based shapes rely on alpha values. A fully opaque image generally produces a rectangular wrapping region.

Ignoring Cross-Origin Restrictions

Images from another origin may require CORS permission before they can be used for shape calculations.

Expecting Inheritance

The property is not inherited. Apply it directly to each floated element that needs custom wrapping.

Using Shapes in Narrow Containers

Large shapes can leave insufficient space for text, especially on smaller screens.

Assuming All Shape Functions Have Equal Support

Newer functions such as shape() may have different browser support from established functions such as circle() and polygon().

Important Considerations

Keep the following points in mind when using shape-outside:

  • It defines a shape around which inline content wraps.
  • The initial value is none.
  • The property is not inherited.
  • It applies to floated elements.
  • It does not change the visible appearance of an element.
  • It supports geometric basic shapes such as circles, ellipses, insets, and polygons.
  • It can use image transparency to calculate irregular wrapping boundaries.
  • Reference boxes determine the coordinate system used for shape calculations.
  • The default reference box for a basic shape is the margin box.
  • The wrapping shape is constrained by the floated element's margin box.
  • Use shape-margin to add spacing around the calculated shape.
  • Use shape-image-threshold to control image alpha thresholds.
  • Use clip-path when the visible element should match the wrapping shape.
  • Image-based shapes may be subject to cross-origin security restrictions.
  • Some newer shape functions have limited browser support.
  • Large shapes can reduce the space available for text.
  • Responsive layouts may require simpler wrapping on narrow screens.
  • Test text zoom, readability, and different viewport sizes.
  • CSS Shapes should enhance presentation without disrupting the document's logical structure.

Browser Support

The CSS shape-outside property is widely available in modern browsers, including current versions of Chrome, Edge, Firefox, and Safari.

Common basic shapes such as circle(), ellipse(), inset(), and polygon() have broad support. Newer shape functions may have more limited availability.

For current compatibility information, visit Can I Use? and search for shape-outside.

Feature Detection

@supports (shape-outside: circle(50%)) {
  .shape {
    shape-outside: circle(50%);
  }
}

Feature queries allow custom wrapping rules to be applied when the browser recognizes the specified shape syntax.

Fallback Behavior

When unsupported, the browser ignores the declaration and uses normal rectangular float wrapping.

Testing Recommendations

Test the intended shape functions, image sources, responsive layouts, and text zoom levels in the browsers you support.

Specifications

The shape-outside property is defined in the CSS Shapes Module Level 1 specification, with additional shape syntax defined in related specifications.

CSS Shapes Module Level 1

The specification defines how shapes and reference boxes affect text wrapping around floated elements.

For additional documentation and examples, consult MDN Web Docs.

MDN Web Docs: shape-outside