Nearby lessons

10 of 15

🖼️ CSS Border Image

📌 What is CSS Border Image?

The border-image property allows you to use an image as a border around an HTML element instead of a solid color or gradient. This can add decorative, creative borders without needing extra elements.

📌 Introduction to Border Images

border-image slices an image into parts and applies them to an element’s border. You must define a border-width for this property to apply.

🖼️ Basic Usage with border-image-source

Defines the image to be used as the border.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

✂️ Adding border-image-slice

Defines how to slice the image into nine parts (top, right, bottom, left, and center).
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🔁 Border Image Repeat: repeat

Repeat the image slice using border-image-repeat: repeat; to tile the image sections.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🔁 Border Image Repeat: stretch

Stretch the image slice using border-image-repeat: stretch; to fill the space.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🔁 Border Image Repeat: round

Repeat the image slice using border-image-repeat: round; and scale to fit the border.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

📏 Set border-image-width

Controls the width of the image portion used for the border.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

📤 Set border-image-outset

Pushes the border image outward beyond the element's border box.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

📦 Complete Shorthand Syntax

You can use the shorthand border-image to set source, slice, width, outset, and repeat all in one line.
Code Example
PREVIEW READY
Loading Editor...
Live Preview

✅ Best Practices

  • 🧱 Always define border-width or border before using border-image
  • 🖼️ Use high-resolution images for crisp borders
  • 🔄 Use 'repeat' or 'round' for seamless edges
  • 📏 Avoid overly large slice values to prevent distortion

📘 Border Image Properties

AttributeDescription
border-imageShorthand to set all border image properties
border-image-sourcePath to the image
border-image-sliceSlices the image into parts (top, right, bottom, left)
border-image-widthSets the width of the border image
border-image-outsetPushes the image outside the element border box
border-image-repeatSets how to repeat the border image (stretch, repeat, round, space)

🧠 Test Your Knowledge

4 Questions

Progress: 0 / 4
Keep Going!CSS - Box & Text Shadow