Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

border-image — an image-based border

border-image is a CSS shorthand that builds a border from an image or gradient. It controls the source, slicing, width, outset, and repetition without reserving additional layout space.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

border-image: <'border-image-source'> || <'border-image-slice'> [ / <'border-image-width'> | / <'border-image-width'>? / <'border-image-outset'> ]? || <'border-image-repeat'>;

border-image sets five properties: border-image-source, border-image-slice, border-image-width, border-image-outset, and border-image-repeat. Omitted components reset to none, 100%, 1, 0, and stretch, respectively. The property is not inherited.

The image is divided into nine parts: corners, edges, and a center. border-image-slice defines cuts using unitless numbers or percentages; the center is discarded unless you specify fill. Do not confuse image slicing with the painted border width: a number in border-image-width multiplies the corresponding border-width.

Slashes separate width and outset from slicing: 1 / 1 / 0. The notation 1 / / 4px omits the width. Edge modes are stretch, repeat, round, and space; two values apply to the horizontal and vertical axes, respectively.

The image does not change layout: space still depends on border-width and border-style. Set an ordinary border as a fallback when the image cannot be displayed. Place border before border-image, because a later border resets this shorthand. The example uses a gradient without external files.

Examples

<!doctype html>
<meta charset="utf-8">
<title>border-image</title>
<style>
  .frame {
    width: 160px;
    height: 80px;
    border: 12px solid gray;
    border-image: linear-gradient(to right, #0066cc, #cc3300) 1 / 1 / 0 stretch;
    background: white;
  }
</style>
<div class="frame"></div>

Result

A 184px × 104px rectangular box with a white 160px × 80px interior and a 12px gradient border, blue at the left and red-orange at the right.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources