CSS border-image Property

Beginner
6 min read
Updated: Oct 2026
3 examples
Live preview

Definition and Usage

The border-image property is a shorthand that paints an image or gradient around an element. It replaces the usual solid border look with sliced regions from a source.

It sets border-image-source, border-image-slice, border-image-width, border-image-outset, and border-image-repeat. Keep a normal border-style and width as a fallback — some browsers skip the image when style is none or width is 0. It is not inherited.

Standard-track.

Not deprecated and not experimental. The shorthand is Baseline and widely available. Always set a fallback border style in case the image fails to load.

CSS Syntax

syntax.css
border-image: <source> <slice> [ / <width> ]? [ / <outset> ]? <repeat>? | initial | inherit;

A minimal useful form is source + slice, for example linear-gradient(...) 1. Width and outset use / separators.

Property Values

PartDescriptionTry it
sourceImage URL or gradient. Default is noneTry it
sliceHow far into the source to cut corners and edgesTry it
/ widthOptional width of the painted border image areaTry it
repeatstretch (default), repeat, round, or spaceTry it
initialResets all longhands to their defaultsTry it
inheritTakes the parent’s border-imageTry it

How to Use border-image

Give the box a border area, then replace the paint with an image or gradient.

  1. Set a visible border first, for example border: 20px solid.
  2. Choose a source (URL or gradient).
  3. Add a slice so the browser knows how to cut the source.
  4. Optionally add / width, a second / outset, and a repeat keyword such as round.
PieceRequired?Role
Border width + styleYes (in practice)Creates the border area; fallback if the image fails
SourceYesWhat to paint: image or gradient
SliceYesCuts the source into corners and edges
Repeat / width / outsetOptionalFit the slices and size the painted frame

Live Preview

The box already has a solid border width. Switch shorthand presets to see gradient and stripe frames.

Border width stays 20px. Only the image shorthand changes.

Frame

border-image: linear-gradient(...) 1

CSS Examples

Each snippet keeps CSS lean: a border area, then border-image. Use Try It Yourself for a live editor.

Example 1 — Gradient Border

Use a gradient as the source with a simple slice of 1.

CSS
<style>
  p {
    border: 20px solid;
    border-image: linear-gradient(135deg, #2563eb, #dc2626) 1;
  }
</style>

<p>Gradient border</p>
Try It Yourself

How It Works

  1. Create a border area. border: 20px solid sets width and style so the frame has space to paint.
  2. Choose a source. linear-gradient(...) is the image to slice.
  3. Slice once. 1 cuts a thin region from the gradient — enough for a simple colored frame.
  4. Fallback stays ready. If the gradient somehow fails, the solid border style remains.

Example 2 — Width and Round

Add an explicit image width and round so edge tiles fit evenly.

CSS
<style>
  p {
    border: 20px solid;
    border-image: linear-gradient(135deg, #2563eb, #0f766e) 1 / 20px round;
  }
</style>

<p>Rounded fit</p>
Try It Yourself

How It Works

  1. Keep source + slice. The gradient and 1 still define what to paint.
  2. Add width after a slash. / 20px sets the border-image width to match the border area.
  3. Use round. round scales edge pieces so they fit without clipping or awkward gaps.
  4. Compare with stretch. The default stretch pulls one piece to fill each edge instead.

Example 3 — Image File

Slice a bitmap and map the pieces around the box.

CSS
<style>
  p {
    border: 30px solid;
    border-image: url("/images/apple.png") 30 / 30px round;
  }
</style>

<p>Image border</p>
Try It Yourself

How It Works

  1. Point to a file. url("/images/apple.png") is the source bitmap.
  2. Pick a slice. 30 means cut 30 CSS pixels inward from each edge of the image.
  3. Size the paint. / 30px makes the painted border 30px thick.
  4. Fit the edges. round adjusts how many edge tiles fit along each side.

Edge Cases & Pitfalls

If the image border is missing or looks wrong, check these first.

fallback

Need width and style

Some browsers will not paint border-image when border-style is none or width is 0. Set a solid border first.

reset

border resets the shorthand

A later border declaration resets all border-image-* longhands. Put border-image after border.

radius

border-radius does not clip it

border-radius has no effect on border images. Round the artwork itself, or use layered backgrounds for curved gradient frames.

a11y

Not read by assistive tech

Screen readers cannot parse border images. If the image carries meaning, put that meaning in real text in the document.

table

Collapsed table cells skip it

Internal table elements with border-collapse: collapse do not use border-image.

Browser Support

border-image is a browser CSS property for element borders. Node.js, Deno, and Bun do not apply it.

✓ Baseline · Widely available

border-image

Chrome 56+, Firefox 50+, Safari 9.1+, Edge 12+, Internet Explorer 11. Gradients as sources are widely supported in modern browsers.

97% Global support
Google Chrome 56+
Full support
Mozilla Firefox 50+
Full support
Apple Safari 9.1+
Full support
Microsoft Edge 12+
Full support
Opera 43+
Full support
Samsung Internet 7.2+
Full support
Internet Explorer 11
Full support
border-image Widely supported

Bottom line: Safe for modern browsers. Always keep a normal border style as fallback, and remember that Internet Explorer before 11 has no support.

Key Takeaways

  • Role: shorthand that paints a sliced image or gradient as the border.
  • Needs a border area: set width and style first, then border-image.
  • Parts: source, slice, optional / width, optional / outset, optional repeat.
  • Limits: border-radius does not round it, and border can reset it.

One line: border-image replaces the border paint with a sliced source — after you give the box a real border area to paint into.

Frequently Asked Questions

It is a shorthand that draws an image or gradient around an element instead of a plain border line. It sets source, slice, width, outset, and repeat together.
Many browsers need a visible border width and a non-none border-style. A common pattern is border: 20px solid; then set border-image. If the source is none or fails to load, the normal border style shows instead.
Yes. A linear-gradient or repeating-linear-gradient can be the source. Pair it with a slice value such as 1 for a simple gradient frame.
No. border-radius does not round a border image. Bake the curve into the image, or use a dual-background trick if you need rounded gradient frames.
Yes. Setting border resets the border-image longhands to their initial values. Apply border-image after border, or avoid resetting it.
It is Baseline and widely available: Chrome 56+, Firefox 50+, Safari 9.1+, Edge 12+, and Internet Explorer 11. It is a browser style property, not a Node.js feature.

Next: border-image-outset

Learn how far the border image can extend outside the box.

border-image-outset tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful