How To Wrap Text Around An Image That Can Be Placed Left Or Right With Css

Master CSS text wrapping around images using float and shape-outside. Learn to create magazine-style layouts with left and right positioned images.

Understanding CSS Float for Image Text Wrapping

The float property remains one of the most straightforward methods for wrapping text around images in CSS. When you apply float: left or float: right to an image, adjacent inline content naturally flows around the image on the opposite side. This behavior mimics traditional print layout techniques where images interrupt the text flow while maintaining readability.

Our web development services often incorporate these CSS layout techniques to create professional, magazine-style designs that engage visitors and improve content readability. The float property has been a foundational CSS layout technique since the early days of web design and continues to be relevant for text wrapping scenarios.

Basic Float Implementation

.image {
 float: left;
 margin-right: 20px;
 max-width: 300px;
 height: auto;
}

The default behavior wraps text around the rectangular bounding box of the floated element. For simple use cases where images have square or rectangular dimensions, this produces perfectly acceptable results. However, when working with images that have irregular shapes, transparent PNGs, or when you want text to follow organic contours, the float property alone falls short.

Float Considerations and Clearfix Patterns

Floated elements are removed from the normal document flow, which can cause container elements to collapse. The classic clearfix pattern addresses this issue:

.container::after {
 content: "";
 display: table;
 clear: both;
}

This pattern forces the container to recognize its floated children, preventing layout breakage. Modern CSS offers additional solutions including overflow: auto and the dedicated display: flow-root value, which provides a cleaner approach to containing floats without modifying pseudo-elements.

For advanced layout techniques that combine float with other CSS properties, explore our guide on CSS Grid and Flexbox to understand how these modern layout systems complement traditional float-based approaches.

CSS shape-outside: The Advanced Solution

The shape-outside CSS property defines a shape around which adjacent inline content should wrap, replacing the default rectangular bounding box with custom-defined contours. This property works in conjunction with floated elements to create magazine-style layouts where text follows the actual shape of images rather than their rectangular boundaries.

Implementing proper text wrapping layouts contributes to better SEO performance, as visually engaging content keeps users on the page longer and reduces bounce rates. The shape-outside property enables designers to create unique, attention-grabbing layouts that stand out from standard grid-based designs.

Browser Support and Compatibility

The shape-outside property has achieved broad browser support and is classified as a Baseline feature, working reliably across Chrome, Firefox, Safari, and Edge since January 2020. According to MDN Web Docs, this feature is well established and works across many devices and browser versions.

For projects requiring support for older browsers, graceful degradation strategies can be implemented. The shape-outside property falls back to the default rectangular float behavior in unsupported browsers, ensuring content remains accessible even if the visual effect is simplified.

Basic Syntax and Values

/* Keyword values */
shape-outside: none;
shape-outside: margin-box;
shape-outside: content-box;
shape-outside: border-box;
shape-outside: padding-box;

/* Function values */
shape-outside: circle(50%);
shape-outside: ellipse(130px 140px at 20% 20%);
shape-outside: inset(10px 10px 10px 10px);
shape-outside: polygon(10px 10px, 20px 20px, 30px 30px);

/* Image-based shape */
shape-outside: url("image.png");

The none value disables shape-based wrapping, reverting to standard rectangular wrapping. The box-based values use the standard CSS box model edges as the wrapping boundary, useful when combined with border-radius to create rounded wrapping areas.

Geometric Shape Functions

Choose the right shape function for your layout needs

circle()

Creates circular wrapping shapes with configurable radius and position. Ideal for profile images, avatars, and circular decorative elements.

ellipse()

Creates elliptical shapes with separate horizontal and vertical radii. Perfect for banner images and oval graphics.

inset()

Defines rectangular areas offset from box edges. Useful for creating text-free zones within images.

polygon()

Creates complex multi-point shapes with full control. Best for custom logos and irregular product images.

Image-Based Shapes

One of the most powerful features of shape-outside is the ability to extract the wrapping boundary directly from an image's alpha channel. When you specify a URL value, the browser reads the transparent areas and uses opaque areas to define the wrapping shape. This approach enables text to wrap around complex shapes like people, products, or irregular objects without manually defining polygon coordinates.

.image {
 float: left;
 max-width: 300px;
 shape-outside: url("transparent-image.png");
 shape-margin: 15px;
}

The shape-margin property adds spacing between the shape boundary and the wrapping text, providing visual separation without affecting the shape itself. This property accepts any valid length or percentage value.

For professional web design services that incorporate advanced CSS techniques like these, consider working with a web development agency that specializes in modern CSS layouts and responsive design. These advanced text wrapping techniques are commonly used in e-commerce product pages and editorial content to create visually engaging layouts.

Creating Left and Right Positioned Images

Left-Positioned Image Example

.image-left {
 float: left;
 max-width: 250px;
 margin-right: 25px;
 margin-bottom: 15px;
 shape-outside: url("left-shape.png");
 shape-margin: 12px;
}

Right-Positioned Image Example

.image-right {
 float: right;
 max-width: 250px;
 margin-left: 25px;
 margin-bottom: 15px;
 shape-outside: url("right-shape.png");
 shape-margin: 12px;
}

Text automatically wraps on the opposite side of the float direction, creating natural reading layouts. The float: left property positions the image on the left with text flowing on the right, while float: right positions the image on the right with text flowing on the left.

For websites looking to implement advanced CSS techniques like text wrapping around images, our AI automation services can help streamline development workflows and ensure consistent implementation across your digital presence.

Complete Responsive Example
1/* Complete example with responsive design */2.image {3 float: left;4 max-width: 300px;5 margin-right: 25px;6 margin-bottom: 15px;7 shape-outside: url("image.png");8 shape-margin: 15px;9}10 11.container {12 overflow: auto;13}14 15@media (max-width: 768px) {16 .image {17 float: none;18 display: block;19 max-width: 100%;20 margin: 0 auto 20px;21 shape-outside: none;22 }23}

Common Questions

Does shape-outside work with background images?

No, shape-outside only works with floated elements. For background image text wrapping, use an actual img element or consider CSS masking techniques.

What image formats work best for shape-outside?

PNG and WebP images with transparency work best. The shape is extracted from the alpha channel, so fully opaque images produce rectangular shapes.

How do I handle browsers that don't support shape-outside?

Provide basic float styling as a fallback. Unsupported browsers will use the default rectangular wrapping behavior, which remains functional.

Can I animate shape-outside?

Basic shape values can be animated, but image-based shapes cannot. Consider transitioning between basic shapes for animated effects.

How does shape-outside affect accessibility?

Screen readers ignore shape-outside and read content in source order. Ensure your HTML maintains logical structure for assistive technologies.

Ready to Build Modern Websites?

Our web development team creates custom sites with advanced CSS layouts and responsive design. From magazine-style layouts to complex responsive interfaces, we bring your vision to life with cutting-edge web development services.

Sources

  1. MDN Web Docs - CSS shape-outside - Official CSS property reference with syntax, values, and browser support information
  2. TheoSoti.com - CSS shape-outside tutorial - Practical implementation guide with code examples
  3. Stack Overflow - CSS shape-outside discussion - Real-world implementation solutions