Title: CSS Backgrounds and Borders Module Level 3 Status: ED Work Status: Testing Shortname: css-backgrounds Level: 3 Group: csswg ED: https://drafts.csswg.org/css-backgrounds/ TR: https://www.w3.org/TR/css-backgrounds-3/ Previous Version: https://www.w3.org/TR/2017/CR-css-backgrounds-3-20171017/ Previous version: https://www.w3.org/TR/2014/CR-css3-background-20140909/ Editor: Bert Bos, W3C, bert@w3.org, w3cid 3343 Editor: Elika J. Etemad / fantasai, Invited Expert, http://fantasai.inkedblade.net/contact, w3cid 35400 Editor: Brad Kemper, Invited Expert, brad.kemper@gmail.com, w3cid 43245 Abstract: This draft contains the features of CSS relating to borders and backgrounds. The main extensions compared to level 2 are borders consisting of images, boxes with multiple backgrounds, boxes with rounded corners and boxes with shadows. Test Suite: http://test.csswg.org/suites/css3-background/nightly-unstable/ At risk: animatability of 'box-shadow' At risk: applicability of 'border' and its longhands to [=ruby base containers=] and [=ruby annotation containers=] Use Autolinks: yes
spec:css2; type:type; text:spec:css2; type:property; text:display spec:css2; type:value; text:table spec:css2; type:value; text:inline-table spec:css2; type:value; text:table-cell spec:css2; type:property; text:overflow spec:css2; type:value; text:visible spec:css-color-3; type:property; text:color spec:css-color-3; type:value; text:transparent spec:selectors-3; type:selector; text: ::first-letter spec:selectors-3; type:selector; text: ::first-line spec:css-values-3; type:type; text:
This subsection is not normative.
When elements are rendered according to the CSS box model [[!CSS-BOX-3]], each element is either not displayed at all, or formatted as one or more rectangular boxes. Each box has a rectangular content area, a band of padding around the content, a border around the padding, and a margin outside the border. (The margin may actually be negative, but margins have no influence on the background and border.)
The various areas and edges of a typical box. (This diagram is explained in the CSS Box Model Module [[!CSS-BOX-3]].)
The properties of this module deal with the decoration of the border area and with the background of the content, padding and border areas. Additionally the box may be given a "drop-shadow" effect with the 'box-shadow' property.
If an element is broken into multiple boxes, 'box-decoration-break' [[CSS3-BREAK]] defines how the borders and background are divided over the various boxes. (An element can result in more than one box if it is broken at the end of a line, at the end of a column or at the end of a page; and continued in the next line, column or page.)
The relative stacking order of backgrounds, borders, and shadows is given in this module. For how these layers interact with other rendered content, see Appendix E “Elaborate description of Stacking Contexts” in [[!CSS2]].
This module replaces and extends the background and border features defined in [[!CSS2]] sections 8.5 and 14.2.
All properties in this module apply to the
::first-letter
pseudo-element. The background properties
and 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]]
It is expected that CSS will include ways to animate transitions between styles. (The section “Animation of property types” of the CSS Transitions module [[CSS3-TRANSITIONS]] is expected to define how different kinds of values are interpolated during a transition.) In anticipation of that, this module includes a line “Animatable” for each property, which specifies whether and how values of the property can be animated.
Each box has a background layer that may be fully transparent (the default), or filled with a color and/or one or more images. The background properties specify what color ('background-color') and images ('background-image') to use, and how they are sized, positioned, tiled, etc.
The background properties are not inherited, but the parent box's background will shine through by default because of the initial ''transparent'' value on 'background-color'.
The background of a box can have multiple layers in CSS3. The number of layers is determined by the number of comma-separated values in the 'background-image' property. Note that a value of ''background-image/none'' still creates a layer.
Each of the images is sized, positioned, and tiled according to the corresponding value in the other background properties. The lists are matched up from the first value: excess values at the end are not used. If a property doesn't have enough comma-separated values to match the number of layers, the UA must calculate its used value by repeating the list of values until there are enough.
For example, this set of declarations:
background-image: url(flower.png), url(ball.png), url(grass.png); background-position: center center, 20% 80%, top left, bottom right; background-origin: border-box, content-box; background-repeat: no-repeat;
has exactly the same effect as this set with the extra position dropped and the missing values for 'background-origin' and 'background-repeat' filled in (emphasized for clarity):
background-image: url(flower.png), url(ball.png), url(grass1.png); background-position: center center, 20% 80%, top left; background-origin: border-box, content-box, border-box; background-repeat: no-repeat, no-repeat, no-repeat;
The first image in the list is the layer closest to the user, the next one is painted behind the first, and so on. The background color, if present, is painted below all of the other layers.
Note that the border-image properties can also define a background image, which, if present, is painted on top of the background created by the background properties.
Name: | background-color | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Value: | <Initial:
| transparent
| Applies to:
| all elements
| Inherited:
| no
| Percentages:
| N/A
| Computed value:
| computed color
| Animation type:
| by computed value
| |
This property sets the background color of an element. The color is drawn behind any background images.
Example:
h1 { background-color: #F00 } /* Sets background to red. */
The background color is clipped according to the 'background-clip' value associated with the bottom-most background image layer.
Name: | background-image | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Value: | <Initial:
| none
| Applies to:
| all elements
| Inherited:
| no
| Percentages:
| N/A
| Computed value:
| computed < | Animation type:
| discrete
| |
This property sets the background image(s) of an element. Images are drawn with the first specified one on top (closest to the user) and each subsequent image behind the previous one. Where
<> = <> | none
A value of none counts as an image layer but draws nothing. An image that is empty (zero width or zero height), that fails to download, or that cannot be displayed (e.g., because it is not in a supported image format) likewise counts as a layer but draws nothing.
See the section “Layering multiple background images” for how 'background-image' interacts with other comma-separated background properties to form each background image layer.
When setting a background image, authors should also specify a 'background-color' that will preserve contrast with the text for when the image is unavailable.
For accessibility reasons, authors should not use background images as the sole method of conveying important information. See Web Content Accessibility Guideline F3 [[WCAG20]]. Images are not accessible in non-graphical presentations, and background images specifically might be turned off in high-contrast display modes.
Note that stylistic foreground images can be provided in CSS with the content property. (Semantically-important foreground images should be provided in the document markup, e.g. with the <img> tag in HTML.)
Media fragments can be used to display a portion of an image. The CSS Images module will provide fallback syntax for image formats and include additional controls for image display.
Some examples specifying background images:
body { background-image: url("marble.svg") } p { background-image: none } div { background-image: url(tl.png), url(tr.png) }
Implementations may optimize by not downloading and drawing images that are not visible (e.g., because they are behind other, fully opaque images).
Name: | background-repeat | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Value: | <Initial:
| repeat
| Applies to:
| all elements
| Inherited:
| no
| Percentages:
| N/A
| Computed value:
| list, each item a pair of keywords, one per dimension
| Animation type:
| discrete
| |
Specifies how background images are tiled after they have been sized and positioned. Where
<> = repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}
Single values for < If a < Unless one of the two keywords is ''no-repeat'', the
whole background painting area will be tiled, i.e., not just one
vertical strip and one horizontal strip.
The effect of ''repeat-y'': One copy
of the background image is centered, and other copies are put above
and below it to make a vertical band behind the element.
The effect of ''background-repeat/space'': the image of a dot is
tiled to cover the whole background and the images are equally
spaced.
See the section “Layering multiple background
images” for how 'background-repeat' interacts with other
comma-separated background properties to form each background image
layer.
If background images are specified, this property specifies whether
they are fixed with regard to the viewport
(''fixed'') or scroll along with the element (''scroll'')
or its contents (''local''). The property's value is given as
a comma-separated list of <attachment> keywords where
Even if the image is fixed, it is still only visible when it is in
the background painting area of the element or otherwise
unclipped. (See “The backgrounds of
special elements” for the cases when background images are not
clipped.) Thus, unless the image is tiled, it may be invisible.
This example creates an infinite vertical band that remains
“glued” to the viewport when the element is scrolled.
User agents that do not support ''fixed'' backgrounds (for
example due to limitations of the hardware platform) should ignore
declarations with the keyword ''fixed''. For example:
See the section “Layering multiple background
images” for how 'background-attachment' interacts with other
comma-separated background properties to form each background image
layer.
If background images have been specified, this property specifies
their initial position (after any resizing)
within their corresponding background positioning area.
Where
If only one value is specified, the second value is assumed to be
''center''. If two values are given, a < Note that a pair of keywords can be reordered while
a combination of keyword and length or percentage cannot.
So ''center left'' is valid while ''50% left'' is not.
If three or four values are given, then
each < Positive values represent an offset inward from the edge of
the background positioning area. Negative values represent an offset
outward from the edge of the background positioning area.
The following declarations give the stated (horizontal, vertical)
offsets from the top left corner: A percentage for the horizontal offset is relative to (width of
background positioning area - width of background image).
A percentage for the vertical offset is relative to (height
of background
positioning area - height of background image), where the
size of the image is the size given by 'background-size'.
For example, with a value pair of ''0% 0%'', the upper left
corner of the image is aligned with the upper left corner of, usually,
the box's padding edge. A value pair of ''100% 100%'' places
the lower right corner of the image in the lower right corner of the
area. With a value pair of ''75% 50%'', the point 75% across
and 50% down the image is to be placed at the point 75% across and 50%
down the area.
Diagram of the meaning of ''background-position: 75% 50%''.
The following 'background' shorthand declarations use keywords
to set 'background-position' to the stated percentage values. In the example below, the (single) image is placed in the lower-right
corner of the viewport.
Background positions can also be relative to other corners than the
top left. E.g., the following puts the background image 10px from the
bottom and 3em from the right:
See the section “Layering multiple background
images” for how 'background-position' interacts with
other comma-separated background properties to form each background
image layer.
Determines the background painting area,
which determines the area within which the background is painted.
The syntax of the property is given with
Values have the following meanings:
Note that the root element has a different background
painting area, and thus the 'background-clip' property has no effect
when specified on it. See “The
backgrounds of special elements.”
Note that the background is always drawn behind
the border, if any. See “Elaborate description of Stacking Contexts” in
[[!CSS2]].
See the section on Corner Shaping
for how 'border-radius' affects the shape of the background painting area.
See the section “Layering multiple background
images” for how ''background-clip'' interacts with other
comma-separated background properties to form each background image
layer.
For elements rendered as a single box, specifies the
background positioning area.
For elements rendered as multiple boxes
(e.g., inline boxes on several lines, boxes on several pages),
specifies which boxes 'box-decoration-break' [[CSS3-BREAK]] operates on
to determine the background positioning area(s).
If the 'background-attachment' value for this image is
''fixed'', then this property has no effect: in this case the
background positioning area is the
initial containing block [[!CSS2]].
Note that if 'background-clip' is ''background-clip/padding-box'',
'background-origin' is ''background-origin/border-box'', 'background-position' is
''top left'' (the initial value), and the element has a
non-zero border, then the top and left of the background image will be
clipped.
See the section “Layering multiple background
images” for how ''background-origin'' interacts with other
comma-separated background properties to form each background image
layer.
Specifies the size of the background images. Where
Values have the following meanings:
The first value gives the width of the corresponding image,
the second value its height. If only one value is given the second
is assumed to be ''background-size/auto''.
A percentage is relative to the background positioning area.
An ''background-size/auto'' value for one dimension is resolved by using the
image's intrinsic ratio and the size of the other dimension, or
failing that, using the image's intrinsic size, or failing that,
treating it as 100%.
If both values are ''background-size/auto'' then the intrinsic width and/or
height of the image should be used, if any, the missing dimension
(if any) behaving as ''background-size/auto'' as described above. If the image has
neither an intrinsic width nor an intrinsic height, its size is
determined as for ''contain''.
Negative values are invalid.
Here are some examples. The first example stretches the background
image independently in both dimensions to completely cover the content
area:
The second example stretches the image so that exactly two copies
fit horizontally. The aspect ratio is preserved:
This example forces the background image to be 15 by 15 pixels:
This example uses the image's intrinsic size. Note that this is the
only possible behavior in CSS level 1 and 2.
The following example rounds the height of the image to 33.3%, up
from the specified value of 30%. At 30%, three images would fit
entirely and a fourth only partially. After rounding, three images
fit. The width of the image is 20% of the background positioning area width and is
not rounded.
If 'background-repeat' is ''background-repeat/round'' for one (or both) dimensions,
there is a second step. The UA must scale the image in that dimension
(or both dimensions) so that it fits a whole number of times in
the background positioning area. In the case of the width (height is
analogous):
If X ≠ 0 is the width of the image after step one
and W is the width of the background positioning area,
then the rounded width
X' = W / round(W / X)
where round() is a function that returns the nearest natural number
(integer greater than zero).
If 'background-repeat' is ''background-repeat/round'' for one dimension only and if
'background-size' is ''background-size/auto'' for the other dimension, then there is a third
step: that other dimension is scaled so that the original aspect ratio
is restored.
In this example the background image is shown at its intrinsic size:
In the following example, the background is shown with a width of
3em and its height is scaled proportionally to keep the original
aspect ratio:
In the following example, the background is shown with a width of
approximately 3em: scaled so that it fits a whole number of times in
the width of the background. The height is scaled proportionally to
keep the original aspect ratio:
In the following example, the background image is shown with a
width of 3em and a height that is either the height corresponding to
that width at the original aspect ratio or slightly less:
In the following example, the background image is shown with a
height of approximately 4em: scaled slightly so that it fits a whole
number of times in the background height. The width is the approximately
the width that correspond to a 4em height at the original aspect ratio:
scaled slightly so that it fits a whole number of times in the background
width.
If the background image's width or height resolves to zero, this
causes the image not to be displayed. (The effect is the same as
if it had been a transparent image.)
See the section “Layering multiple background
images” for how 'background-size' interacts with other
comma-separated background properties to form each background image
layer.
Where
Note that a color is permitted in
< The 'background' property is a
shorthand property for setting most background properties at the same
place in the style sheet. The number of comma-separated items defines
the number of background layers. Given a valid declaration, for each layer
the shorthand first sets the corresponding layer of each of
'background-image',
'background-position',
'background-size',
'background-repeat',
'background-origin',
'background-clip'
and 'background-attachment' to
that property's initial value, then assigns any explicit values specified
for this layer in the declaration. Finally 'background-color' is set to
the specified color, if any, else set to its initial value.
If one < In the first rule of the following example, only a value for
'background-color' has been given and the
other individual properties are set to their initial values. In the
second rule, many individual properties have been specified.
The first rule is equivalent to:
The second is equivalent to:
The following example shows how a both a background color (#CCC) and a background image (url(metal.jpg)) are set. The image is rescaled to
the full width of the element:
Another example shows equivalence:
The following declaration with multiple, comma-separated values
is equivalent to
The document canvas
is the infinite surface over which the document is rendered. [[!CSS2]]
Since no element corresponds to the canvas,
in order to allow styling of the canvas
CSS propagates the background of the root element
(or, in the case of HTML, the <body> element)
as described below.
However, if no boxes are generated for the element whose background
would be used for the canvas
(for example, if the root element has ''display: none''),
then the canvas background is transparent.
Note that an element might be invisible, but still generate boxes.
For example, if the element has ''visibility: hidden'' but not ''display: none'',
boxes are generated for it and its background is used for the canvas.
If the [=canvas background=] is not opaque,
the canvas surface below it shows through.
The texture of the [=canvas surface=] is UA-dependent
(but is typically an opaque white).
The background of the root element becomes the canvas background
and its background painting area extends
to cover the entire canvas.
However, any images are sized and positioned relative to the root element
as if they were painted for that element alone.
(In other words, the
background positioning area
is determined as for the root element.)
The root element does not paint this background again, i.e., the used
value of its background is transparent.
For documents whose root element is
an HTML According to these rules, the canvas underlying the following HTML
document will have a “marble” background:
The ''::first-line'' pseudo-element is like an inline-level element
for the purposes of the background (see section 5.12.1 of [[!CSS2]]).
That means, e.g., that in a left-justified first line, the background
does not necessarily extend all the way to the right margin.
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.
These properties set the foreground color of the border specified
by the border-style properties.
The 'border-color' property is a shorthand property for setting
'border-top-color', 'border-right-color', 'border-bottom-color', and 'border-left-color'
in a single declaration.
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
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 'border-style' property is a shorthand property for setting
'border-top-style', 'border-right-style', 'border-bottom-style', and 'border-left-style'
in a single declaration.
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
Where
Values have the following meanings:
Borders are drawn in front of the element's background, but behind
the element's content (in case it overlaps).
Example renderings of the predefined border styles.
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'', ''border-style/inset'', or ''border-style/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.
Note: This specification does not define how borders
of different styles should be joined in the corner. Also note that
rounded corners may cause the corners and the contents to overlap, if
the padding is less than the radius of the corner.
These properties set the thickness of the border.
Where
The lengths corresponding to thin, medium, and thick
are not specified, but the values are constant throughout a
document and thin ≤ medium ≤ thick. A UA could,
e.g., make the thickness depend on the ''medium'' font size: one
choice might be 1, 3 & 5px when the ''medium'' font size is 17px or
less. Negative values are invalid.
The 'border-width' property is a shorthand property for setting
'border-top-width', 'border-right-width', 'border-bottom-width', and 'border-left-width'
in a single declaration.
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
Note that the initial width is ''medium'', but the initial
style is ''border-style/none'' and therefore the used width is 0.
This is a shorthand property for setting the width, style, and
color of the top, right, bottom, and left border of a box. Omitted
values are set to their initial values.
The 'border' property is a shorthand property for setting the same width,
color, and 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.
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
For example, the first rule below is equivalent to the set of five
rules shown after it:
Since, to some extent, the properties have overlapping
functionality, the order in which the rules are specified is
important.
Consider this example:
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.
The two < The two values of
''border-top-left-radius: 55pt 25pt'' define the
curvature of the corner.
This example draws ovals of 15em wide and 10em high:
The 'border-radius' shorthand sets all four 'border-*-radius'
properties. If values are given before and after the slash, then
the values before the slash set the horizontal radius and the values
after the slash set the vertical radius. If there is no slash, then the
values set both radii equally. The four values for each radii are
given in the order top-left, top-right, bottom-right, bottom-left.
If bottom-left is omitted it is the same as top-right. If
bottom-right is omitted it is the same as top-left. If top-right is
omitted it is the same as top-left.
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 its center
might not coincide with that of the outer border 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'', ''border-style/inset'', etc.)
follow the curve of the border.
The effect of a rounded corner when the two borders
it connects are of unequal thickness (left) and the effect of a
rounded corner on borders that are thicker than the radius of the
corner (right).
Note that 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. Where the border-radius curve extends into the opposite
sides' borders, the arc of the padding edge is less than 90°.
The margin edge, being outside the border edge, calculates its radius
by adding the corresponding margin thickness to each border radius.
However, in order to create a sharper corner when the border radius is small
(and thus ensure continuity between round and sharp corners),
when the border radius is less than the margin,
the margin is multiplied by the proportion 1 + (r-1)3,
where r is the ratio of the border radius to the margin,
in calculating the corner radii of the margin box shape.
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,
[=replaced element=] content to the curved content edge,
pointer events to the curved border edge,
etc.
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.
This example adds appropriate padding, so that the
contents do not overflow the corners. Note that there is no border,
but the background will still have rounded corners.
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.
Given these corner shapes, color and style transitions
must be contained within the green region. In case D the rectangle
defined by the border radii does not include the center of the inner
curve (which is a sharp corner), so the transition region is expanded
to include that corner. Transitions may take up the entire transition
region, but are not required to: For example, a gradient color transition
between two solid border styles might take up only the region bounded
by the tips of the outer radii and the tips of the inner radii
(represented in case D by the dark green region).
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 that 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.
For example, the borders A of the figure below might be the
result of
The height (2.5em) is enough for the specified radii (0.5em plus
2.0em). However, if the height is only 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.
These rounded corner might be the result of 'width:
6em; height: 2.5em; border-radius: 0.5em 2em 0.5em 2em' for A; and
ditto but with 'height: 2em' for B.
The 'border-radius' properties do apply to
''display/table'', ''inline-table'', and ''table-cell'' boxes
in separated borders mode (''border-collapse: separate'').
When 'border-collapse' is ''border-collapse/collapse'', they have no effect.
Authors can specify an image to be used in place of the border styles.
In this case, the border's design is taken from the sides and corners
of an image specified with 'border-image-source', whose pieces may be
sliced, scaled and stretched in various ways to fit the size of the
border image area. The border-image properties do not affect layout:
layout of the box, its content, and surrounding content is based on
the 'border-width' and 'border-style' properties only.
This example creates a top and bottom border consisting of a whole
number of orange diamonds and a left and right border of a single,
stretched diamond. The corners are diamonds of a different color. The
image to tile is as follows. Apart from the diamonds, it is
transparent:
The image is 81 by 81 pixels and has to be divided into 9 equal
parts. The style rules could thus be as follows:
The result, when applied to a DIV of 12 by 5em, will be similar to
this:
This shows a more complicated example, demonstrating how the border
image corresponds to the fallback border-style but can also extend
beyond the border area. The border image is a wavy green border with
an extended corner effect: The 'border-image-source' image, with the four
'border-image-slice' cuts at 124px dividing the image into nine parts. The rest of the border properties then interact to lay out the
tiles as follows: Diagram of all border-image properties and how they
interact, and showing the rendering with and without the border-image
in effect. Here, even though the border-width is 12px, the 'border-image-width'
property computes to 124px. The border-image area is then outset 31px
from the border-box and into the margin area. If the border-image fails
to load (or border images are not supported by the UA), the fallback
rendering uses a green double border.
Notice that the 'border' shorthand resets 'border-image'. This makes
it easy to turn off or reset all border effects: Specifies an image to use in place of the rendering specified by the 'border-style' properties
and, if given the ''fill'' keyword in 'border-image-slice', as an additional image backdrop for the element.
If the value is ''border-image-source/none'' or if the image cannot be displayed
(or the property doesn't apply), the border styles will be used;
otherwise the element's 'border-style' borders are not drawn
and the border image is drawn as described in the sections below.
This property specifies inward offsets from the top, right, bottom,
and left edges of the image, dividing it into nine regions: four corners,
four edges and a middle.
The middle image part is discarded (treated as fully transparent)
unless the ''fill'' keyword is present. (It is drawn over the background;
see Drawing the Border Image.)
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
Negative values are invalid.
Computed values larger than the size of the image are interpreted as ''100%''.
The regions given by the 'border-image-slice' values may overlap.
However if the sum of the right and left widths is equal to or
greater than the width of the image, the images for the top and
bottom edge and the middle part are empty, which has the same effect
as if a nonempty transparent image had been specified for those
parts. Analogously for the top and bottom values.
If the image must be sized to determine the slices
(for example, for SVG images with no intrinsic size),
then it is sized using the default sizing algorithm
with no specified size and the border image area as the default object size.
Diagram illustrating the cuts corresponding to the
value ''25% 30% 12% 20%''
The border image is drawn inside an area called the
border image area. This is an area whose boundaries
by default correspond to the border box, see 'border-image-outset'.
The four values of 'border-image-width' specify offsets that are used
to divide the border image area into nine parts. They represent inward
distances from the the top, right, bottom, and left sides of the
area, respectively.
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
Values have the following meanings: Negative values are invalid for any 'border-image-width' values.
If two opposite 'border-image-width' offsets are large enough that
they overlap, then the used values of all 'border-image-width' offsets
are proportionally reduced until they no longer overlap. In mathematical
notation: Given Lwidth as the width of the border
image area, Lheight as its height, and
Wside as the border image width offset
for the side side, let f =
min(Lwidth/(Wleft+Wright),
Lheight/(Wtop+Wbottom)).
If f < 1, then all W are reduced by multiplying
them by f.
The values specify the amount by which the border image area extends beyond the border box.
If there is only one component value,
it applies to all sides.
If there are two values,
the top and bottom are set to the first value
and the right and left are set to the second.
If there are three values,
the top is set to the first value,
the left and right are set to the second,
and the bottom is set to the third.
If there are four values
they apply to the top, right, bottom, and left, respectively.
Negative values are invalid.
Portions of the border-image that are rendered outside the border
box do not trigger scrolling. Also such portions are invisible to mouse
events and do not capture such events on behalf of the element. Note that, even though they never cause a scrolling
mechanism, outset images may still be clipped by an ancestor or by the
viewport.
This property specifies how the images for the sides and the middle
part of the border image are scaled and tiled.
The first keyword applies to the horizontal scaling and tiling
of the top, middle and bottom parts,
the second to the vertical scaling and tiling
of the left, middle and right parts;
see Drawing the Border Image.
If the second keyword is absent, it is assumed to be the same as the first.
Values have the following meanings:
The exact process for scaling and tiling the border-image parts is
given in the section below. After the border-image given by 'border-image-source' is sliced by
the 'border-image-slice' values, the resulting nine images are scaled,
positioned, and tiled into their corresponding border image regions
in four steps:
The two images for the top and bottom edges are made as tall
as the top and bottom border image area parts, respectively, and
their width is scaled proportionally.
The images for the left and right edge are made as wide as the
left and right border image area parts, respectively, and their
height is scaled proportionally.
The corner images are scaled to be as wide and as tall as the
two border-image edges they are part of.
The middle image's width is scaled by the same factor as the top
image unless that factor is zero or infinity, in which case the scaling
factor of the bottom is substituted, and failing that, the width is not
scaled. The height of the middle image is scaled by the same factor as
the left image unless that factor is zero or infinity, in which case the
scaling factor of the right image is substituted, and failing that, the
height is not scaled. If the first keyword is ''border-image-repeat/stretch'', the top, middle and bottom
images are further scaled to be as wide as the middle part of the
border image area. The height is not changed any further.
If the first keyword is ''border-image-repeat/round'', the top, middle and bottom
images are resized in width, so that exactly a whole number of them
fit in the middle part of the border-image area, exactly as for
''background-repeat/round'' in the 'background-repeat' property.
If the first keyword is ''border-image-repeat/repeat'' or ''border-image-repeat/space'', the top, middle,
and bottom images are not changed any further.
The effects of ''border-image-repeat/stretch'', ''border-image-repeat/round'', ''border-image-repeat/repeat'', and ''border-image-repeat/space''
for the second keyword are analogous, acting on the height of the left,
middle and right images.
If the first keyword is ''border-image-repeat/repeat'', the top, middle, and bottom
images are centered horizontally in their respective areas. Otherwise
the images are placed at the left edge of their respective parts
of the border-image area.
If the second keyword is ''border-image-repeat/repeat'', the left, middle, and right
images are centered vertically in their respective areas. Otherwise
the images are placed at the top edge of their respective parts
of the border-image area.
The images are then tiled to fill their respective areas.
In the case of ''border-image-repeat/space'', any partial tiles are discarded and
the extra space distributed before, after, and between the tiles.
(I.e. the gap before the first tile, the gap after the last tile,
and the gaps between tiles are equalized.)
This can result in empty border-image side areas.
The images are drawn at the same stacking level as normal borders:
immediately in front of the background layers.
The middle image is not drawn unless ''fill'' was specified for 'border-image-source'.
This is a shorthand property for setting 'border-image-source',
'border-image-slice', 'border-image-width', 'border-image-outset' and
'border-image-repeat'. Omitted values are set to their initial values.
The 'border-image' properties apply to the border of tables and
inline tables that have 'border-collapse' set to
''border-collapse/collapse''. However, this specification does not define how such an
image border is rendered. In particular, it does not define how the
image border interacts with the borders of cells, rows and row groups
at the edges of the table
(see border conflict resolution in [[!CSS2]]).
It is expected that a future specification will define the
rendering. It is recommended that UAs do not apply border images to
tables with collapsed borders until then.
The 'box-decoration-break' property,
which defines how backgrounds and borders apply to a fragmented box,
has been moved to the CSS Fragmentation Module. [[CSS3-BREAK]]
The 'box-shadow' property attaches one or more drop-shadows to the box.
The property accepts either
the none value, which indicates no shadows,
or a comma-separated list of shadows, ordered front to back.
Each shadow is given as a < The components of each < Note that for inner shadows,
expanding the shadow (creating more shadow area)
means contracting the shadow’s perimeter shape.
The example below demonstrates the effects of spread and blur on the shadow:
An outer box-shadow casts a shadow as if the border-box of the element were opaque.
Assuming a spread distance of zero, its perimeter has the exact same size and shape as the border box.
The shadow is drawn outside the border edge only:
it is clipped inside the border-box of the element.
An inner box-shadow casts a shadow as if everything outside the padding edge were opaque.
Assuming a spread distance of zero, its perimeter has the exact same size and shape as the padding box.
The shadow is drawn inside the padding edge only:
it is clipped outside the padding box of the element.
If a spread distance is defined, the shadow perimenter defined above
is expanded outward (for outer box-shadows) or contracted inward (for inner box-shadows)
by outsetting (insetting, for inner shadows) the shadow's straight edges by the spread distance
(and flooring the resulting width/height at zero).
Below are some examples of an orange box with a blue border being
given a drop shadow. To preserve the box's shape when spread is applied,
the corner radii of the shadow are also increased (decreased, for inner shadows)
from the border-box radii by adding (subtracting)
the spread distance (and flooring at zero).
However, in order to create a sharper corner when the border radius is small
(and thus ensure continuity between round and sharp corners),
when the border radius is less than the spread distance
(or in the case of an inner shadow,
less than the absolute value of a negative spread distance),
the spread distance
is multiplied by the proportion 1 + (r-1)3,
where r is the ratio of the border radius to the spread distance,
in calculating the corner radii of the spread shadow shape.
For example, if the border radius is 10px and the spread distance is 20px (r = .5),
the corner radius of the shadow shape will be 10px + 20px × (1 + (.5 - 1)3) = 27.5px.
This adjustment is applied independently to the radii in each dimension.
The 'border-image' does not affect the shape of the box-shadow.
A non-zero blur radius indicates that the resulting shadow should
be blurred, such as by a Gaussian filter. The exact algorithm is not
defined; however the resulting shadow must approximate (with each pixel
being within 5% of its expected value) the image that would be generated
by applying to the shadow a Gaussian blur with a standard deviation equal
to half the blur radius
Note this means for a long, straight shadow edge, the
blur radius will create a visibly apparent color transition approximately
the twice length of the blur radius that is perpendicular to and centered
on the shadow's edge, and that ranges from almost the full shadow color at the
endpoint inside the shadow to almost fully transparent at the endpoint outside it.
The shadow effects are applied front-to-back:
the first shadow is on top and the others are layered behind.
Shadows do not influence layout and may overlap (or be overlapped by)
other boxes and text or their shadows.
In terms of stacking contexts and the painting order,
the outer box-shadows of an element are drawn immediately below the background of that element,
and the inner shadows of an element are drawn immediately above the background of that element
(below the borders and border image, if any).
If an element has multiple boxes, all of them get drop shadows,
but shadows are only drawn where borders would also be drawn;
see 'box-decoration-break'.
Shadows do not trigger scrolling or increase the size of the scrollable area.
Outer shadows have no effect on internal table elements in the collapsing border model.
If a shadow is defined for single border edge in the collapsing border model
that has multiple border thicknesses
(e.g. an outer shadow on a table where one row has thicker borders than the others,
or an inner shadow on a rowspanning table cell that adjoins cells with different border thicknesses),
the exact position and rendering of its shadows are undefined
The following terms and abbreviations are used in this
module.
A program that reads and/or writes CSS style sheets on behalf of a
user in either or both of these categories: programs whose purpose is
to render documents (e.g., browsers) and
programs whose purpose is to create style sheets (e.g., editors). A UA
may fall into both categories. (There are other programs that read or
write style sheets, but this module gives no rules for them.)
A tree-structured document with elements and attributes, such as an
SGML or XML document [[XML11]].
This section is informative. CSS has different levels of
features, each a subset of the other.
(See [[CSS-2017]] for a full explanation.)
The lists below describe which features from this specification are in each level.
To preserve the box's shape when spread is applied,
the corner radii of the shadow are also increased (decreased, for inner shadows)
from the border-box radii by adding (subtracting)
the spread distance (and flooring at zero).
However, in order to create a sharper corner when the border radius is small
(and thus ensure continuity between round and sharp corners),
when the border radius is less than the spread distance
(or in the case of an inner shadow,
less than the absolute value of a negative spread distance),
the spread distance
is multiplied by the proportion 1 + (r-1)3,
where r is the ratio of the border radius to the spread distance,
in calculating the corner radii of the spread shadow shape.
If the color is absent, it defaults to ''currentColor''
The following (non-trivial) changes were made to this specification since the
9 September 2014 Candidate Recommendation:
The following (non-trivial) changes were made to this specification since the
4 February 2014 Last Call Working Draft:
A full Disposition of Comments is available.
The following (non-trivial) changes were made to this specification since the
24 July 2012 Candidate Recommendation:
The following (non-editorial) changes were made to this specification since the
17
April 2012 Candidate Recommendation:
The following (non-editorial) changes were made to this
specification since the 14 February 2012 “Last Call” Working Draft:
These changes were in response to comments received during the
review period. For details, see the full Disposition of Comments.
The following changes were made to this specification since the
15 February 2011
Candidate Recommendation:
If both values are ''background-size/auto'' then the intrinsic width and/or
height of the image should be used, if any, the missing
dimension (if any) behaving as ‘auto’ as described above.
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
must be proportional to the ratio of the border widths such that a
function of its location is continuous with respect to this ratio.
However it is not defined what these transitions look like or how
“proportional” maps to a point on the curve.
If the image must be sized to determine the slices (for
example, for SVG images with no intrinsic size), then it is sized
as for an auto-sized background, using the border image area as
the default object size in place of the background positioning
area.
UAs may also apply ‘box-decoration-break’ to control
rendering at bidi-imposed breaks, i.e. when bidi reordering causes
an inline to split into non-contiguous fragments. Otherwise such
breaks are always handled as ‘slice’.
The color is the color of the shadow. If the color is
absent, the used color is taken from the ‘color’ property.
Changed [ stretch | repeat | round | space ]{1,2}
The height (2.5em) is enough for the specified radii (0.5em
plus The following changes were made to this specification since the
17 December 2009
Candidate Recommendation:
Tapas Roy was editor of the Border Module, before it was merged
with the Background Module.
Thanks to Ben Stucki for defining what happens with rounded corners
if the two adjoining borders are of unequal thickness or one of them
is zero; to Arjan Eising and Anne van Kesteren for the 'border-radius'
syntax; to Zack Weinberg for the corner transition regions diagram;
and to Lea Verou, plinss, and dbaron for the corner radius adjustment formula
(with special thanks to Lea for the live demo).
A set of properties for border images was initially proposed by
fantasai. The current simplification (one image cut into nine
parts) is due to Ian Hickson. (Though the original idea seems to
originate with some anonymous Microsoft engineers.)
Finally, special thanks go to Brad Kemper for his feedback and
suggestions for many of the features in the draft, for drawing all
the box-shadow examples, and for proposing some
radical changes
to the 'border-image' property that solved a number of problems with
the earlier definition.
body {
background: white url("pendant.png");
background-repeat: repeat-y;
background-position: center;
}
body {
background-image: url(dot.png) white;
background-repeat: space
}
Affixing Images: the 'background-attachment' property
Name:
background-attachment
Value:
<
Initial:
scroll
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
list, each item the keyword as specified
Animation type:
discrete
<
body {
background: red url("pendant.gif");
background-repeat: repeat-y;
background-attachment: fixed;
}
body {
/* For all UAs: */
background: white url(paper.png) scroll;
/* For UAs that do fixed backgrounds: */
background: white url(ledger.png) fixed;
}
h1 {
/* For all UAs: */
background: silver;
/* For UAs that do fixed backgrounds: */
background: url(stripe.png) fixed, white url(ledger.png) fixed;
}
Positioning Images: the 'background-position' property
Name:
background-position
Value:
<
Initial:
0% 0%
Applies to:
all elements
Inherited:
no
Percentages:
refer to size of background positioning
area minus size of background image; see text
Computed value:
list, each item
a pair of offsets (horizontal and vertical) from the top left origin
each given as a computed <
Animation type:
repeatable list
<
background-position: left 10px top 15px; /* 10px, 15px */
background-position: left top ; /* 0px, 0px */
background-position: 10px 15px; /* 10px, 15px */
background-position: left 15px; /* 0px, 15px */
background-position: 10px top ; /* 10px, 0px */
background-position: left top 15px; /* 0px, 15px */
background-position: left 10px top ; /* 10px, 0px */
body { background: url("banner.jpeg") right top } /* 100% 0% */
body { background: url("banner.jpeg") top center } /* 50% 0% */
body { background: url("banner.jpeg") center } /* 50% 50% */
body { background: url("banner.jpeg") bottom } /* 50% 100% */
body {
background-image: url("logo.png");
background-attachment: fixed;
background-position: 100% 100%;
background-repeat: no-repeat;
}
background-position: right 3em bottom 10px
Painting Area: the 'background-clip' property
Name:
background-clip
Value:
<
Initial:
border-box
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
list, each item a keyword as specified
Animation type:
repeatable list
<
Positioning Area: the 'background-origin' property
Name:
background-origin
Value:
<
Initial:
padding-box
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
list, each item a keyword as specified
Animation type:
repeatable list
Sizing Images: the 'background-size' property
Name:
background-size
Value:
<
Initial:
auto
Applies to:
all elements
Inherited:
no
Percentages:
see text
Computed value:
list, each item a pair of sizes (one per axis)
each represented as either a keyword or a computed <
Animation type:
repeatable list
<
div {
background-image: url(plasma.png);
background-repeat: no-repeat;
background-size: 100% 100%;
background-origin: content-box }
p {
background-image: url(tubes.png);
background-size: 50% auto;
background-origin: border-box }
para {
background-size: 15px 15px;
background-image: url(tile.png)}
body {
background-size: auto; /* default */
background-image: url(flower.png) }
p {
background-image: url(chain.png);
background-repeat: no-repeat round;
background-size: 20% 30% }
div {
background-image: url(image1.png);
background-repeat: repeat; /* default */
background-size: auto } /* default */
div {
background-image: url(image2.png);
background-repeat: repeat; /* default */
background-size: 3em } /* = '3em auto' */
div {
background-image: url(image3.png);
background-repeat: round repeat;
background-size: 3em auto }
div {
background-image: url(image4.png);
background-repeat: repeat round;
background-size: 3em auto }
div {
background-image: url(image5.png);
background-repeat: round;
background-size: auto 4em }
Backgrounds Shorthand: the 'background' property
Name:
background
Value:
[<
Initial:
see individual properties
Applies to:
all elements
Inherited:
no
Percentages:
see individual properties
Computed value:
see individual properties
Animation type:
see individual properties
<
<
body { background: red }
p { background: url("chess.png") 40% / 10em gray
round fixed border-box; }
body {
background-color: red;
background-position: 0% 0%;
background-size: auto;
background-repeat: repeat;
background-clip: border-box;
background-origin: padding-box;
background-attachment: scroll;
background-image: none }
p {
background-color: gray;
background-position: 40% 50%;
background-size: 10em auto;
background-repeat: round;
background-clip: border-box;
background-origin: border-box;
background-attachment: fixed;
background-image: url(chess.png) }
E { background: #CCC url("metal.jpg") top left / 100% auto no-repeat}
div { background: padding-box url(paper.jpg) white center }
div {
background-color: white;
background-image: url(paper.jpg);
background-repeat: repeat;
background-attachment: scroll;
background-position: center;
background-clip: padding-box;
background-origin: padding-box;
background-size: auto auto }
background: url(a.png) top left no-repeat,
url(b.png) center / 100% 100% no-repeat,
url(c.png) white;
background-image: url(a.png), url(b.png), url(c.png);
background-position: top left, center, top left;
background-repeat: no-repeat, no-repeat, repeat;
background-clip: border-box, border-box, border-box;
background-origin: padding-box, padding-box, padding-box;
background-size: auto auto, 100% 100%, auto auto;
background-attachment: scroll, scroll, scroll;
background-color: white;
Backgrounds of Special Elements
The Canvas Background and the Root Element
The Canvas Background and the HTML <body> Element
HTML
element
or an XHTML html
element [[!HTML]]:
if the computed
value of 'background-image' on the root element is ''background-image/none'' and its
'background-color' is ''transparent'', user agents must instead propagate
the computed values of the background properties from that element's first
HTML BODY
or XHTML body
child element. The used values of that BODY
element's
background properties are their initial values, and the propagated values
are treated as if they were specified on the root element.
It is recommended that authors of HTML documents specify the canvas background
for the BODY
element rather than the
HTML
element.
<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.0//EN'
>
<html>
<head>
<title>Setting the canvas background</title>
<style type="text/css">
body { background: url("http://example.org/marble.png") }
</style>
</head>
<body>
<p>My background is marble.</p>
</body>
</html>
The ''::first-line'' Pseudo-element‘s Background
Borders
Line Colors: the 'border-color' properties
Name:
border-top-color ,
border-right-color,
border-bottom-color,
border-left-color
Value:
<
Initial:
currentColor
Applies to:
all elements except [=ruby base containers=] and [=ruby annotation containers=]
Inherited:
no
Percentages:
N/A
Computed value:
computed color
Animation type:
by computed value
Name:
border-color
Value:
<
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
Animatable:
see individual properties
Line Patterns: the 'border-style' properties
Name:
border-top-style,
border-right-style,
border-bottom-style,
border-left-style
Value:
<
Initial:
none
Applies to:
all elements except [=ruby base containers=] and [=ruby annotation containers=]
Inherited:
no
Percentages:
N/A
Computed value:
specified keyword
Animation type:
discrete
Name:
border-style
Value:
<
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
<
Line Thickness: the 'border-width' properties
Name:
border-top-width, border-right-width,
border-bottom-width, border-left-width
Value:
<
Initial:
medium
Applies to:
all elements except [=ruby base containers=] and [=ruby annotation containers=]
Inherited:
no
Percentages:
N/A
Computed value:
absolute length; zero if the border style is ''border-style/none'' or ''hidden''
Animatable:
by computed value
Name:
border-width
Value:
<
Initial:
(see individual properties)
Applies to:
all elements except [=ruby base containers=] and [=ruby annotation containers=]
Inherited:
no
Percentages:
see individual properties
Computed value:
see individual properties
Animatable:
see individual properties
<
Border Shorthand Properties
Name:
border-top,
border-right,
border-bottom,
border-left
Value:
<
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
Animatable:
see individual properties
Name:
border
Value:
<
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
Animatable:
see individual properties
p { border: solid red }
p {
border-top: solid red;
border-right: solid red;
border-bottom: solid red;
border-left: solid red;
border-image: none;
}
blockquote {
border-color: red;
border-left: double;
color: black
}
Rounded Corners
Curve Radii: the 'border-radius' properties
Name:
border-top-left-radius,
border-top-right-radius,
border-bottom-right-radius,
border-bottom-left-radius
Value:
<
Initial:
0
Applies to:
all elements (but see prose)
Inherited:
no
Percentages:
Refer to corresponding dimension of the
border box.
Computed value:
pair of computed <
Animatable:
by computed value
Name:
border-radius
Value:
<
Initial:
see individual properties
Applies to:
all elements (but see prose)
Inherited:
no
Percentages:
Refer to corresponding dimension of the
border box.
Computed value:
see individual properties
Animatable:
see individual properties
DIV.standout {
width: 13em;
height: 8em;
border: solid black 1em;
border-radius: 7.5em 5em }
border-radius: 4em;
is equivalent to
border-top-left-radius: 4em;
border-top-right-radius: 4em;
border-bottom-right-radius: 4em;
border-bottom-left-radius: 4em;
and
border-radius: 2em 1em 4em / 0.5em 3em;
is equivalent to
border-top-left-radius: 2em 0.5em;
border-top-right-radius: 1em 3em;
border-bottom-right-radius: 4em 0.5em;
border-bottom-left-radius: 1em 3em;
Corner Shaping
p { width: 70px; height: 70px; border: solid 30px;
border-color: orange orange silver silver;
border-top-right-radius: 100%; }
Corner Clipping
DIV {
background: black;
color: white;
border-radius: 1em;
padding: 1em }
Color and Style Transitions
Overlapping Curves
box-sizing: border-box;
width: 6em;
height: 2.5em;
border-radius: 0.5em 2em 0.5em 2em
box-sizing: border-box;
width: 6em;
height: 2em;
border-radius: 0.5em 2em 0.5em 2em
Effect on Tables
Border Images
DIV {
border: double orange 1em;
border-image: url("border.png") 27 round stretch;
}
.notebox {
border: double orange;
/* must set 'border' shorthand first, otherwise it erases 'border-image' */
border-image: url("border.png") 30 round;
/* but other 'border' properties can be set after */
border-width: thin thick;
}
...
.sidebar .notebox {
box-shadow: 0 0 5px gray;
border-radius: 5px;
border: none; /* turn off all borders */
/* 'border' shorthand resets 'border-image' */
}
Image Source: the 'border-image-source' property
Name:
border-image-source
Value:
none | <
Initial:
none
Applies to:
All elements, except internal table elements when 'border-collapse' is
''border-collapse/collapse''
Inherited:
no
Percentages:
N/A
Computed value:
the keyword ''border-image-source/none'' or the computed <
Animation type:
discrete
Image Slicing: the 'border-image-slice' property
Name:
border-image-slice
Value:
[<
Initial:
100%
Applies to:
All elements, except internal table elements when 'border-collapse' is
''border-collapse/collapse''
Inherited:
no
Percentages:
refer to size of the border image
Computed value:
four values, each either a number or percentage; plus a ''fill'' keyword if specified
Animation type:
by computed value
Drawing Areas: the 'border-image-width' property
Name:
border-image-width
Value:
[ <
Initial:
1
Applies to:
All elements, except internal table elements when 'border-collapse' is
''border-collapse/collapse''
Inherited:
no
Percentages:
Relative to width/height of the border image area
Computed value:
four values, each either a number, the keyword ''border-image-width/auto'', or a computed <
Animation type:
by computed value
Edge Overhang: the 'border-image-outset' property
Name:
border-image-outset
Value:
[ <
Initial:
0
Applies to:
All elements, except internal table elements when 'border-collapse' is
''border-collapse/collapse''
Inherited:
no
Percentages:
N/A
Computed value:
four values, each a number or absolute length
Animation type:
by computed value
Image Tiling: the 'border-image-repeat' property
Name:
border-image-repeat
Value:
[ stretch | repeat | round | space ]{1,2}
Initial:
stretch
Applies to:
All elements, except internal table elements when 'border-collapse' is
''border-collapse/collapse''
Inherited:
no
Percentages:
N/A
Computed value:
two keywords, one per axis
Animation type:
discrete
Drawing the Border Image
Border Image Shorthand: the 'border-image' property
Name:
border-image
Value:
<<'border-image-source'>>
|| <<'border-image-slice'>>
[ / <<'border-image-width'>> |
/ <<'border-image-width'>>? / <<'border-image-outset'>> ]?
|| <<'border-image-repeat'>>
Initial:
See individual properties
Applies to:
See individual properties
Inherited:
no
Percentages:
N/A
Computed value:
See individual properties
Animatable:
See individual properties
Effect on Tables
Miscellaneous Effects
Drop Shadows: the 'box-shadow' property
Name:
box-shadow
Value:
none | <
Initial:
none
Applies to:
all elements
Inherited:
no
Percentages:
N/A
Computed value:
either the keyword ''box-shadow/none'' or
a list, each item consisting of four absolute lengths
plus a computed color and optionally also a ''box-shadow/inset'' keyword
Animation type:
by computed value,
treating ''box-shadow/none'' as a zero-item list
and appending blank shadows (''transparent 0 0 0 0'')
with a corresponding ''box-shadow/inset'' keyword as needed
to match the longer list
if the the shorter list is otherwise compatible with the longer one
<
width: 100px; height: 100px;
border: 12px solid blue; background-color: orange;
border-top-left-radius: 60px 90px;
border-bottom-right-radius: 60px 90px;
box-shadow: 64px 64px 12px 40px rgba(0,0,0,0.4),
12px 12px 0px 8px rgba(0,0,0,0.4) inset;
Shadow Shape, Spread, and Knockout
border:5px solid blue;
background-color:orange;
width: 144px;
height: 144px;
border-radius: 20px;
border-radius: 0;
box-shadow:
rgba(0,0,0,0.4)
10px 10px;
box-shadow:
rgba(0,0,0,0.4)
10px 10px
inset
box-shadow:
rgba(0,0,0,0.4)
10px 10px 0
10px /* spread */
box-shadow:
rgba(0,0,0,0.4)
10px 10px 0
10px /* spread */
inset
Blurring Shadow Edges
Layering, Layout, and Other Details
Definitions
Glossary
Levels
Level 1
Level 2
Level 3
Changes
Changes since the 17 October 2017 Candidate Recommendation
<
inset<<inset?
the used color is taken from the 'color' property.
Changes since the 9 September 2014 Candidate Recommendation
Changes since the 4 February 2014 Last Call Working Draft
Changes since the 24 July 2012 Candidate Recommendation
Changes since the 17 April 2012 Candidate Recommendation
Changes since the 14 February 2012 “Last Call” Working Draft
Changes Since the 15 February 2011 Candidate Recommendation
The center of color and style transitions between
adjoining borders is at the point on the curve that is at an angle
that is proportional to the ratio of the border widths. For
example, if the top and right border widths are equal, that point
is at a 45° angle from the horizontal, and if the top is twice the
width of the right the point is at a 30° angle from the
horizontal. The line demarcating this transition is drawn between
the point at that angle on the outer arc and the point at that
angle on the inner arc.
If one or two values are specified, for a <length> the
absolute length, otherwise a percentage. If three or four values
are specified, two pairs of a keyword plus a length or
percentage. Two keywords representing the origin and
two offsets from that origin, each given as an absolute length (if
given a <Equivalent to Computes in
definition of keywords.
bg-position<position> = [
[ left | center | right | top | bottom | <?
|
[ center | [ left | right ] <
2.5em 2.0em).
Changes Since the 17 December 2009 Candidate Recommendation
Acknowledgments