1. Introduction
The properties of this module deal with the decoration of the border area. It also defines decorations that can be applied to the box.
1.1. Module Interactions
This specification extends the parts related to borders and box decorations of CSS Backgrounds and Borders Module Level 3 [CSS3BG].
It provides specifications for the added corner-*-shape and border-shape properties, as well as logical shorthands for border-*-radius, box-shadow-* longhands, and partial borders via the border-limit and border-*-clip properties.
All properties in this module apply to the ::first-letter pseudo-element. The border-radius properties also apply to the ::first-line pseudo-element. The UA may (but is not required to) apply the border-image or box-shadow properties to ::first-line. The UA must not apply the border-color/style/width properties to ::first-line. [CSS2]
1.2. Value Definitions
This specification follows the CSS property definition conventions from [CSS2] using the value definition syntax from [CSS-VALUES-3]. Value types not defined in this specification are defined in CSS Values & Units [CSS-VALUES-3]. Combination with other CSS modules may expand the definitions of these value types. For example, combining with CSS Images allows for using CSS gradients as background-image or border-image values. [CSS-IMAGES-3]
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the CSS-wide keywords as their property value. For readability they have not been repeated explicitly.
2. Borders
The border can either be a predefined style (solid line, double line, dotted line, pseudo-3D border, etc.) or it can be an image. In the former case, various properties define the style (border-style), color (border-color), and thickness (border-width) of the border.
Tests
Tests for features Not yet incorporated from Backgrounds 3
- border-image-gradient-zero-size-transform-crash.html (live test) (source)
- border-image-width-interpolation-math-functions.html (live test) (source)
2.1. Line Colors: the border-color properties
| Name: | border-top-color, border-right-color, border-bottom-color, border-left-color, border-block-start-color, border-block-end-color, border-inline-start-color, border-inline-end-color |
|---|---|
| Value: | <color> | <image-1D> |
| Initial: | currentcolor |
| Applies to: | all elements except ruby base containers and ruby annotation containers |
| Inherited: | no |
| Percentages: | N/A |
| Computed value: | the computed color and/or a one-dimensional image function |
| Canonical order: | per grammar |
| Animation type: | see prose |
| Logical property group: | border-color |
These properties set the foreground color of the border specified by the border-style properties.
The stripes defined by <image-1D> follow the shape of the border on the side to which they apply, and are drawn in bands starting from the padding edge and progressing outwards. The border width at each point defines the total width of the stripes at that point.
.foo{ border : 30 px solid; border-color : stripes ( dodgerblue, skyblue) stripes ( yellow, gold) stripes ( lightgreen, limegreen) stripes ( indianred, orange); }
Sample rendering:

The same border colors with border-style: dotted:

| Name: | border-color |
|---|---|
| Value: | [ <color> | <image-1D> ]{1,4} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
border-color is a shorthand property for the four physical border-*-color properties. The four values set the top, right, bottom and left border, respectively. A missing left is the same as right, a missing bottom is the same as top, and a missing right is also the same as top. This is resolved individually for each list item.
The flow-relative properties border-block-start-color, border-block-end-color, border-inline-start-color, and border-inline-end-color correspond to the physical properties border-top-color, border-bottom-color, border-left-color, and border-right-color. The mapping depends on the element’s writing-mode, direction, and text-orientation.
| Name: | border-block-color, border-inline-color |
|---|---|
| Value: | <'border-top-color'>{1,2} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
These two shorthand properties set the border-block-start-color & border-block-end-color and border-inline-start-color & border-inline-end-color, respectively. The first value represents the start side color, and the second value represents the end side color. If only one value is given, it applies to both the start and end sides.
Tests
- border-color-interpolation.html (live test) (source)
- border-image-displayed-with-transparent-border-color.html (live test) (source)
- color-mix-currentcolor-border-repaint-parent.html (live test) (source)
- color-mix-currentcolor-border-repaint.html (live test) (source)
- currentcolor-border-repaint-parent.html (live test) (source)
- inheritance.sub.html (live test) (source)
- border-color-computed.html (live test) (source)
- border-color-invalid.html (live test) (source)
- border-color-shorthand.html (live test) (source)
- border-color-valid.html (live test) (source)
2.2. Line Patterns: the border-style properties
| Name: | border-top-style, border-right-style, border-bottom-style, border-left-style, border-block-start-style, border-block-end-style, border-inline-start-style, border-inline-end-style |
|---|---|
| Value: | <line-style> |
| Initial: | none |
| Applies to: | all elements except ruby base containers and ruby annotation containers |
| Inherited: | no |
| Percentages: | N/A |
| Computed value: | specified keyword |
| Canonical order: | per grammar |
| Animation type: | discrete |
| Logical property group: | border-style |
These properties control whether a border appears, and if it does what style it’s drawn in (if it is not overridden by a border image).
The flow-relative properties border-block-start-style, border-block-end-style, border-inline-start-style, and border-inline-end-style correspond to the physical properties border-top-style, border-bottom-style, border-left-style, and border-right-style. The mapping depends on the element’s writing-mode, direction, and text-orientation.
| Name: | border-block-style, border-inline-style |
|---|---|
| Value: | <'border-top-style'>{1,2} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
These two shorthand properties set the border-block-start-style & border-block-end-style and border-inline-start-style & border-inline-end-style, respectively. The first value represents the start side style, and the second value represents the end side style. If only one value is given, it applies to both the start and end sides.
| Name: | border-style |
|---|---|
| Value: | <'border-top-style'>{1,4} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
border-style is a shorthand property for the four physical border-*-style properties. The four values set the top, right, bottom and left border, respectively. A missing left is the same as right, a missing bottom is the same as top, and a missing right is also the same as top. This is resolved individually for each list item.
The style is specified as a <line-style> keyword, where
<line-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
Values have the following meanings:
- none
- No border. Color and width are ignored (i.e., the border has width 0). Note this means that the initial value of border-image-width will also resolve to zero.
- hidden
- Same as none, but has different behavior in the border conflict resolution rules for border-collapsed tables [CSS2].
- dotted
- A series of round dots.
- dashed
- A series of square-ended dashes.
- solid
- A single line segment.
- double
- Two parallel solid lines with some space between them. (The thickness of the lines is not specified, but the sum of the lines and the space must equal border-width.)
- groove
- Looks as if it were carved in the canvas. (This is typically achieved by creating a “shadow” from two colors that are slightly lighter and darker than the specified border-color.)
- ridge
- Looks as if it were coming out of the canvas.
- inset
- Looks as if the content on the inside of the border is sunken into the canvas. Treated as ridge in the collapsing border model. [CSS2]
- outset
- Looks as if the content on the inside of the border is raised out of the canvas. Treated as groove in the collapsing border model. [CSS2]
Borders are drawn in front of the element’s background, but behind the element’s content (in case it overlaps).
Note: Border colors close to black or white may need different color calculations than colors in between in order to create the required “3D” effect of groove, ridge, inset, or outset.
Note: There is no control over the spacing of the dots and dashes, nor over the length of the dashes. Implementations are encouraged to choose a spacing that makes the corners symmetrical.
Tests
2.3. Line Thickness: the border-width properties
| Name: | border-top-width, border-right-width, border-bottom-width, border-left-width, border-block-start-width, border-block-end-width, border-inline-start-width, border-inline-end-width |
|---|---|
| Value: | <line-width> |
| Initial: | medium |
| Applies to: | all elements except ruby base containers and ruby annotation containers |
| Inherited: | no |
| Percentages: | N/A |
| Computed value: | absolute length, snapped as a border width |
| Canonical order: | per grammar |
| Animation type: | by computed value |
| Logical property group: | border-width |
These properties specify the thickness of the border, i.e. the border width. Where
<line-width> = <length [0,∞]> | hairline | thin | medium | thick
Negative values are invalid. The thin, medium, and thick keywords are equivalent to 1px, 3px, and 5px, respectively. The hairline keyword is a UA-defined length, less than or equal to 1px and equal to an integer number of device pixels at the default page zoom, which represents a "just visible" line. (While it can be as large as 1px, on many devices it will be approximately 0.3px to 0.5px.)
The resolved value for the border-width properties is the used value.
If the border-style corresponding to a given border-width is none or , then the used width is 0.
The flow-relative properties border-block-start-width, border-block-end-width, border-inline-start-width, and border-inline-end-width correspond to the physical properties border-top-width, border-bottom-width, border-left-width, and border-right-width. The mapping depends on the element’s writing-mode, direction, and text-orientation.
| Name: | border-block-width, border-inline-width |
|---|---|
| Value: | <'border-top-width'>{1,2} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
These two shorthand properties set the border-block-start-width & border-block-end-width and border-inline-start-width & border-inline-end-width, respectively. The first value represents the start side width, and the second value represents the end side width. If only one value is given, it applies to both the start and end sides.
| Name: | border-width |
|---|---|
| Value: | <'border-top-width'>{1,4} |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
border-width is a shorthand property for the four physical border-*-width properties. The four values set the top, right, bottom and left border, respectively. A missing left is the same as right, a missing bottom is the same as top, and a missing right is also the same as top. This is resolved individually for each list item.
Note: Although the initial width is medium, the initial style is none; therefore the used initial width is 0.
Tests
- border-bottom-width-composition.html (live test) (source)
- border-image-width-composition.html (live test) (source)
- border-image-width-interpolation.html (live test) (source)
- border-left-width-composition.html (live test) (source)
- border-right-width-composition.html (live test) (source)
- border-top-width-composition.html (live test) (source)
- border-width-interpolation.html (live test) (source)
- border-bottom-width-medium.html (live test) (source)
- border-bottom-width-thick.html (live test) (source)
- border-bottom-width-thin.html (live test) (source)
- border-left-width-medium.html (live test) (source)
- border-left-width-thick.html (live test) (source)
- border-left-width-thin.html (live test) (source)
- border-right-width-medium.html (live test) (source)
- border-right-width-thick.html (live test) (source)
- border-right-width-thin.html (live test) (source)
- border-top-width-medium.html (live test) (source)
- border-top-width-thick.html (live test) (source)
- border-top-width-thin.html (live test) (source)
- border-width-cssom.html (live test) (source)
- border-width-pixel-snapping-001-a.html (live test) (source)
- border-width-pixel-snapping-001-b.html (live test) (source)
- border-width-small-values-001-a.html (live test) (source)
- border-width-small-values-001-b.html (live test) (source)
- border-width-small-values-001-c.html (live test) (source)
- border-width-small-values-001-d.html (live test) (source)
- border-width-small-values-001-e.html (live test) (source)
- inheritance.sub.html (live test) (source)
- border-width-computed.html (live test) (source)
- border-width-invalid.html (live test) (source)
- border-width-shorthand.html (live test) (source)
- border-width-valid.html (live test) (source)
2.4. Border Shorthand Properties
| Name: | border-top, border-right, border-bottom, border-left, border-block-start, border-block-end, border-inline-start, border-inline-end |
|---|---|
| Value: | <line-width> || <line-style> || <color> |
| Initial: | See individual properties |
| Applies to: | all elements except ruby base containers and ruby annotation containers |
| Inherited: | no |
| Percentages: | N/A |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
These shorthand properties set the border-width, border-color, and border-style of one side of the borders of a box. Omitted values are set to their initial values.
The flow-relative properties border-block-start, border-block-end, border-inline-start, and border-inline-end correspond to the physical properties border-top, border-bottom, border-left, and border-right. The mapping depends on the element’s writing-mode, direction, and text-orientation.
| Name: | border-block, border-inline |
|---|---|
| Value: | <'border-block-start'> |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
These two shorthand properties set the border-block-start & border-block-end or border-inline-start & border-inline-end, respectively, both to the same style.
| Name: | border |
|---|---|
| Value: | <line-width> || <line-style> || <color> |
| Initial: | see individual properties |
| Applies to: | see individual properties |
| Inherited: | see individual properties |
| Percentages: | see individual properties |
| Computed value: | see individual properties |
| Animation type: | see individual properties |
| Canonical order: | per grammar |
Tests
The border property is a shorthand property for setting the same border-width, border-color, and border-style for all four borders of a box. Unlike the shorthand margin and padding properties, the border property cannot set different values on the four borders. To do so, one or more of the other border properties must be used.
The border shorthand also resets border-image to its initial value. It is therefore recommended that authors use the border shorthand, rather than other shorthands or the individual properties, to override any border settings earlier in the cascade. This will ensure that border-image has also been reset to allow the new styles to take effect.
Note: The CSS Working Group intends for the border shorthand to reset all border properties in future levels of CSS as well. For example, if a border-characters property is introduced in the future to allow glyphs as borders, it will also be reset by the border shorthand. By using the border shorthand to reset borders, authors can be guaranteed a “blank canvas” no matter what properties are introduced in the future.
p { border: solid red }
p {
border-top: solid red;
border-right: solid red;
border-bottom: solid red;
border-left: solid red;
border-image: none;
}
Since, to some extent, the properties have overlapping functionality, the order in which the rules are specified is important.
blockquote {
border-color: red;
border-left: double;
color: black
}
In the above example, the color of the left border is black, while the other borders are red. This is due to border-left setting the width, style, and color. Since the color value is not given by the border-left property, it will be taken from the color property. The fact that the color property is set after the border-left property is not relevant.
3. Corners
The padding edge (inner border) radius is the outer border radius minus the corresponding border thickness. In the case where this results in a negative value, the inner radius is zero. (In such cases the center of the border’s inner curve might not coincide with that of its outer curve.) Likewise the content edge radius is the padding edge radius minus the corresponding padding, or if that is negative, zero. The border and padding thicknesses in the curved region are thus interpolated from the adjoining sides, and when two adjoining borders are of different thicknesses the corner will show a smooth transition between the thicker and thinner borders.
All border styles (solid, dotted, inset, etc.) follow the curve of the border.
Note: If the center of a corner’s outer curve is past an opposite padding edge (in the border area of a side opposite the corner), the inner curve will not be a full quarter ellipse.
p { width: 70px; height: 70px; border: solid 30px;
border-color: orange orange silver silver;
border-top-right-radius: 100%; }
|
|
The margin edge, being outside the border edge, calculates its radius by adding the corresponding margin thickness to each border radius, with the corresponding outset-adjusted border radius applied.
When expanding an edge that has a border radius, e.g. for computing the margin edge, box-shadow spread, or overflow-clip-margin, the different border radius values are adjusted so that a small rounded corner with a big outset does not appear to be disproportionally round.
This is done by computing the corresponding outset-adjusted border radius.
To compute the outset-adjusted border radius given the 2-dimensional size’s edge, radius, and outset:
-
Let coverage be
2 * min(radius’s width / edge’s width, radius’s height / edge’s height). -
Let adustedRadiusWidth be the adjusted radius dimension given coverage, radius’s width, and outset’s width.
-
Let adustedRadiusHeight be the adjusted radius dimension given coverage, radius’s height, and outset’s height.
-
Return (adustedRadiusWidth, adustedRadiusHeight).
To compute the adjusted radius dimension given numbers coverage, radius, and outset:
-
If radius is greater than spread, or if coverage is greater than 1, then return
radius + outset. -
Let ratio be
radius / outset. -
Return
radius + outset * (1 - (1 - ratio)3 * (1 - coverage3)).
Note: this algorithm is designed to reduce the effect of the outset (or spread) on the shape of the corner. The coverage factor makes this reduction more pronounced for rectangular shapes (where the border radius is close to 0), and less pronounced for elliptical shapes (where the border radius is close to 50%).
3.1. Corner Clipping
Although border images are not affected by border-radius, other effects that clip painting or event handling to the border, padding, or content edge must clip to their respective curves. For example, backgrounds clip to the curve specified by background-clip, overflow values other than visible to the curved padding edge (when overflow on both axes is not visible), replaced element content to the curved content edge, pointer events to the curved border edge, etc.
Note: As border-radius reduces the interactive area of an element authors should make sure the remaining interactive area conforms to recommended minima for the platforms they target; in particular, conforming to recommended minimum touch target sizes may require larger widths and heights when border-radius is used.
DIV {
background: black;
color: white;
border-radius: 1em;
padding: 1em }
3.2. Color and Style Transitions
Color and style transitions must be contained within the segment of the border that intersects the smallest rectangle that contains both border radii as well as the center of the inner curve (which may be a point representing the corner of the padding edge, if the border radii are smaller than the border width).
If one of these borders is zero-width, then the other border takes up the entire transitional area. Otherwise, the center of color and style transitions between adjoining borders is a point along the curve that is a continuous monotonic function of the ratio of the border widths. However it is not defined what these transitions look like or what function maps from this ratio to a point on the curve.
3.3. Overlapping Curves
Corner curves must not overlap: When the sum of any two adjacent border radii exceeds the size of the border box, UAs must proportionally reduce the used values of all border radii until none of them overlap. The algorithm for reducing radii is as follows:
Let f = min(Li/Si), where i ∈ {top, right, bottom, left}, Si is the sum of the two corresponding radii of the corners on side i, and Ltop = Lbottom = the width of the box, and Lleft = Lright = the height of the box. If f < 1, then all corner radii are reduced by multiplying them by f.
Note: This formula ensures that quarter circles remain quarter circles and large radii remain larger than smaller ones, but it may reduce corners that were already small enough, which may make borders of nearby elements that should look the same look different.
If the curve interferes with UI elements such as scrollbars, the UA may further reduce the used value of the affected border radii (and only the affected border radii) as much as necessary, but no more.
box-sizing: border-box; width: 6em; height: 2.5em; border-radius: 0.5em 2em 0.5em 2em
The height (2.5em) is enough for the specified radii (0.5em plus 2.0em). However, if the height is only 2em,
box-sizing: border-box; width: 6em; height: 2em; border-radius: 0.5em 2em 0.5em 2em
all corners need to be reduced by a factor 0.8 to make them fit. The used border radii thus are 0.4em (instead of 0.5em) and 1.6em (instead of 2em). See borders B in the figure.