liveBook · Manning

Shape-outside

As explained in Tiny CSS Projects

The CSS shape-outside property defines the geometric shape around which inline content may flow beside a floated element.

A floated image normally makes nearby text wrap around its rectangular box. Add `shape-outside` when the text should follow a contour instead. For a square compass image floated right, `circle(50%)` makes the text follow a circular outline. The optional center position defaults to the image’s center; without a radius, `circle()` uses `closest-side`. section 7.3.1

Listing 7.6 shape-outside
img.compass {
  aspect-ratio: 1;                #1
  float: right;                   #2
  shape-outside: circle(50%);     #3
}

The compass CSS keeps the image square, floats it right, and gives adjacent text a circular shape to follow. section 7.3.1

The wrapping shape does not have to be specified with `circle()`. If `border-radius: 50%` already makes the image circular, use `shape-outside: margin-box` to follow that contour while accounting for its margin. Other box choices are `border-box`, `padding-box`, and `content-box`. Unlike this rounded-image approach, `circle()` alone does not crop the image; `clip-path` can handle that visual step. section 7.3.3

Listing 7.9 Adding border-radius and shape-outside
img.compass {
  aspect-ratio: 1;
  float: right;
  margin-left: 1rem;
  border-radius: 50%;
  shape-outside: margin-box;
}

This alternative combines a right float, spacing, a circular image, and a margin-aware wrapping shape. section 7.3.3

Wrap text around a transparent illustration

Float the SVG illustration left and set `shape-outside: url("img/dog.svg")`. The browser uses the image’s transparency to establish the outline. Serve the file through a server rather than opening the page directly from the file system so the browser can fetch it. For partly transparent edges, `shape-image-threshold` adjusts the cutoff. Although `path()` could describe an outline, it was not fully implemented in browsers at the time described; an image URL or an approximate polygon was the practical alternative. section 7.4.2 section 7.4.1

How Tiny CSS Projects covers it

How deep it goes
Works through circle(), rounded box contours, and image transparency, including defaults and a file-serving pitfall; defers path() because of browser support.
Examples
Uses a right-floated circular compass and a left-floated transparent SVG illustration to demonstrate different wrapping contours.
What it assumes
Builds on floated images and CSS declarations while explaining circle() defaults and the available box-model shape choices.
What you can do after
Build it from scratch: wrap text around circular and transparent floated images using circle(), margin-box, or url().
How it connects
Connects CSS floats to circle(), border-radius, box-model boxes, image transparency, clip-path, and shape-image-threshold.

Also explained in

Compare how 2 books explain shape-outside →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.