Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
CSS is a language for describing the rendering of structured documents (such as HTML and XML) on screen, on paper, in speech, etc. This draft contains the features of CSS level 3 relating to borders and backgrounds. It includes and extends the functionality of CSS level 2 [CSS21], which builds on CSS level 1 [CSS1]. The main extensions compared to level 2 are borders consisting of images, boxes with multiple backgrounds, boxes with rounded corners and boxes with shadows.
This module replaces two earlier drafts: CSS3 Backgrounds and CSS3 Border.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This document was produced by the CSS Working Group as a Candidate Recommendation.
A Candidate Recommendation is a document that has been widely reviewed and is ready for implementation. W3C encourages everybody to implement this specification and return comments to the (archived) public mailing list [email protected] (see instructions). When sending e-mail, please put the text âcss3-backgroundâ in the subject, preferably like this: â[css3-background] â¦summary of commentâ¦â
Publication as a Candidate Recommendation does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
The following features are at-risk and may be dropped at the end of the
CR period if there has not been enough interest from implementers: âbox-decoration-break
â, animatability of âbox-shadow
â
The CSS WG maintains an issues list for this module. A test suite and implementation report for CSS Backgrounds and Borders Level 3 will be developed during the Candidate Recommendation phase, which will last a minimum of three months, and at least until 25 July 2012. See the section âCR exit criteriaâ for more details.
The changes to this specification since the previous drafts are listed in the âChangesâ section.
background-color
â
property
background-image
â
property
background-repeat
â property
background-attachment
â property
background-position
â property
background-clip
â property
background-origin
â property
background-size
â
property
background
â
property
border-image-source
â property
border-image-slice
â property
border-image-width
â property
border-image-outset
â property
border-image-repeat
â property
border-image
â
property
This subsection is not normative.
When elements are rendered according to the CSS box model [CSS21], 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 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
â 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 [CSS21].
This specification follows the CSS property definition conventions from [CSS21].
This module replaces and extends the background and border features defined in [CSS21] 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
. [CSS21]
The <image> value type is
defined by this specification as <image> =
<uri>
. Other value types are defined in CSS
Level 2 Revision 1 [CSS21]. Other CSS modules may expand
the definitions of these value types: for example [CSS3COLOR], when combined with
this module, expands the definition of the <color> value type as
used in this specification. Similarly, [CSS3-IMAGES], when combined
with this module, expands the definition of <image> as used in this
specification.
In addition to the property-specific values listed in their definitions, all properties defined in this specification also accept the inherit keyword as their property value. For readability it has not been repeated explicitly.
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 if the property can be animated or not.
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 â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.
background-color
â propertyName: | background-color |
---|---|
Value: | <color> |
Initial: | transparent |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | the computed color(s) |
Animatable: | yes |
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.
background-image
â propertyName: | background-image |
---|---|
Value: | <bg-image> [ , <bg-image> ]* |
Initial: | none |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified, but with URIs made absolute |
Animatable: | no |
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
<bg-image> = <image> | 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).
background-repeat
â propertyName: | background-repeat |
---|---|
Value: | <repeat-style> [ , <repeat-style> ]* |
Initial: | repeat |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | A list, each item consisting of: two keywords, one per dimension |
Animatable: | no |
Specifies how background images are tiled after they have been sized and positioned. Where
<repeat-style> = repeat-x | repeat-y | [repeat | space | round | no-repeat]{1,2}
Single values for <repeat-style> have the following meanings:
repeat-x
â
repeat no-repeat
â.
repeat-y
â
no-repeat repeat
â.
repeat
â
repeat repeat
â.
space
â
space space
â
round
â
round round
â
no-repeat
â
no-repeat no-repeat
â
If a <repeat-style> value has two keywords, the first one is for the horizontal direction, the second for the vertical one, as follows:
repeat
â
space
â
background-position
â for this direction is
ignored, unless there is not enough space for two copies of the image in
this direction, in which case only one image is placed and âbackground-position
â determines its position
in this direction.
round
â
background-size
â. If the background
painting area is larger than the background positioning area, then
the pattern repeats to fill the background painting area.
no-repeat
â
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.
body { background: white url("pendant.png"); background-repeat: repeat-y; background-position: center; }
body { background-image: url(dot.png) white; background-repeat: space }
See the section âLayering multiple background
imagesâ for how âbackground-repeat
â interacts with other
comma-separated background properties to form each background image layer.
background-attachment
â propertyName: | background-attachment |
---|---|
Value: | <attachment> [ , <attachment> ]* |
Initial: | scroll |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
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
<attachment> = scroll | fixed | local
fixed
â background is fixed with respect to the page box and
therefore replicated on every page. Note that there is
only one viewport per view. Even if an element has a scrolling mechanism
(see the âoverflow
â property [CSS21]), a âfixed
â background doesn't
move with the element.
border-box
â value of âbackground-clip
â as âpadding-box
â in cases where âbackground-attachment
â is âlocal
â and the contents of
the element scroll.
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.
body { background: red url("pendant.gif"); background-repeat: repeat-y; background-attachment: fixed; }
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:
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; }
See the section âLayering multiple background
imagesâ for how âbackground-attachment
â interacts with other
comma-separated background properties to form each background image layer.
background-position
â propertyName: | background-position |
---|---|
Value: | <position> [ , <position> ]* |
Initial: | 0% 0% |
Applies to: | all elements |
Inherited: | no |
Percentages: | refer to size of background positioning area minus size of background image; see text |
Media: | visual |
Computed value: | A list, each item consisting of: two keywords representing the origin and two offsets from that origin, each given as an absolute length (if given a <length>), otherwise as a percentage. |
Animatable: | yes |
If background images have been specified, this property specifies their initial position (after any resizing) within their corresponding background positioning area.
Where
<position> = [ [ left | center | right | top | bottom | <percentage> | <length> ] | [ left | center | right | <percentage> | <length> ] [ top | center | bottom | <percentage> | <length> ] | [ center | [ left | right ] [ <percentage> | <length> ]? ] && [ center | [ top | bottom ] [ <percentage> | <length> ]? ] ]
If only one value is specified, the second value is assumed to be
âcenter
â. If two values are given, a length or
percentage as the first value represents the horizontal position (or
offset) and a length or percentage as the second value represents the
vertical position (or offset). <percentage> and
<length> values here represent an offset of the top left
corner of the background image from the top left corner of the background
positioning area.
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
<percentage> or<length> represents an
offset and must be preceded by a keyword, which specifies from which edge
the offset is given. For example, âbackground-position:
bottom 10px right 20px
â represents a â10px
â vertical offset up from the bottom edge and a
â20px
â horizontal offset leftward from the
right edge. If three values are given, the missing offset is assumed to be
zero.
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:
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 */
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.
2cm 1cm
â, the upper left corner
of the image is placed 2cm to the right and 1cm below the upper left
corner of the background positioning area.
top
â
0%
â for the vertical position
if one or two values are given, otherwise specifies the top edge as the
origin for the next offset.
right
â
100%
â for the horizontal
position if one or two values are given, otherwise specifies the right
edge as the origin for the next offset.
bottom
â
100%
â for the vertical
position if one or two values are given, otherwise specifies the bottom
edge as the origin for the next offset.
left
â
0%
â for the horizontal
position if one or two values are given, otherwise specifies the left
edge as the origin for the next offset.
center
â
50%
â (âleft
50%
â) for the horizontal position if the horizontal position is
not otherwise specified, or â50%
â (âtop 50%
â) for the vertical position if it is.
The following âbackground
â shorthand declarations use
keywords to set âbackground-position
â to the stated percentage
values.
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% */
In the example below, the (single) image is placed in the lower-right corner of the viewport.
body { background-image: url("logo.png"); background-attachment: fixed; background-position: 100% 100%; background-repeat: no-repeat; }
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:
background-position: right 3em bottom 10px
See the section âLayering multiple background
imagesâ for how âbackground-position
â interacts with other
comma-separated background properties to form each background image layer.
background-clip
â propertyName: | background-clip |
---|---|
Value: | <box> [ , <box> ]* |
Initial: | border-box |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
Determines the background painting area, which determines the area within which the background is painted. The syntax of the property is given with
<box> = border-box | padding-box | content-box
Values have the following meanings:
border-box
â
padding-box
â
content-box
â
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 [CSS21].
See the section âLayering multiple background
imagesâ for how âbackground-clip
â interacts with other
comma-separated background properties to form each background image layer.
background-origin
â propertyName: | background-origin |
---|---|
Value: | <box> [ , <box> ]* |
Initial: | padding-box |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
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
â operates on to determine
the background positioning area(s).
padding-box
â
0 0
â is the upper left corner of the padding
edge, â100% 100%
â is the lower right corner.)
border-box
â
content-box
â
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 [CSS21].
Note that if âbackground-clip
â is âpadding-box
â, âbackground-origin
â is â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.
background-size
â propertyName: | background-size |
---|---|
Value: | <bg-size> [ , <bg-size> ]* |
Initial: | auto |
Applies to: | all elements |
Inherited: | no |
Percentages: | see text |
Media: | visual |
Computed value: | as specified, but with lengths made absolute |
Animatable: | yes except keyword values |
Specifies the size of the background images. Where
<bg-size> = [ <length> | <percentage> | auto ]{1,2} | cover | contain
Values have the following meanings:
contain
â
cover
â
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
âauto
â.
A percentage is relative to the background positioning area.
An â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 â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 the image has neither an intrinsic width nor an
intrinsic height, its size is determined as for âcontain
â.
Negative values are not allowed.
Here are some examples. The first example stretches the background image independently in both dimensions to completely cover the content area:
div { background-image: url(plasma.png); background-repeat: no-repeat; background-size: 100% 100%; background-origin: content-box }
The second example stretches the image so that exactly two copies fit horizontally. The aspect ratio is preserved:
p { background-image: url(tubes.png); background-size: 50% auto; background-origin: border-box }
This example forces the background image to be 15 by 15 pixels:
para { background-size: 15px 15px; background-image: url(tile.png)}
This example uses the image's intrinsic size. Note that this is the only possible behavior in CSS level 1 and 2.
body { background-size: auto; /* default */ background-image: url(flower.png) }
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 area width and is not rounded.
p { background-image: url(chain.png); background-repeat: no-repeat round; background-size: 20% 30% }
If âbackground-repeat
â is â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 âround
â for one dimension only and if âbackground-size
â
is â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:
div { background-image: url(image1.png); background-repeat: repeat; /* default */ background-size: auto } /* default */
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:
div { background-image: url(image2.png); background-repeat: repeat; /* default */ background-size: 3em } /* = '3em auto' */
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:
div { background-image: url(image3.png); background-repeat: round repeat; background-size: 3em auto }
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:
div { background-image: url(image4.png); background-repeat: repeat round; background-size: 3em auto }
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.
div { background-image: url(image5.png); background-repeat: round; background-size: auto 4em }
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.
background
â
propertyName: | background |
---|---|
Value: | [ <bg-layer> , ]* <final-bg-layer> |
Initial: | see individual properties |
Applies to: | all elements |
Inherited: | no |
Percentages: | see individual properties |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
Where
<bg-layer> = <bg-image> || <position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box>{1,2}
<final-bg-layer> = <bg-image> || <position> [ / <bg-size> ]? || <repeat-style> || <attachment> || <box>{1,2} || <'background-color'>
Note that a color is permitted in <final-bg-layer>, but not in <bg-layer>.
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 <box> value is present
then it sets both âbackground-origin
â and âbackground-clip
â
to that value. If two values are present, then the first sets âbackground-origin
â and the second âbackground-clip
â.
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.
body { background: red } p { background: url("chess.png") 40% / 10em gray round fixed border-box; }
The first rule is equivalent to:
body { background-color: red; background-position: 0% 0%; background-size: auto auto; background-repeat: repeat repeat; background-clip: border-box; background-origin: padding-box; background-attachment: scroll; background-image: none }
The second is equivalent to:
p { background-color: gray; background-position: 40% 50%; background-size: 10em 10em; background-repeat: round round; background-clip: border-box; background-origin: border-box; background-attachment: fixed; background-image: url(chess.png) }
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:
E { background: #CCC url("metal.jpg") top left / 100% auto no-repeat}
Another example shows equivalence:
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 }
The following declaration with multiple, comma-separated values
background: url(a.png) top left no-repeat, url(b.png) center / 100% 100% no-repeat, url(c.png) white;
is equivalent to
background-image: url(a.png), url(b.png), url(c.png); background-position: top left, center, top left; background-repeat: no-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;
The background of the root element becomes the background of the canvas and its
background painting area extends to cover
the entire canvas, although 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.) If
the root's âbackground-color
â value is âtransparent
â, the canvas's background color is UA
dependent. 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 HTML
element [HTML401] or an XHTML html
element [XHTML11]: if the computed value of
âbackground-image
â on the root element is
â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.
According to these rules, the canvas underlying the following HTML document will have a âmarbleâ background:
<!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 is like an
inline-level element for the purposes of the background (see
section 5.12.1 of [CSS21]). 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.
border-color
â
propertiesName: | border-top-color , border-right-color, border-bottom-color, border-left-color |
---|---|
Value: | <color> |
Initial: | currentColor |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | the computed color |
Animatable: | yes |
Name: | border-color |
---|---|
Value: | <color>{1,4} |
Initial: | (see individual properties) |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
These properties set the foreground color of the border specified by the border-style properties.
âBorder-color
â is a shorthand for the four
â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.
border-style
â
propertiesName: | border-top-style, border-right-style, border-bottom-style, border-left-style |
---|---|
Value: | <border-style> |
Initial: | none |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | specified value |
Animatable: | no |
Name: | border-style |
---|---|
Value: | <border-style>{1,4} |
Initial: | (see individual properties) |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
These properties set the style of the border, unless there is a border image
âBorder-style
â is a shorthand for the other
four. Its 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.
Where
<border-style> = none | hidden | dotted | dashed | solid | double | groove | ridge | inset | outset
Values have the following meanings:
none
â
background-image
â
hidden
â
none
â, but has different
behavior in the border conflict resolution rules for border-collapsed
tables [CSS21].
dotted
â
dashed
â
solid
â
double
â
border-width
â.)
groove
â
border-color
â.)
ridge
â
inset
â
ridge
â in the collapsing
border model. [CSS21]
outset
â
Borders are drawn in front of the element's background, but behind the element's content (in case it overlaps).
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.
border-width
â
propertiesName: | border-top-width, border-right-width, border-bottom-width, border-left-width |
---|---|
Value: | <border-width> |
Initial: | medium |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | absolute length; â0 â if the border style
is ânone â or âhidden â
|
Animatable: | yes |
Name: | border-width |
---|---|
Value: | <border-width>{1,4} |
Initial: | (see individual properties) |
Applies to: | all elements |
Inherited: | no |
Percentages: | see individual properties |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
These properties set the thickness of the border. Where
<border-width> = <length> | thin | medium | thick
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
<length> values are not allowed.
âBorder-width
â is a shorthand that sets the
four âborder-*-width
â properties. If it has
four values, they set top, right, bottom and left in that order. If left
is missing, it is the same as right; if bottom is missing, it is the same
as top; if right is missing, it is the same as top.
Note that the initial width is âmedium
â, but the initial style is ânone
â and therefore the used width is 0.
When the used width of the border is 0, we say that the border is absent.
Name: | border-top, border-right, border-bottom, border-left |
---|---|
Value: | <border-width> || <border-style> || <color> |
Initial: | See individual properties |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
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.
Name: | border |
---|---|
Value: | <border-width> || <border-style> || <color> |
Initial: | See individual properties |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
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 â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.
For example, the first rule below is equivalent to the set of five rules shown after it:
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.
Consider this example:
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.
border-radius
â propertiesName: | border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius |
---|---|
Value: | [ <length> | <percentage> ]{1,2} |
Initial: | 0 |
Applies to: | all elements (but see prose) |
Inherited: | no |
Percentages: | Refer to corresponding dimension of the border box. |
Media: | visual |
Computed value: | two absolute <length> or percentages |
Animatable: | yes |
Name: | border-radius |
---|---|
Value: | [ <length> | <percentage> ]{1,4} [ / [ <length> | <percentage> ]{1,4} ]? |
Initial: | see individual properties |
Applies to: | all elements (but see prose) |
Inherited: | no |
Percentages: | Refer to corresponding dimension of the border box. |
Media: | visual |
Computed value: | see individual properties |
Animatable: | see individual properties |
The two length or percentage values of the âborder-*-radius
â properties define the radii of a
quarter ellipse that defines the shape of the corner of the outer border
edge (see the diagram below). The first value is the horizontal radius,
the second the vertical radius. If the second value is omitted it is
copied from the first. If either length is zero, the corner is square, not
rounded. Percentages for the horizontal radius refer to the width of the
border box, whereas percentages for the vertical radius refer to the
height of the border box. Negative values are not allowed.
This example draws ovals of 15em wide and 10em high:
DIV.standout { width: 13em; height: 8em; border: solid black 1em; border-radius: 7.5em 5em }
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.
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;
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
â, âinset
â, etc.) follow the curve of the border.
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.
p { width: 70px; height: 70px; border: solid 30px; border-color: orange orange silver silver; border-top-right-radius: 100%; } |
A box's backgrounds, but not its border-image, are clipped to the appropriate
curve (as determined by âbackground-clip
â). Other effects that clip to
the border or padding edge (such as âoverflow
â other than âvisible
â) also must clip to the curve. The content of
replaced elements is always trimmed to the content edge curve.
Also, the area outside the curve of the border edge does not accept pointer events on behalf of the element.
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.
DIV { background: black; color: white; border-radius: 1em; padding: 1em }
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.
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
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.
The âborder-radius
â properties do apply to âtable
â and âinline-table
â
elements. When âborder-collapse
â is
âcollapse
â, the UA may apply the border-radius
properties to âtable
â and âinline-table
â elements, but is not required to. In this
case not only must the border radii of adjacent corners not intersect, but
the horizontal and vertical radii of a single corner must not extend past
the far border edges of the cell at that corner (i.e. a table corner's
border-radius does not affect cells not at that corner). If the computed
values of the border radii would cause this effect, then the used values
of all the border radii of the table must be reduced by the same factor so
that the radii neither intersect nor extend past the border edges of their
respective corner cells.
The effect of border-radius on internal table
elements is undefined in CSS3 Backgrounds and Borders, but may be
defined in a future specification. CSS3 UAs should ignore
border-radius properties applied to internal table elements when âborder-collapse
â is âcollapse
â.
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:
DIV { border: double orange 1em; border-image: url("border.png") 27 round stretch; }
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 rest of the border properties then interact to lay out the tiles as follows:
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:
.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' */ }
border-image-source
â propertyName: | border-image-source |
---|---|
Value: | none | <image> |
Initial: | none |
Applies to: | All elements, except internal table elements when âborder-collapse â is âcollapse â
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | ânone â or the image with its URI made
absolute
|
Animatable: | no |
Specifies an image to use instead of the border styles given by the
âborder-style
â
properties and as an additional background layer for the element. If the
value is ânone
â or if the image cannot be
displayed (or the property doesn't apply), the border styles will be used;
otherwise the element's borders are invisible and the border image is
drawn as described in the sections below.
border-image-slice
â propertyName: | border-image-slice |
---|---|
Value: | [<number> | <percentage>]{1,4} && fill? |
Initial: | 100% |
Applies to: | All elements, except internal table elements when âborder-collapse â is âcollapse â
|
Inherited: | no |
Percentages: | refer to size of the border image |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
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.)
When four values are specified, they set the offsets on the top, right, bottom and left sides in that order. If the left is missing, it is the same as the right; if the bottom is missing, it is the same as the top; if the right is missing, it is the same as the top.
fill
â
fill
â keyword, if present, causes the middle part
of the border-image to be preserved. (By default it is discarded, i.e.,
treated as empty.)
Negative values are not allowed and values bigger 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 as for an auto-sized background, using the border image area as the default object size in place of the background positioning area.
border-image-width
â propertyName: | border-image-width |
---|---|
Value: | [ <length> | <percentage> | <number> | auto ]{1,4} |
Initial: | 1 |
Applies to: | All elements, except table elements when âborder-collapse â is âcollapse â
|
Inherited: | no |
Percentages: | Relative to width/height of the border image area |
Media: | visual |
Computed value: | all <length>s made absolute, otherwise as specified |
Animatable: | no |
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 the left width is missing, it is the same as the
right; if the bottom is missing, it is the same as the top; if the right
is missing, it is the same as the top. Values have the following meanings:
auto
â
auto
â is specified then the border
image width is the intrinsic width or height (whichever is applicable) of
the corresponding image slice (see âborder-image-slice
â). If the image does not
have the required intrinsic dimension then the corresponding border-width is used instead.
Negative values are not allowed 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.
border-image-outset
â propertyName: | border-image-outset |
---|---|
Value: | [ <length> | <number> ]{1,4} |
Initial: | 0 |
Applies to: | All elements, except internal table elements when âborder-collapse â is âcollapse â
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | all <length>s made absolute, otherwise as specified |
Animatable: | no |
The values specify the amount by which the border image area extends beyond the border box. If it has four values, they set the outsets on the top, right, bottom and left sides in that order. If the left is missing, it is the same as the right; if the bottom is missing, it is the same as the top; if the right is missing, it is the same as the top.
As with âborder-image-width
â, a <number>
represents a multiple of the corresponding border-width. Negative values are not allowed
for any of the âborder-image-outset
â values.
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.
border-image-repeat
â propertyName: | border-image-repeat |
---|---|
Value: | [ stretch | repeat | round | space ]{1,2} |
Initial: | stretch |
Applies to: | All elements, except internal table elements when âborder-collapse â is âcollapse â
|
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
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 sides, the second to the vertical ones; 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:
stretch
â
repeat
â
round
â
space
â
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:
border-image-width
â.
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.
border-image-repeat
â.
If the first keyword is â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 â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 âround
â in the âbackground-repeat
â property.
If the first keyword is ârepeat
â or
âspace
â, the top, middle, and bottom images
are not changed any further.
The effects of âstretch
â, âround
â,
ârepeat
â, and âspace
â for the second keyword are analogous, acting
on the height of the left, middle and right images.
If the first keyword is â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 â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. All images are drawn at the same stacking level as normal borders: immediately in front of the background layers.
In the case of â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.
border-image
â propertyName: | 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 |
Media: | visual |
Computed value: | See individual properties |
Animatable: | See individual properties |
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 â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 [CSS21]).
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.
box-decoration-break
â propertyName: | box-decoration-break |
---|---|
Value: | slice | clone |
Initial: | slice |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | as specified |
Animatable: | no |
When a box is broken at a page break, column break, or, for inline
elements, at a line break, the âbox-decoration-break
â property specifies
whether box fragments are treated as broken fragments of one continuous
box, or whether each fragment is individually wrapped with the border and
padding. For backgrounds it defines how the background positioning area is derived
from these multiple fragments and how the element's background is drawn
within them. Values have the following meanings:
clone
â
border-radius
â and âborder-image
â and
âbox-shadow
â,
if any, are applied to each fragment independently. The background is
drawn independently in each fragment of the element. A no-repeat
background image will thus be rendered once in each fragment of the
element.
slice
â
No border and no padding are inserted at a break. No box-shadow is
drawn at a broken edge; âborder-radius
â does not apply to its
corners; and the âborder-image
â is rendered for the whole box
as if it were unbroken. The effect is as though the element were
rendered with no breaks present, and then sliced by the breaks
afterward.
Backgrounds are drawn as if, after the element has been laid out (including any justification, bidi reordering, page breaks, etc.), all the element's box fragments were taken and put one after the other in visual order. The background is applied to the bounding box of this composite box and then the fragments are put back, with each with its share of the background.
For boxes broken across lines, first fragments on the same line are
connected in visual order. Then fragments on subsequent lines are
ordered according to the element's inline progression direction and
aligned on the baseline. For example in a left-to-right containing block
(âdirection
â is âltr
â), the first fragment is the leftmost fragment on
the first line and fragments from subsequent lines are put to the right
of it. In a right-to-left containing block, the first fragment is the
rightmost on the first line and subsequent fragments are put to the left
of it.
For boxes broken across columns, the columns are treated as one continuous element, as if the column boxes were glued together in the block progression direction of the multi-column element. For boxes broken across pages, the page content areas are glued together in the block progression direction of the root element. In these cases, if the box fragments have different widths (heights, if the root element / multi-column element is in a vertical writing mode), then each piece draws its background assuming that the whole element has the same width (height) as this piece. This ensures that right-aligned images stay aligned to the right edge, left-aligned images stay aligned to the left edge, and centered images stay centered.
For inline elements, which side of a fragment is the broken
edge is determined by the parent element's inline progression direction.
For example, if an inline element whose parent has âdirection: rtl
â breaks across two lines, the
left edge of the fragment on the first line will be the broken
edge. (Note in particular that neither the element's own âdirection
â nor its containing block's âdirection
â is used.) See [CSS3-WRITING-MODES].
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
â.
box-shadow
â propertyName: | box-shadow |
---|---|
Value: | none | <shadow> [ , <shadow> ]* |
Initial: | none |
Applies to: | all elements |
Inherited: | no |
Percentages: | N/A |
Media: | visual |
Computed value: | any <length> made absolute; any specified color computed; otherwise as specified |
Animatable: | yes, except between inner and outer shadows (Transition to/from an
absent shadow is a transition to/from â0 0
transparent â or â0 0 transparent
inset â, as appropriate.)
|
The âbox-shadow
â property attaches one or more
drop-shadows to the box. The property is a comma-separated list of
shadows, each specified by 2-4 length values, an optional color, and an
optional âinset
â keyword.
Omitted lengths are 0; omitted colors are a UA-chosen color.
Where
<shadow> = inset? && [ <length>{2,4} && <color>? ]
The components of each <shadow> are interpreted as follows:
color
â property.
inset
â keyword,
if present, changes the drop shadow from an outer shadow (one that
shadows the box onto the canvas, as if it were lifted above the canvas)
to an inner shadow (one that shadows the canvas onto the box, as if the
box were cut out of the canvas and shifted behind it).
An outer box-shadow casts a shadow as if the border-box of the element were opaque. 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. The inner shadow is drawn inside the padding edge only: it is clipped outside the padding box of the element.
If the box has a nonzero âborder-radius
â,
the shadow shape is rounded in the same way. The âborder-image
â does
not affect the shape of the box-shadow.
If a spread distance is defined, the shadow is expanded outward or contracted inward by an operation equivalent to applying the absolute value of the spread value to a blur operation as defined below and thresholding the result such that for a positive spread distance all non-transparent pixels are given the full shadow color and for a negative spread distance all non-opaque pixels are made transparent. The UA may approximate this operation by taking an outward outset of the specified amount normal to the original shadow perimeter. Alternatively the UA may approximate the transformed shadow perimeter shape by outsetting (insetting, for inner shadows) the shadow's straight edges by the spread distance and increasing (decreasing, for inner shadows) and flooring at zero the corner radii by the same amount. (The UA may even combine these methods, using one method for outer shadows and another for inner ones.) For corners with a zero border-radius, however, the corner must remain sharpâthe operation is equivalent to scaling the shadow shape. In any case, the effective width and height of the shadow shape is floored at zero. (A zero-sized shadow shape would cause an outer shadow to disappear, and an inner shadow to cover the entire padding-box.)
A non-zero blur distance 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 the full shadow color at the endpoint inside the shadow to fully transparent at the endpoint outside it.
The example below demonstrates the effects of spread and blur on the shadow:
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;
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 other boxes or their shadows. In terms of stacking contexts and the painting order, the outer 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.
Below are some examples of an orange box with a blue border being given a drop shadow.
|
|
|
---|---|---|
| ||
| ||
| ||
|
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].
Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words âMUSTâ, âMUST NOTâ, âREQUIREDâ, âSHALLâ, âSHALL NOTâ, âSHOULDâ, âSHOULD NOTâ, âRECOMMENDEDâ, âMAYâ, and âOPTIONALâ in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification. All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. [RFC2119]
Examples in this specification are introduced with the words âfor
exampleâ or are set apart from the normative text with
class="example"
, like this:
This is an example of an informative example.
Informative notes begin with the word âNoteâ and are set apart from
the normative text with class="note"
, like this:
Note, this is an informative note.
Conformance to CSS Backgrounds and Borders Level 3 is defined for three classes:
A style sheet is conformant to CSS Backgrounds and Borders Level 3 if all of its declarations that use properties defined in this module have values that are valid according to the generic CSS grammar and the individual grammars of each property as given in this module.
A renderer is conformant to CSS Backgrounds and Borders Level 3 if, in addition to interpreting the style sheet as defined by the appropriate specifications, it supports all the properties defined by CSS Backgrounds and Borders Level 3 by parsing them correctly and rendering the document accordingly. However the inability of a UA to correctly render a document due to limitations of the device does not make the UA non-conformant. (For example, a UA is not required to render color on a monochrome monitor.)
An authoring tool is conformant to CSS Backgrounds and Borders Level 3 if it writes syntactically correct style sheets, according to the generic CSS grammar and the individual grammars of each property in this module.
This section is informative. CSS has different levels of features, each a subset of the other. (See [CSS-2010] for a full explanation.) The lists below describe which features from this specification are in each level.
background-color
â
background-image
â only one image (no layers)
background-repeat
â: only ârepeat
â | ârepeat-x
â | ârepeat-y
â | âno-repeat
â
background-attachment
â: only âscroll
â | âfixed
â
background-position
â: only one or two values
allowed
background
â
shorthand: only color, image, repeat, attachment and position
border-color
â properties
border-style
â properties
border-width
â properties
border-top
â, âborder-bottom
â,
âborder-right
â, âborder-left
â, and
âborder
â shorthands
background-color
â
background-image
â: only one image (no layers)
background-repeat
â: only ârepeat
â | ârepeat-x
â | ârepeat-y
â | âno-repeat
â
background-attachment
â: only âscroll
â | âfixed
â
background-position
â: only one or two values
allowed
background
â: only color, image, repeat,
attachment and position
border-color
â properties
border-style
â properties
border-width
â properties
border-top
â, âborder-bottom
â,
âborder-right
â, âborder-left
â, and
âborder
â shorthands
As described in the W3C process document, a Candidate Recommendation (CR) is a specification that W3C recommends for use on the Web. The next stage is âRecommendation,â when the specification is sufficiently implemented.
For this specification to be proposed as a W3C Recommendation, the following conditions shall be met. There must be at least two independent, interoperable implementations of each feature. Each feature may be implemented by a different set of products, there is no requirement that all features be implemented by a single product. For the purposes of this criterion, we define the following terms:
A minimum of three months of the CR period must have elapsed. This is to ensure that enough time is given for any remaining major errors to be caught.
Features will be dropped if two or more interoperable implementations are not found by the end of the CR period.
Features may/will also be dropped if adequate/sufficient (by judgment of CSS WG) tests have not been produced for those feature(s) by the end of the CR period.
The following (non-editorial) changes were made to this specification since the 17 April 2012 Candidate Recommendation:
background-position
â: the computed value is a
list of positions.
border-radius
â reduces the interactive area,
the width/height of the box might need to be increased.
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.
::first-line
â and
â::first-letter
â pseudo-elements.
background-repeat
â. The value is always a
pair of keywords, never a single keyword.
background-image
â to the list of properties
that the âbackground
â property reset.
border-width
â.
border-radius
â.
border-image
â on tables with collapsed
borders and added that the rendering will be defined later.
The following changes were made to this specification since the 15 February 2011 Candidate Recommendation:
background-position
â has two âauto
â values and the image is missing an intrinsic
dimension.
If both values are â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.
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 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.
box-decoration-break
â. Added:
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â.
box-shadow
â.
The color is the color of the shadow. If the color is absent, the used color is taken from the âcolorâ property.
background-position
â.
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 <length>), otherwise as a percentage.
Changed Equivalent to Computes in definition of
keywords.
bg-position<position> = [ [ left | center | right | top | bottom | <percentage> | <length> ] | [ left | center | right | <percentage> | <length> ] [ top | center | bottom | <percentage> | <length> ]?| [ center | [ left | right ] [ <percentage> | <length> ]? ] && [ center | [ top | bottom ] [ <percentage> | <length> ]? ] ]
space
â keyword to âborder-image-repeat
â property value table: it
was included in the list of allowable values, but not in the syntax
definition.
[ stretch | repeat | round | space ]{1,2}
The height (2.5em) is enough for the specified radii (0.5em plus
2.5em2.0em).
border-width
â, since they are not included in
the property.
The following changes were made to this specification since the 17 December 2009 Candidate Recommendation:
content-box
â value of âbackground-clip
â.
background
â shorthand syntax for âbackground-clip
â and âbackground-origin
â.
border-radius
â produces a curve.
box-shadow
â property.
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.
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.
Property | Values | Initial | Applies to | Inh. | Percentages | Media |
---|---|---|---|---|---|---|
background | [ <bg-layer> , ]* <final-bg-layer> | see individual properties | all elements | no | see individual properties | visual |
background-attachment | <attachment> [ , <attachment> ]* | scroll | all elements | no | N/A | visual |
background-clip | <box> [ , <box> ]* | border-box | all elements | no | N/A | visual |
background-color | <color> | transparent | all elements | no | N/A | visual |
background-image | <bg-image> [ , <bg-image> ]* | none | all elements | no | N/A | visual |
background-origin | <box> [ , <box> ]* | padding-box | all elements | no | N/A | visual |
background-position | <position> [ , <position> ]* | 0% 0% | all elements | no | refer to size of background positioning area minus size of background image; see text | visual |
background-repeat | <repeat-style> [ , <repeat-style> ]* | repeat | all elements | no | N/A | visual |
background-size | <bg-size> [ , <bg-size> ]* | auto | all elements | no | see text | visual |
border | <border-width> || <border-style> || <color> | See individual properties | all elements | no | N/A | visual |
border-color | <color>{1,4} | (see individual properties) | all elements | no | N/A | visual |
border-image | <âborder-image-sourceâ> || <âborder-image-sliceâ> [ / <âborder-image-widthâ> | / <âborder-image-widthâ>? / <âborder-image-outsetâ> ]? || <âborder-image-repeatâ> | See individual properties | See individual properties | no | N/A | visual |
border-image-outset | [ <length> | <number> ]{1,4} | 0 | All elements, except internal table elements when âborder-collapseâ is âcollapseâ | no | N/A | visual |
border-image-repeat | [ stretch | repeat | round | space ]{1,2} | stretch | All elements, except internal table elements when âborder-collapseâ is âcollapseâ | no | N/A | visual |
border-image-slice | [<number> | <percentage>]{1,4} && fill? | 100% | All elements, except internal table elements when âborder-collapseâ is âcollapseâ | no | refer to size of the border image | visual |
border-image-source | none | <image> | none | All elements, except internal table elements when âborder-collapseâ is âcollapseâ | no | N/A | visual |
border-image-width | [ <length> | <percentage> | <number> | auto ]{1,4} | 1 | All elements, except table elements when âborder-collapseâ is âcollapseâ | no | Relative to width/height of the border image area | visual |
border-radius | [ <length> | <percentage> ]{1,4} [ / [ <length> | <percentage> ]{1,4} ]? | see individual properties | all elements (but see prose) | no | Refer to corresponding dimension of the border box. | visual |
border-style | <border-style>{1,4} | (see individual properties) | all elements | no | N/A | visual |
border-top, border-right, border-bottom, border-left | <border-width> || <border-style> || <color> | See individual properties | all elements | no | N/A | visual |
border-top-color , border-right-color, border-bottom-color, border-left-color | <color> | currentColor | all elements | no | N/A | visual |
border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius | [ <length> | <percentage> ]{1,2} | 0 | all elements (but see prose) | no | Refer to corresponding dimension of the border box. | visual |
border-top-style, border-right-style, border-bottom-style, border-left-style | <border-style> | none | all elements | no | N/A | visual |
border-top-width, border-right-width, border-bottom-width, border-left-width | <border-width> | medium | all elements | no | N/A | visual |
border-width | <border-width>{1,4} | (see individual properties) | all elements | no | see individual properties | visual |
box-decoration-break | slice | clone | slice | all elements | no | N/A | visual |
box-shadow | none | <shadow> [ , <shadow> ]* | none | all elements | no | N/A | visual |
auto
â
background-size
â value, 3.9.
border-image-width
â value, 6.3.
border-box
â
background-clip
â value, 3.7.
background-origin
â value, 3.8.
bottom
â
background-position
â value, 3.6.
center
â
background-position
â value, 3.6.
clone
â, 7.1.
contain
â, 3.9.
content-box
â,
3.8.
background-clip
â value, 3.7.
cover
â, 3.9.
dashed
â, 4.2.
dotted
â, 4.2.
double
â, 4.2.
fill
â, 6.2.
fixed
â, 3.5.
groove
â, 4.2.
hidden
â, 4.2.
inset
â, 4.2.
left
â
background-position
â value, 3.6.
local
â, 3.5.
none
â
background-image
â value, 3.3.
border-style
â value, 4.2.
no-repeat
â
background-repeat
â value, 3.4.
outset
â, 4.2.
padding-box
â
background-clip
â value, 3.7.
background-origin
â value, 3.8.
repeat
â
background-repeat
â value, 3.4.
border-image-repeat
â value, 6.5.
repeat-x
â, 3.4.
repeat-y
â, 3.4.
ridge
â, 4.2.
right
â
background-position
â value, 3.6.
round
â
background-repeat
â value, 3.4.
border-image-repeat
â value, 6.5.
scroll
â, 3.5.
slice
â, 7.1.
solid
â, 4.2.
space
â
background-repeat
â value, 3.4.
border-image-repeat
â value, 6.5.
stretch
â, 6.5.
top
â
background-position
â value, 3.6.