Image outlines
A faint line just inside the edge of an image, so it doesn't blend into a page of the same color. Add layerStyle="imageOutline" to any image or avatar.
When the edges of an image are close in color to the page, the image blends into it. A white product shot on a white page, or a night sky on a dark one, loses its edge, and the eye can't tell where the image stops.
The imageOutline layer style draws a 1px line just inside the image: black at 10% in light mode, white at 10% in dark
mode. It's too faint to read as a border, but it gives every image the same defined edge.


Ivan Aivazovsky, Storm at Sea on a Moonlit Night
import { styled } from "styled-system/jsx"
export function ImageOutlineCompareDemo() {
return (
<styled.div
display="grid"
gridTemplateColumns={{ base: "1fr", sm: "repeat(2, minmax(0, 1fr))" }}
gap="8"
w="full"
maxW="xl"
>
<styled.figure display="flex" flexDirection="column" alignItems="center" gap="3">
<styled.img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Storm_at_Sea_on_a_Moonlit_Night_%28Aivazovsky%29.jpg/960px-Storm_at_Sea_on_a_Moonlit_Night_%28Aivazovsky%29.jpg"
alt="Storm at Sea on a Moonlit Night by Ivan Aivazovsky"
w="full"
rounded="l3"
/>
<styled.figcaption textStyle="xs" fontFamily="mono" color="fg.muted">
No outline
</styled.figcaption>
</styled.figure>
<styled.figure display="flex" flexDirection="column" alignItems="center" gap="3">
<styled.img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Storm_at_Sea_on_a_Moonlit_Night_%28Aivazovsky%29.jpg/960px-Storm_at_Sea_on_a_Moonlit_Night_%28Aivazovsky%29.jpg"
alt="Storm at Sea on a Moonlit Night by Ivan Aivazovsky"
w="full"
rounded="l3"
layerStyle="imageOutline"
/>
<styled.figcaption textStyle="xs" fontFamily="mono" color="fg.muted">
layerStyle="imageOutline"
</styled.figcaption>
</styled.figure>
<styled.p gridColumn="1 / -1" textAlign="center" textStyle="xs" color="fg.subtle">
Ivan Aivazovsky, <em>Storm at Sea on a Moonlit Night</em>
</styled.p>
</styled.div>
)
}Usage
The Image component and Avatar.Image already have it: the image and avatar recipes apply the layer style by
default. Turn it off on one element with outlineStyle="none".
<Image src="/sunflowers.jpg" alt="Sunflowers by Vincent van Gogh" rounded="l3" />
<Image src="/van-gogh-signature.png" alt="Vincent van Gogh's signature" outlineStyle="none" />The layer style ships with @isbatak/panda-ds, so there is nothing to install. Add it to any other image.
<styled.img src="/water-lilies.jpg" alt="Water Lilies by Claude Monet" rounded="l3" layerStyle="imageOutline" />Or from css(), next to your other styles.
import { css } from "styled-system/css"
export function Painting() {
return (
<img
src="/the-magpie.jpg"
alt="The Magpie by Claude Monet"
className={css({ layerStyle: "imageOutline", rounded: "l3" })}
/>
)
}The outline follows the element's border-radius, so it works on rounded images and circles without extra styles.
How it works
The layer style sets four properties.
imageOutline: {
value: {
outlineWidth: "1px",
outlineStyle: "solid",
outlineOffset: "-1px",
outlineColor: "color-mix(in srgb, {colors.black} calc(var(--image-outline-opacity, 0.1) * 100%), transparent)",
_dark: {
outlineColor: "color-mix(in srgb, {colors.white} calc(var(--image-outline-opacity, 0.1) * 100%), transparent)",
},
},
}outline-offset: -1pxpulls the outline inside the image, so it paints over the edge pixels instead of around them.color-mix()mixes theblackorwhitetoken withtransparent, so the opacity can come from a CSS variable._darkswaps black for white. A dark line disappears on a dark page, and a light one would glow on a light page.
Why not a border
A border takes up space. On a sized image it either grows the box by 2px or shrinks the picture inside it, and toggling
it shifts the layout around it. An outline is painted on top and takes up no space. An inset box-shadow does the same,
but it's drawn under an <img>'s content, so the image covers it.
<styled.img src="/the-night-cafe.jpg" borderWidth="1px" /> {/* adds 2px to the box */}
<styled.img src="/the-night-cafe.jpg" layerStyle="imageOutline" /> {/* takes up no space */}Strength
About 10% is a good default. Below 5%, the line disappears against pale backgrounds. Above 20%, it stops reading as an edge and starts to look like a frame. Drag the slider to compare.

A defined edge that doesn't read as a border.
import { Slider } from "@isbatak/react-ui/slider"
import { type CSSProperties, useState } from "react"
import { styled } from "styled-system/jsx"
function describe(percent: number) {
if (percent < 5) return "Too faint: the edge disappears against pale backgrounds."
if (percent > 20) return "Too strong: it reads as a frame instead of an edge."
return "A defined edge that doesn't read as a border."
}
export function ImageOutlineStrengthDemo() {
const [percent, setPercent] = useState(10)
const style = { "--image-outline-opacity": percent / 100 } as CSSProperties
return (
<styled.div display="flex" flexDirection="column" gap="6" w="full" maxW="sm">
<styled.figure display="flex" flexDirection="column" alignItems="center" gap="3">
<styled.img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Claude_Monet_-_Water_Lilies_-_1906%2C_Ryerson.jpg/960px-Claude_Monet_-_Water_Lilies_-_1906%2C_Ryerson.jpg"
alt="Water Lilies by Claude Monet"
w="full"
rounded="l3"
layerStyle="imageOutline"
style={style}
/>
<styled.figcaption textStyle="xs" color="fg.subtle">
Claude Monet, <em>Water Lilies</em>
</styled.figcaption>
</styled.figure>
<Slider.Root value={[percent]} min={0} max={30} onValueChange={(details) => setPercent(details.value[0] ?? 0)}>
<styled.div display="flex" justifyContent="space-between" textStyle="sm">
<Slider.Label>--image-outline-opacity</Slider.Label>
<styled.span fontFamily="mono" color="fg.muted">
{(percent / 100).toFixed(2)}
</styled.span>
</styled.div>
<Slider.Control>
<Slider.Track>
<Slider.Range />
</Slider.Track>
<Slider.Thumb index={0}>
<Slider.HiddenInput />
</Slider.Thumb>
</Slider.Control>
</Slider.Root>
<styled.p textStyle="sm" color="fg.muted">
{describe(percent)}
</styled.p>
</styled.div>
)
}Set --image-outline-opacity to change it. It takes a number from 0 to 1 and inherits like any custom property, so you
can set it on one image or on a whole gallery.
<styled.div css={{ "--image-outline-opacity": "0.15" }}>
<styled.img src="/the-starry-night.jpg" alt="The Starry Night by Vincent van Gogh" layerStyle="imageOutline" />
<styled.img src="/impression-sunrise.jpg" alt="Impression, Sunrise by Claude Monet" layerStyle="imageOutline" />
</styled.div>Light and dark modes can need different values. A dark page often needs a little more contrast. Set the variable per condition.
<styled.img
src="/the-ninth-wave.jpg"
alt="The Ninth Wave by Ivan Aivazovsky"
layerStyle="imageOutline"
css={{ "--image-outline-opacity": { base: "0.1", _dark: "0.14" } }}
/>Avatars
Avatars benefit most. They're small and round, and they often have a white or pale background, so without an outline
they look like a gap in the page. The avatar recipe applies the layer style to Avatar.Image by default, and the
image already takes the avatar's radius, so the outline stays round. Switch between the two and watch the edges of the
bright and dark photos.
import { Avatar } from "@isbatak/react-ui/avatar"
import { Icon } from "@isbatak/react-ui/icon"
import { SegmentGroup } from "@isbatak/react-ui/segment-group"
import { useState } from "react"
import { styled } from "styled-system/jsx"
export function ImageOutlineAvatarDemo() {
const [value, setValue] = useState("outline")
const outlineStyle = value === "outline" ? undefined : "none"
return (
<styled.div display="flex" flexDirection="column" alignItems="center" gap="8">
<styled.div
display="flex"
flexWrap="wrap"
justifyContent="center"
gap="4"
p="5"
rounded="l3"
borderWidth="1px"
bg="bg.panel"
>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Vincent van Gogh" />
<Avatar.Image
src="https://upload.wikimedia.org/wikipedia/commons/thumb/4/4c/Vincent_van_Gogh_-_Self-Portrait_-_Google_Art_Project_%28454045%29.jpg/330px-Vincent_van_Gogh_-_Self-Portrait_-_Google_Art_Project_%28454045%29.jpg"
alt="Vincent van Gogh"
outlineStyle={outlineStyle}
/>
</Avatar.Root>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Claude Monet" />
<Avatar.Image
src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Claude_Monet_1899_Nadar_crop.jpg/330px-Claude_Monet_1899_Nadar_crop.jpg"
alt="Claude Monet"
outlineStyle={outlineStyle}
/>
</Avatar.Root>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Ivan Aivazovsky" />
<Avatar.Image
src="https://upload.wikimedia.org/wikipedia/commons/thumb/c/c6/Aivazovsky_-_Self-portrait_1874.jpg/330px-Aivazovsky_-_Self-portrait_1874.jpg"
alt="Ivan Aivazovsky"
outlineStyle={outlineStyle}
/>
</Avatar.Root>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Berthe Morisot" />
</Avatar.Root>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Rembrandt van Rijn" />
<Avatar.Image
src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bd/Rembrandt_van_Rijn_-_Self-Portrait_-_Google_Art_Project.jpg/330px-Rembrandt_van_Rijn_-_Self-Portrait_-_Google_Art_Project.jpg"
alt="Rembrandt van Rijn"
outlineStyle={outlineStyle}
/>
</Avatar.Root>
<Avatar.Root size="2xl">
<Avatar.Fallback name="Edgar Degas" />
<Avatar.Image
src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a1/Edgar_Degas_self_portrait_1855.jpeg/330px-Edgar_Degas_self_portrait_1855.jpeg"
alt="Edgar Degas"
outlineStyle={outlineStyle}
/>
</Avatar.Root>
</styled.div>
<SegmentGroup.Root
value={value}
onValueChange={(details) => setValue(details.value ?? "outline")}
orientation="horizontal"
aria-label="Image outline"
>
<SegmentGroup.Indicator />
<SegmentGroup.Item value="none">
<SegmentGroup.ItemText display="inline-flex" alignItems="center" gap="2">
<styled.span
display="inline-flex"
alignItems="center"
justifyContent="center"
boxSize="4"
rounded="full"
colorPalette="red"
bg="colorPalette.solid"
color="colorPalette.contrast"
>
<Icon name="close" boxSize="3" />
</styled.span>
No outline
</SegmentGroup.ItemText>
<SegmentGroup.ItemHiddenInput />
</SegmentGroup.Item>
<SegmentGroup.Item value="outline">
<SegmentGroup.ItemText display="inline-flex" alignItems="center" gap="2">
<styled.span
display="inline-flex"
alignItems="center"
justifyContent="center"
boxSize="4"
rounded="full"
colorPalette="green"
bg="colorPalette.solid"
color="colorPalette.contrast"
>
<Icon name="check" boxSize="3" />
</styled.span>
Outline
</SegmentGroup.ItemText>
<SegmentGroup.ItemHiddenInput />
</SegmentGroup.Item>
</SegmentGroup.Root>
</styled.div>
)
}To turn it off for one avatar, remove the outline or set its opacity to 0.
<Avatar.Root>
<Avatar.Fallback name="Rembrandt van Rijn" />
<Avatar.Image src="/rembrandt.jpg" alt="Rembrandt van Rijn" outlineStyle="none" />
</Avatar.Root>In plain CSS
The same technique outside Panda, for reference.
.image-outline {
outline: 1px solid rgb(0 0 0 / var(--image-outline-opacity, 0.1));
outline-offset: -1px;
}
.dark .image-outline {
outline-color: rgb(255 255 255 / var(--image-outline-opacity, 0.1));
}FAQ
Yes. It's a regular outline, so it works on <video>, <canvas>, <picture> and any box with a background image.
Pick it for media, though: cards and panels already have border.* tokens.
It sets outline, so a focus style that also sets outline replaces it while the element is focused. Images aren't
focusable, so this only matters when the image is itself a link or button. Put the layer style on the <img>
inside, not on the link.
An outline outside the image adds a visible ring with the page's background between it and the picture. Inside, it darkens or lightens the edge pixels, which reads as the image's own edge.
Chrome 111, Safari 16.2 and Firefox 113 or newer.
Credits
From Jakub Krehel's Details that make interfaces feel better and Gustavo Fior's Image outlines.
The paintings and portraits are in the public domain, from Wikimedia Commons:
- Ivan Aivazovsky, Storm at Sea on a Moonlit Night
- Claude Monet, Water Lilies (1906)
- Vincent van Gogh, Self-Portrait (1887)
- Nadar, Claude Monet (1899)
- Ivan Aivazovsky, Self-Portrait (1874)
- Rembrandt van Rijn, Self-Portrait
- Edgar Degas, Self-Portrait (1855)