Web design and digital-business ideas grounded in real tasks.

CSS border-image divides one image into edges and corners

A decorative webpage frame beside a designer's sketches
AI-generated photographic illustration; not documentary photography.

A decorative frame does not have to stretch as one giant background image. CSS border-image can divide a source image into regions and use them around an element. The corners keep their role while the edges adapt to the space between them.

The MDN explanation of border-image-slice describes nine regions: four corners, four edges and a centre. The centre is not painted by default; the optional fill behaviour changes that.

Imagine a square source image with a decorative corner in each corner and a narrow pattern along each side. Four slice lines separate those areas. If a line cuts through the decorative corner, the browser cannot know that you intended to keep the motif intact.

Open the source image and mark where the corner ends and the edge pattern begins. Use those positions to choose slice values. This is more reliable than repeatedly changing numbers until one element size happens to look acceptable.

Source slicing and the displayed border width answer different questions. One chooses which image regions to use; the other affects how the border is drawn around the element.

Watch the edges change length

The border-image reference explains the related properties, including repeat behaviour. Stretching can distort a repeated motif, while repetition can produce partial patterns at an edge. Test the choice with the actual artwork.

Try a short text block, a longer one and a narrow mobile width. Check all four corners and the final segment of each edge. A frame that works around one fixed screenshot may behave quite differently when the text wraps.

Keep meaningful content in the document itself. A decorative border image should not carry an essential label or instruction that disappears when the image fails to load.

For a practical fallback, give the element a sensible ordinary border and enough spacing for its text. Then treat the image border as an enhancement. The result is easier to maintain because the content remains readable while the decorative frame is free to adapt to different sizes.