← Back to CSS
27

Advanced borders with `border-image`

Master `border-image`: the 9-slice model, `slice`/`width`/`repeat` control, fallbacks and reusable patterns for real components.

📘 Theory

Mental model: 9 slices and the border area

1

The browser divides the source into a 3x3 grid: four corners, four edges and a center region. Most of the time you only render the perimeter, but the center can be kept with `fill`.

2

Always create the border area first with `border`, then layer `border-image` on top. If you skip that first step, it can look as if the property is broken.

`slice`, percentages and `fill`

  • `slice` decides where the source is cut, either with numbers or percentages.
  • `fill` keeps the center region too, which is useful for textured frames or sticker-like effects.
  • A poorly calibrated slice value can distort the corners, so gradients often start safely at `1`.

`width`, `repeat` and visual stability

1

`border-image-width` controls the final painted thickness and does not always need to match the original `border-width` exactly.

2

`repeat` is often the safest choice for patterned frames, while `round` helps avoid awkward clipping when the source does not divide evenly.

Progressive fallback

  • Set a useful plain `border-color` first so the component still has contrast.
  • Use `@supports` to enable the enhanced frame only when it makes sense.
  • Do not rely on a decorative border alone to communicate a critical state.

🧪 Learn by doing

Example Interactive demo: slice, thickness and repeat mode Tune the key parameters to understand why one frame feels clean and another feels distorted.
Example Example: feature card with a dynamic frame A practical pattern for highlighted cards without adding extra pseudo-elements.

🏁 Challenges

Challenge Challenge: gradient frame Apply `border-image` using a gradient and a transparent border.

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com