CSS: Float Layout. (text flow around image)

By Xah Lee. Date: . Last updated: .

The float property can make text flow around an element such as an image.

Example. Text Flow Around Image

xah java logo
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversation?”.

Code

<div class="div-6a">

<img class="float-24c6" src="../java-a-day/java_logo/xah_java_logo.svg" alt="xah java logo" style="width:80px" />

<div class="xc4f0a">
Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, “and what is the use of a book,” thought Alice “without pictures or conversation?”.
</div>

</div>

<hr style="visibility: hidden; clear: both">
.div-6a {
 max-width: 300px;
}

.float-24c6 {
 float: left;
 margin: 0.5rem;
}

Float property values

The float can have a value of left or right. When it's left, it aligns to the left.

When a element is floating, other elements goes around it to avoid collision or overlap.

Multiple consecutive HTML elements with float: left behave as sequence of inline-block elements such as sequence of Image Tags flowing from left to right.

Stop Flowing

If you have many floating elements, the position of the last item will be the position the next non-floating item begin. For example, you might have:

floatElement floatElement floatElement … <h2></h2>

The <h2> will be shown at the position right after the last flow, as if it is part of the flow.

If you don't want that, you need to stop the flow with clear:left in the element that comes after the float. Like this:

<h2 style="clear: both">A New Beginning</h2>

The clear can have values of left, right, both.

Usually, it is best to use this element to clear the floats:

<hr style="visibility: hidden; clear: both">
xtodo

shape-outside is a CSS property that lets you define a custom (often non-rectangular) shape around which text (inline content) will wrap.

It works only on floated elements (usually images or other floated boxes). Without a float: left or float: right, shape-outside has no effect.

What It Solves

By default, text wraps around the rectangular margin box of a floated element.
With shape-outside, you can make the text follow curves, circles, polygons, or even the transparent parts of an image.

Basic Syntax

.floated-element {
  float: left;                    /* required */
  shape-outside: circle(50%);     /* text wraps in a circle */
  shape-margin: 20px;             /* optional space between text and shape */
}

Supported Shape Values

Value Example Description
circle() circle(50% at 50% 50%) Perfect circle or ellipse
ellipse() ellipse(40% 60%) Elliptical shape
inset() inset(10% 20% 10% 20% round 20px) Rectangular with rounded corners
polygon() polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%) Any polygon (great for triangles, stars, etc.)
url() url(image.png) Uses the alpha channel of an image to define the shape
linear-gradient() (advanced) Can create gradient-based shapes

You can also combine with shape-image-threshold to control how transparent pixels are considered part of the shape (0.0 to 1.0).

Complete Example: Circular Text Wrap

<img src="portrait.jpg" alt="portrait" class="circle-image">

<p>Lorem ipsum dolor sit amet... (long text)</p>
.circle-image {
  float: left;
  width: 300px;
  height: 300px;
  border-radius: 50%;           /* visual circle */
  shape-outside: circle(50%);   /* text wrap circle */
  shape-margin: 25px;
  margin: 0 30px 20px 0;
}

Example: Polygon Shape

.shape {
  float: left;
  shape-outside: polygon(30% 0%, 70% 0%, 100% 50%, 70% 100%, 30% 100%, 0% 50%);
  shape-margin: 15px;
}

Is shape-outside New?

No — it's not new, but it took a long time to become widely supported:

As of 2026:

Some advanced features (like path() or the newer shape() function) are still rolling out or partial.

Limitations & Tips

Quick Tip: Use your browser’s DevTools — most support a Shapes Editor (especially Firefox and Chrome) that lets you visually drag points of a polygon.

Would you like a full interactive demo with multiple shapes or examples using images with alpha channels?

CSS, Layout