Emoji as image sources for shape-outside
CSS Shapes lets inline content wrap along a geometric shape defined on a floated element instead of the element's rectangular box. The shape-outside property accepts either a basic shape function — circle(), ellipse(), polygon(), inset() — or an image. Text wraps along the right edge of a left float and the left edge of a right float.
Images are rectangles, and most CSS-drawn shapes are boxy or limited to standard forms. Emoji characters break out of that constraint. The approach: convert an emoji into an image, float it, then apply the shape to it.
Building an emoji image in SVG
The conversion takes three steps: cut the emoji shape out of SVG, URL-encode the SVG and prefix it with data:image/svg+xml to get a DataURL, then use that DataURL as the url() value of background-image.
<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'>
<clipPath id='emojiClipPath'>
<text x='0' y='130px' font-size='130px'>🦕</text>
</clipPath>
<text x='0' y='130px' font-size='130px' clip-path='url(#emojiClipPath)'>🦕</text>
</svg>
A <text> element is given an emoji character to serve as a <clipPath> — the outline of the region kept visible when the clip is applied. A second <text> element carrying the same character references that clip path via its clip-path property, producing a cutout shaped like the emoji. The SVG can be URL-encoded by hand or with an online encoder.
.emoji {
background: url("data:image/svg+xml,<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'> <clipPath id='emojiClipPath'> <text x='0' y='130px' font-size='130px'>🦕</text> </clipPath> <text x='0' y='130px' font-size='130px' clip-path='url(%23emojiClipPath)'>🦕</text></svg>");
}
Given dimensions on the .emoji element, the character now renders as a background image.
Applying the shape
Float the element carrying the emoji background, then point shape-outside at the same DataURL:
.emoji {
--image-url: url("data:image/svg+xml,<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'> <clipPath id='emojiClipPath'> <text x='0' y='130px' font-size='130px'>🦕</text> </clipPath> <text x='0' y='130px' font-size='130px' clip-path='url(#emojiClipPath)'>🦕</text></svg>");
background: var(--image-url);
float: left;
height: 150px;
shape-outside: var(--image-url);
width: 150px;
margin-left: -6px;
}
The DataURL sits in a custom property, --image-url, so the long encoded string is written once and referenced from both background and shape-outside. Nearby inline content then flows in the emoji's outline. margin and shape-margin adjust the space around the shape.
Solid-color variants
For a color-blocked shape, apply the clip path to a <rect> element instead of text:
<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'>
<clipPath id='emojiClipPath'>
<text x='0' y='130px' font-size='130px'>🦕</text>
</clipPath>
<rect x='0' y='0' fill='green' width='150px' height='150px' clip-path='url(#emojiClipPath)'/>
</svg>
The same technique works with letters as well as emoji.
Firefox fallback
Firefox does not always render the emoji shape, but updating the SVG code works around it:
<svg xmlns='http://www.w3.org/2000/svg' width='150px' height='150px'>
<foreignObject width='150px' height='150px'>
<div xmlns='http://www.w3.org/1999/xhtml' style='width:150px;height:150px;line-height:150px;text-align:center;color:transparent;text-shadow: 0 0 black;font-size:130px;'>🧗</div>
</foreignObject>
</svg>
This variant makes the emoji transparent and gives it a text-shadow through inline CSS, creating a block-colored shape. The <div> holding the emoji and the inline style is placed inside an SVG <foreignObject> so HTML markup can be used within the SVG namespace; the rest matches the previous technique.
Centering a shape by splitting it
Shapes apply only to floated elements, so text flows to one side or the other depending on the float direction. To center both the element and the shape:
- Split the emoji in half.
- Float the left half right and the right half left.
- Bring both halves back together.
One caveat: with running sentences, letters on the two sides must be aligned manually.
The markup for both sides is identical:
<div id="design">
<p id="leftSide">A C G T A <!-- more characters --> C G T A C G T A C G T <span class="emoji"></span>A C G <!-- more characters --> C G T </p>
<p id="rightSide">A C G T A <!-- more characters --> C G T A C G T A C G T <span class="emoji"></span>A C G <!-- more characters --> C G T </p>
</div>
Inside #design, p#leftSide and p#rightSide are arranged side by side in a grid.
#design {
border-radius: 50%; /* A circle */
box-shadow: 6px 6px 20px silver;
display: grid;
grid: "1fr 1fr"; /* A grid with two columns */
overflow: hidden;
width: 400px; height: 400px;
}
The CSS for the emoji:
span.emoji {
filter: drop-shadow(15px 15px 5px green);
shape-margin: 10px;
width: 75px;
height: 150px;
}
/* Left half of the emoji */
p#leftSide>span.emoji {
--image-url:url("data:image/svg+xml,<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'> <clipPath id='emojiClipPath'> <text x='0' y='130px' font-size='130px'>🦎</text> </clipPath> <rect x='0' y='0' width='150px' height='150px' clip-path='url(%23emojiClipPath)'/></svg>");
background-image: var(--image-url);
float: right;
shape-outside: var(--image-url);
}
/* Right half of the emoji */
p#rightSide>span.emoji {
--image-url:url("data:image/svg+xml,<svg width='150px' height='150px' xmlns='http://www.w3.org/2000/svg'> <clipPath id='emojiClipPath'> <text x='-75px' y='130px' font-size='130px'>🦎</text> </clipPath> <rect x='0' y='0' width='150px' height='150px' clip-path='url(%23emojiClipPath)'/></svg>");
background-image: var(--image-url);
float: left;
shape-outside: var(--image-url);
}
span.emoji is 75px wide while the SVG emoji image is 150px wide, so each span automatically crops the image to one half. On the right side, where the emoji is left-floated (p#rightSide>span.emoji), the emoji must shift half its width left to reveal the right half; that means changing the x value of the <text> in the DataURL to 75px. This is the only difference between the DataURLs used on the two sides.
The method generalizes: any CSS Shape can be centered this way as long as the element can be split in two and the halves reassembled with CSS.



