CSS backgrounds and borders
The CSS backgrounds and borders module provides properties for adding borders, rounded corners, and box shadows to elements.
You can add different types of border styles, including borders made of images of any image type, from raster images to CSS gradients. Borders can be square or rounded, and a different radius can be set for each corner. Elements can be rounded whether or not they have a visible border.
Box shadows include inset and outset shadow, single or multiple shadows, and solid or allowed to fade to transparent. An outer box-shadow casts a shadow as if the border-box of the element were opaque. An inner box-shadow casts a shadow as if everything outside the padding edge were opaque. The shadow can be solid or include a spread distance with the shadow color transitioning to transparent.
The properties in this module also let you define whether cells inside a <table>
should have shared or separate borders.
Backgrounds, borders, and box shadows in action
This sample of borders, backgrounds, and box shadows consists of centered background images made of linear and radial gradients. A series of box shadows make the border appear to "pop". The element on the left has a border image set. The element on the right has a rounded dotted border.
The background images are defined with background-image
. The images are centered with background-position
. Different values of the background-clip
property for the multiple background images are used to make the background images stay within the content box. The background color gets clipped to the padding box preventing the background from appearing through the transparent sections for the border-image
and the dotted
border
. The rounded corners in the element on the right are created using the border-radius
property. A single box-shadow
declaration is used to set all the shadows, both inset and outset.
To see the code for this sample, view the source on GitHub.
Reference
Properties
background-attachment
background-clip
background-color
background-image
background-origin
background-position
background-repeat
background-size
background
shorthandbackground-position-x
background-position-y
background-position-inline
background-position-block
border-bottom-color
border-bottom-style
border-bottom-width
border-bottom
shorthandborder-left-color
border-left-style
border-left-width
border-left
shorthandborder-right-color
border-right-style
border-right-width
border-right
shorthandborder-top-color
border-top-style
border-top-width
border-top
shorthandborder-color
shorthandborder-style
shorthandborder-width
shorthandborder
shorthandborder-collapse
border-bottom-left-radius
border-bottom-right-radius
border-top-left-radius
border-top-right-radius
border-radius
shorthandborder-image-outset
border-image-repeat
border-image-slice
border-image-source
border-image-width
border-image
shorthandbox-shadow
Data types
<line-style>
enumerated type
Guides
- Learn CSS: background and borders
-
Explains how to implement decorative images using CSS background images.
- Using multiple backgrounds
-
Explains how to set one or more backgrounds on an element.
- Resizing background images
-
Describes how to change the size and repeating behavior of background images.
- Learn CSS: the box model
-
Explains how borders, along with other box model properties, impact the CSS box model.
- Using CSS gradients
-
Explains how to create CSS gradient background images.
Related concepts
border-block-end-color
propertyborder-block-start-color
propertyborder-inline-end-color
propertyborder-inline-start-color
propertyborder-block-end-style
propertyborder-block-start-style
propertyborder-inline-end-style
propertyborder-inline-start-style
propertyborder-block-end-width
propertyborder-block-start-width
propertyborder-inline-end-width
propertyborder-inline-start-width
propertyborder-start-start-radius
propertyborder-start-end-radius
propertyborder-end-start-radius
propertyborder-end-end-radius
propertybox-sizing
propertybox-decoration-break
propertytext-shadow
propertyurl()
CSS function<color>
data type<image>
data type<position>
data typecurrentcolor
keyword
Specifications
Specification |
---|
CSS Backgrounds and Borders Module Level 3 |
See also
- Interactive tools that let you visually create borders images, rounded corners, and box shadows:
- Applying color to HTML elements using CSS, including for borders.
- The
drop-shadow()
filter function that applies a drop shadow effect to the input image. The function is used by thefilter
andbackdrop-filter
properties.