CSS border-image Property

Beginner
⏱️ 7 min read
📚 Updated: Jun 2026
🎯 4 Examples
Box Model & Layout

What You’ll Learn

The border-image property uses an image or gradient as a border. CSS slices the source into corners and edges, then stretches or repeats those pieces around your element.

01

Image Borders

Beyond solid lines.

02

Shorthand

Source, slice, repeat.

03

Slice Values

Divide the image.

04

Repeat Modes

stretch, round, space.

05

Gradients

No file required.

06

Longhands

Five sub-properties.

Definition and Usage

The border-image CSS property is a shorthand for drawing borders with an image or gradient instead of a basic line style. The browser slices the source image into nine regions — four corners, four edges, and a center — then places those regions around the element’s border box.

This property is useful for decorative frames, themed cards, buttons, and UI elements that need richer borders than solid, dashed, or dotted can provide.

💡
Beginner Tip

Start with a transparent border width, then add border-image. Example: border: 10px solid transparent; and border-image: linear-gradient(...) 1;.

📝 Syntax

border-image combines source, slice, width, outset, and repeat in one declaration:

syntax.css
selector {
  border-image: source slice / width / outset repeat;
}

Basic Example

border-image.css
.bordered {
  width: 300px;
  height: 200px;
  border: 10px solid transparent;
  border-image: url("border-image.png") 30 round;
}

Syntax Rules

  • You need a border width so the browser has space to paint the image border.
  • slice defines how far inward the image is cut from each edge.
  • Width and outset are optional and separated by / when used.
  • repeat controls whether edge pieces stretch, repeat, round, or space.
  • Gradients can replace url() as the image source in modern browsers.

⚡ Quick Reference

QuestionAnswer
Initial valuenone
Applies toBorder area of the element
InheritedNo
AnimatableNo
Common useDecorative frames, gradient borders, themed UI cards

Default Value

The default value of border-image is none. When set to none, no image border is used and the element relies on normal border properties instead.

💎 Property Values

The shorthand accepts these component values:

ComponentExampleMeaning
sourceurl("frame.png") or linear-gradient(...)The image or gradient used for the border
slice30 or 30 fillHow the source is divided into nine regions
width/ 20pxBorder image area width on each side
outset/ 5pxHow far the border image extends outside the border box
repeatstretch, repeat, round, spaceHow edge slices are tiled or scaled

Longhand Sub-Properties

border-image-source Sets the image or gradient URL.
border-image-slice Sets the slice distances from each edge.
border-image-width Sets the width of the border image area.
border-image-outset Sets how far the border image extends outward.
border-image-repeat Sets stretch, repeat, round, or space behavior.

Repeat Keywords

stretchStretches edge slices to fit
roundRepeats and scales to fit evenly
repeatRepeats edge slices as-is

border-image vs related properties

PropertyTargetsBest for
border-imageImage or gradient border paintingDecorative frames and rich border effects
borderWidth, style, and color togetherSimple everyday outlines
border-colorBorder line color onlySolid-color borders on each side
outlineLine outside the border boxFocus rings that do not affect layout

👀 Live Preview

A box with a gradient image border:

Uses border: 10px solid transparent; and border-image: linear-gradient(135deg, #2563eb, #dc2626, #059669) 1;.

Examples Gallery

Try border-image with image URLs, slice values, repeat modes, and gradient borders.

📚 Basic Image Borders

Start with a border width and an image source, then slice the image for the frame.

Example 1 — Image Border with Slice and Round

Apply an image as the border of a div, matching the reference tutorial pattern.

border-image-basic.html
<style>
  .bordered {
    width: 300px;
    height: 200px;
    border: 10px solid transparent;
    border-image: url("border-image.png") 30 round;
  }
</style>

<div class="bordered"></div>
Try It Yourself

How It Works

The transparent border creates space for the image. The slice value 30 cuts the image 30 pixels from each edge, and round scales edge tiles to fit cleanly.

Example 2 — Gradient Border Without an Image File

Use a CSS gradient as the border source — no external image required.

border-image-gradient.css
.gradient-border {
  padding: 1rem;
  border: 4px solid transparent;
  border-image: linear-gradient(135deg, #2563eb, #9333ea) 1;
  background: #fff;
}
Try It Yourself

How It Works

Gradients behave like an image source. A slice of 1 tells the browser to use the gradient across the border area.

🎨 Repeat and Layout

Control how edge slices stretch or tile around the element.

Example 3 — Repeating Pattern with Round

Use a repeating gradient and the round keyword for tiled border edges.

border-image-round.css
.pattern {
  width: 16rem;
  height: 6rem;
  border: 8px solid transparent;
  border-image: repeating-linear-gradient(45deg, #dc2626 0 10px, #fff 10px 20px) 8 round;
  background: #fff;
}
Try It Yourself

How It Works

The round keyword repeats edge tiles and adjusts them so they fit the side length without clipping awkwardly.

Example 4 — Decorative Card Frame

Combine border-image with padding and background for a framed card layout.

border-image-card.css
.card {
  max-width: 18rem;
  padding: 1.25rem;
  border: 6px solid transparent;
  border-image: linear-gradient(to right, #059669, #2563eb) 1;
  background: #f8fafc;
  border-radius: 0.25rem;
}
Try It Yourself

How It Works

Padding keeps content away from the decorative border. The gradient frame adds visual emphasis without extra HTML elements.

🧠 How border-image Works

1

You set a border width

The element needs border space — often border: 10px solid transparent;.

Border area
2

The source is sliced into nine parts

CSS cuts the image or gradient into corners, edges, and a center region.

Slice
3

Edge pieces fill each side

Corners stay fixed while edges stretch or repeat based on your keyword.

Repeat
=

Custom image border

Your element gets a decorative frame that goes beyond basic line styles.

Modern Browser Support

The border-image property is supported in all modern browsers. Gradient sources work in current Chrome, Firefox, Safari, and Edge versions.

Baseline · Modern browsers

Image borders in today’s browsers

Chrome, Edge, Firefox, Safari, and Opera support border-image in current versions.

96% Modern browser support
Google Chrome15+ · Desktop & Mobile
Full support
Mozilla Firefox15+ · Desktop & Mobile
Full support
Apple Safari6+ · macOS & iOS
Full support
Microsoft Edge12+ · All versions
Full support
Opera15+ · Modern versions
Full support

Fallback behavior

When unsupported, the border falls back to normal border styling.

💻
Internet Explorer Partial support in IE 11 · May need vendor prefixes for older versions
Partial
border-image property 96% supported

Bottom line: Use border-image for decorative borders in modern projects. Provide a simple solid border fallback for legacy browsers if needed.

Conclusion

The border-image property opens up creative border styling beyond plain lines. By combining a source image or gradient with slice and repeat values, you can build frames, patterned edges, and eye-catching UI elements.

Experiment with different sources, slice numbers, and repeat keywords to see how this property can enhance the visual appeal of your web designs.

💡 Best Practices

✅ Do

  • Set a visible border width before applying border-image
  • Use gradients for simple colorful borders without image files
  • Test slice values with your actual border artwork
  • Keep border width proportional to the design
  • Provide a solid border fallback for critical UI elements

❌ Don’t

  • Forget that border-radius and border-image interact inconsistently across browsers
  • Use huge slice values without checking the source image size
  • Depend on image borders for essential accessibility cues alone
  • Assume round and repeat behave identically on all sides
  • Skip testing on mobile browsers for gradient borders

Key Takeaways

Knowledge Unlocked

Five things to remember about border-image

Use these points when building decorative borders.

5
Core concepts
02

Default none

Normal borders.

Default
✂️03

Slice

Nine-region cut.

Syntax
🔀04

Repeat

stretch, round, space.

Behavior
🎨05

Gradients

No file needed.

Tip

❓ Frequently Asked Questions

The border-image property lets you use an image or gradient as an element's border instead of a plain solid line. It slices the source into regions and maps them to the border edges and corners.
The initial value is none, which means no image border is used and the element falls back to normal border properties.
You usually need a visible border width, a border-image-source, and a border-image-slice value. A common pattern is border: 10px solid transparent; followed by border-image settings.
Yes. Gradients work as a border-image-source in modern browsers and are a simple way to create colorful borders without an image file.
border sets width, style, and color for standard lines. border-image replaces the border painting with a sliced image or gradient while still using the border area for sizing.

Practice in the Live Editor

Open the HTML editor, try border-image, and preview decorative borders instantly.

HTML Editor →

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.

5 people found this page helpful