What is shape-outside?
The shape-outside CSS property defines a shape--which may be non-rectangular--around which adjacent inline content should wrap. This property works in conjunction with floated elements to create text that contours around custom shapes rather than following the standard rectangular bounding box.
Before shape-outside, developers had limited options for creating interesting text flows: either accept the rectangular boundary of floated elements or resort to complex workarounds involving negative margins and positioning hacks that often broke across different screen sizes.
Our web development services team regularly implements CSS shape techniques for clients who want standout visual designs that differentiate their brand from competitors.
Key requirements:
- The element must be floated (left or right)
- The element must have a defined width
- Shape-outside has no effect on non-floated elements
For projects that require both advanced CSS techniques and strong search performance, combining our SEO services with creative layouts ensures your visually stunning site also ranks well in search results.
Geometric Shapes
Use inset(), circle(), ellipse(), and polygon() to define custom shape boundaries for text wrapping.
Image Alpha Channels
Create shapes from transparent portions of PNG or WebP images for natural text flow around subjects.
Shape Margin Control
Add consistent spacing between shapes and surrounding content using the shape-margin property.
Reference Box System
Control shape coordinate systems using margin-box, border-box, padding-box, or content-box references.
Understanding Basic Shapes
CSS Shapes supports several fundamental shape types that can be combined with shape-outside to create different effects.
inset() for Rectangular Shapes
The inset() function defines a rectangle that can be inset from the reference box by specified distances. This becomes valuable when you want text to flow around a smaller rectangular area within a larger floated element.
/* inset(top right bottom left round border-radius) */
.shape {
float: left;
shape-outside: inset(20px 10px 20px 10px round 10px);
}
circle() for Circular Shapes
The circle() function creates circular shapes with optional positioning. The radius can be a length, percentage, or the closest-side/farthest-side keywords.
/* circle(radius at position) */
.shape {
float: left;
shape-outside: circle(50% at center);
}
ellipse() for Oval Shapes
Ellipses provide horizontal and vertical radius control for creating stretched or compressed circular shapes.
/* ellipse(rx ry at position) */
.shape {
float: left;
shape-outside: ellipse(30% 50% at center);
}
polygon() for Complex Shapes
Polygon() offers the most flexibility with arbitrary shapes using coordinate pairs. This approach is particularly useful for creating custom shapes that match specific design requirements, such as brand logos or unique visual elements.
/* polygon(x1 y1, x2 y2, ...) */
.shape {
float: left;
shape-outside: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
For teams working with modern CSS frameworks, these shape techniques complement our web design with HTML, CSS, and JavaScript approach to creating responsive, visually engaging websites.
The Reference Box System
Understanding the reference box is crucial for accurate shape positioning and sizing. The reference box defines the coordinate system and boundaries for shape calculations.
Available Reference Boxes
| Reference Box | Description |
|---|---|
| margin-box | Default. Includes content, padding, border, and margin |
| border-box | Includes content, padding, and border |
| padding-box | Includes content and padding |
| content-box | Includes only the content area |
/* Explicit reference box specification */
.shape {
shape-outside: circle(50%) margin-box; /* Default */
shape-outside: circle(50%) border-box; /* Use border as reference */
}
Choosing the right reference box affects how shapes interact with other layout properties and impacts the overall visual composition of your design.
Working with Images and Alpha Channels
One of shape-outside's most powerful capabilities is using images as shape definitions through their alpha channel.
Image-Based Shapes
img {
float: left;
width: 300px;
shape-outside: url('image-with-transparent-background.png');
shape-image-threshold: 0.5;
shape-margin: 1rem;
}
shape-image-threshold
The shape-image-threshold property controls which pixels contribute to the shape:
- 0.0: Includes all pixels with any transparency
- 0.5: Intermediate cutoff
- 1.0: Only fully opaque pixels
Image Preparation Tips
- Use PNG with transparent backgrounds or WebP with transparency
- Clean, precise edges create smooth shape boundaries
- Complex subjects may need threshold tuning
- Consider clip-path as a non-destructive alternative
For e-commerce clients, these techniques can create unique product layouts that improve user engagement and time-on-page metrics.
1/* Combined shape-outside properties */2.floating-image {3 float: left;4 width: 250px;5 height: auto;6 margin: 20px;7 8 /* Define the shape using image alpha channel */9 shape-outside: url('portrait.png');10 11 /* Control which pixels form the shape */12 shape-image-threshold: 0.2;13 14 /* Add spacing around the shape */15 shape-margin: 15px;16}17 18/* Responsive adjustment */19@media (max-width: 768px) {20 .floating-image {21 width: 100%;22 float: none;23 shape-outside: none;24 }25}Performance Considerations
Computational Overhead
Shape-outside introduces rendering calculations that can affect performance:
- Complex polygons require more computational effort than circles or ellipses
- Image-based shapes add decoding overhead
- Large content volumes multiplied by shape calculations impact scroll performance
Optimization Strategies
- Prefer simple shapes when possible--circles and ellipses are faster than polygons
- Reduce polygon points to minimum necessary for visual fidelity
- Use CSS transforms for rotations instead of recalculating polygon coordinates
- Implement lazy loading for images with alpha channel shapes
- Use content-visibility to skip off-screen shape calculations
Testing Recommendations
- Test on target devices, not just desktop browsers
- Measure time-to-interactive with shapes applied
- Compare performance with and without shape-outside
- Monitor scroll frame rates on mobile devices
Our development team follows performance best practices to ensure your visually rich designs also deliver fast load times and smooth interactions.
Best Practices and Common Patterns
Progressive Enhancement
Use shape-outside as a progressive enhancement that doesn't break layouts in unsupported browsers:
/* Fallback for browsers without shape-outside support */
.image-wrapper {
float: left;
margin: 20px;
}
/* Enhanced shapes for supporting browsers */
@supports (shape-outside: circle(50%)) {
.image-wrapper {
shape-outside: circle(50%);
shape-margin: 15px;
}
}
Non-Destructive Approaches
Combine clip-path and shape-outside with identical values for visual editing without image modification:
.image-with-shape {
clip-path: polygon(10% 0, 100% 0, 90% 100%, 0 100%);
shape-outside: polygon(10% 0, 100% 0, 90% 100%, 0 100%);
}
Responsive Shapes
Use percentage-based values for responsive behavior:
.responsive-shape {
shape-outside: circle(30% at 25%); /* Adapts to container width */
shape-margin: 5%; /* Scales with container */
}
These responsive techniques align with modern web development practices for building Bootstrap CSS compatible layouts that work across all devices.
Creative Applications
Shape-outside enables sophisticated design techniques that elevate web layouts beyond standard grid patterns.
Editorial Layouts
Magazine-style layouts use shape-outside to create:
- Text flowing around portrait photographs
- Organic layouts with asymmetric balance
- Visual hierarchy that guides reading direction
Product Showcases
E-commerce benefits from shape-outside for:
- L-shaped product descriptions wrapping around images
- Efficient use of screen real estate
- Visual interest on product detail pages
Brand Storytelling
Marketing pages leverage shape-outside for:
- Custom shapes aligned with brand graphics
- Memorable visual experiences
- Layouts that reinforce brand identity
Multi-Shape Layouts
Complex compositions coordinate multiple shapes:
- Grid items with individual text wrapping
- Vertical text flows between multiple floated elements
- Compositions that guide users through content deliberately
Looking to implement these creative layouts on your site? Our web development team has experience building custom designs that bring your brand vision to life.
Frequently Asked Questions
Does shape-outside work without float?
No. Shape-outside only affects floated elements. Non-floated elements will not have their surrounding text wrap around the defined shape.
Which browsers support shape-outside?
Modern browsers including Chrome, Firefox, Safari, and Edge all support shape-outside. The feature has been standardized since 2014.
Can I use shape-outside with CSS Grid?
Yes. Shape-outside works with Grid layout by applying the property to individual grid items. The shape affects text wrapping within that cell.
What's the difference between clip-path and shape-outside?
Clip-path controls which part of an element is visually displayed. Shape-outside controls how surrounding content flows around the element. They can be used together.
How do I create shapes from existing images?
Use shape-outside: url('image.png') and set shape-image-threshold to control which pixels form the shape boundary. PNG or WebP with transparency work best.