border-image

« CSS « CSS Reference

Summary

The border-image CSS property allows drawing an image on the borders of elements. This makes drawing complex looking widgets much simpler than it has been and removes the need for nine boxes in some cases.

The border-image is used instead of the border styles given by the border-style properties. It is important to note that if the computed value of border-image-source, which can be set either by border-image-source or the shorthand border-image, is none, or if the image cannot be displayed, the border styles will be used.

  • Initial value border-image is a shorthand property, so it does not technically have an initial value
    but the properties for which it is shorthand have the following initial values:
    • border-image-source: none
    • border-image-slice: 100%
    • border-image-width: 1
    • border-image-outset: 0
    • border-image-repeat: stretch
  • Applies to all elements, except table elements when border-collapse is collapse
  • Inherited no
  • Media visual
  • Computed value any URI made absolute, any <length> made absolute, other parts as specified

Syntax

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

Values

See the respective properties for the different values.

Examples

Bitmap repeated (repeat)

The image is sliced and simply tiled to fill the border area.

.example { 
    border: 30px solid transparent;
    -moz-border-image:url("/files/4127/border.png") 30 30 repeat; /* Old firefox */
    -webkit-border-image:url("/files/4127/border.png") 30 30 repeat; /* Safari */
    -o-border-image:url("/files/4127/border.png") 30 30 repeat; /* Opera */
    border-image:url("/files/4127/border.png") 30 30 repeat;
}

Results into:
border image repeat demo

Bitmap repeated (round)

The round option is a variation on the repeat option that distributes the tiles in such a way that the ends nicely connect.

.example { 
    border: 30px solid transparent;
    -moz-border-image:url("/files/4127/border.png") 30 30 round; /* Old firefox */
    -webkit-border-image:url("/files/4127/border.png") 30 30 round; /* Safari */
    -o-border-image:url("/files/4127/border.png") 30 30 round; /* Opera */
    border-image:url("/files/4127/border.png") 30 30 round;
}

Results into:
border image round demo

Bitmap stretched

The 'stretch' option stretches the images to fill the border area.

.example { 
    border: 30px solid transparent;
    -moz-border-image:url("/files/4127/border.png") 30 30 stretch; /* Old firefox */
    -webkit-border-image:url("/files/4127/border.png") 30 30 stretch; /* Safari */
    -o-border-image:url("/files/4127/border.png") 30 30 stretch; /* Opera */
    border-image:url("/files/4127/border.png") 30 30 stretch;
}

Results into:
border image stretch demo

Specifications

Specification Status Comment
CSS Backgrounds and Borders Module Level 3 Candidate Recommendation  

Browser compatibility

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari
Basic support

3.5 (1.9.1)-moz [1]

Without prefix since 15.0 (15)

7.0-webkit Not supported 10.5 / 11.0-o 3.0-webkit [2]
optional <border-image-slice> 15.0 (15) ? Not supported ? ?
fill keyword 15.0 (15) ? Not supported ? ?
Feature iOS Safari Opera Mini Opera Mobile Android Browser
Basic support

3.2-webkit

Without prefix since 15.0 (15)

Not supported 11.0-o 2.1-webkit
optional <border-image-slice> 15.0 (15) Not supported ? ?
fill keyword 15.0 (15) Not supported ? ?

Notes

  • [1] An earlier version of the specification was implemented, prefixed, in Gecko versions prior to 15.
  • [2] For Opera, the prefixed property was added after the non-prefixed.

See also

Tags (2)

Attachments (4)

File Size Date Attached by
border image
an example borderimage
849 bytes 2012-10-10 12:47:02 Murb
border image repeat demo
border image repeat demo
4002 bytes 2012-10-10 13:19:33 Murb
border image round demo
border image round demo
9313 bytes 2012-10-10 13:19:45 Murb
border image stretch demo
border image stretch demo
4632 bytes 2012-10-10 13:20:01 Murb
Contributors to this page: Sheppy, leaverou, Jürgen Jeka, teoli, ethertank, Mohammed.Ibrahim, zweinberg, GiulianT, Kennyluck, mnoorenberghe, barryvan, Wjjohnst, brianloveswords, j.j., Murb, paul.irish
Last updated by: Murb,
Last reviewed by: Murb,