Color & backgrounds

The properties that set an element's text colour and transparency, paint the layers of its background, and tell the browser how to adapt colours for dark schemes, forced colours, printing and HDR screens. The colour values themselves are under <color> and Colour functions; gradients are under Gradients; borders are under Borders, corners & outlines.

Colour

color

The foreground colour of an element's text and text decorations. It is inherited, and it sets the value of currentColor, which borders, outlines, SVG fills and many other colour properties use by default.

Syntax<color>
InitialCanvasText
Applies toAll elements and text
InheritedYes
AnimationBy computed value type
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-color-4

The initial value CanvasText is the system colour for text on the default canvas, so it follows color-scheme: dark text in a light scheme, light text in a dark one.

opacity

Makes an element and everything inside it partly transparent, as one group. An <opacity-value> is a <number> or a <percentage>; 0 is fully transparent and 1 fully opaque.

Syntax<opacity-value>
Initial1
Applies toAll elements
InheritedNo
PercentagesMap to the range [0,1]
AnimationBy computed value type
SupportChrome 1 · Firefox 1 · Safari 2
Speccss-color-4

Any value below 1 creates a stacking context. A child cannot be more opaque than its parent; to fade only a background, use a translucent colour such as rgb(0 0 0 / 50%) instead.

Backgrounds

background

Shorthand for all the background longhands. Layers are separated by commas, the first on top; each <bg-layer> may give an image, a position with an optional / size, a repeat style, an attachment and one or two boxes. Only the last layer, <final-bg-layer>, may also give a background-color.

Syntax<bg-layer>#? , <final-bg-layer>
InitialSee individual properties
Applies toAll elements
InheritedNo
PercentagesSee individual properties
AnimationSee individual properties
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4

Like every shorthand, it resets any longhand you leave out to its initial value. One box keyword sets both background-origin and background-clip; two set origin then clip.

background: url(paper.png) center / cover no-repeat, #f4f1ea;
One image layer, centred and scaled to cover, over a solid colour.

background-color

A solid colour painted beneath all the background images, filling the area set by background-clip.

Syntax<color>
Initialtransparent
Applies toAll elements
InheritedNo
AnimationBy computed value
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4

background-image

One or more images to paint as background layers, separated by commas, with the first listed on top. Each <bg-image> is an <image> (a url(), a gradient or image-set()) or none.

Syntax<bg-image>#
Initialnone
Applies toAll elements
InheritedNo
AnimationDiscrete
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4

The number of layers is set by this list. The other background longhands are matched to it item by item; a shorter list is repeated and a longer one is cut off.

background-image: linear-gradient(rgb(0 0 0 / 0), rgb(0 0 0 / 60%)), url(hero.jpg);
A darkening gradient laid over a photo, so text on top stays readable.

background-position

Where each background image is placed inside its positioning area. A <bg-position> is one to four values: keywords (left, center, bottom …), lengths or percentages.

Syntax<bg-position>#
Initial0% 0%
Applies toAll elements
InheritedNo
PercentagesRefer to the size of the background positioning area minus the size of the background image
AnimationRepeatable list
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4

Because percentages subtract the image size, 50% 50% centres the image and 100% 100% puts it flush in the bottom-right corner. The four-value form offsets from any edge: right 1rem bottom 1rem.

background-position-x, background-position-y

The background position in one physical axis, so you can change one axis without restating the other. The ! after the group means at least one of its parts must be given.

Syntaxbackground-position-x: [ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#
background-position-y: [ center | [ [ top | bottom | y-start | y-end ]? <length-percentage>? ]! ]#
Initial0%
Applies toAll elements
InheritedNo
PercentagesRefer to the width (for background-position-x) or height (for background-position-y) of the background positioning area minus that of the background image
AnimationRepeatable list
SupportChrome 1 · Firefox 49 · Safari 1
Speccss-backgrounds-4

background-size

The size of each background image. A <bg-size> is cover, contain, or one or two lengths, percentages or auto (width, then height).

Syntax<bg-size>#
Initialauto
Applies toAll elements
InheritedNo
PercentagesRelative to the background positioning area
AnimationRepeatable list
SupportChrome 3 · Firefox 4 · Safari 5
Speccss-backgrounds-4
ValueEffect
autoThe image's natural size, or its natural ratio if only one axis is given.
coverScales the image, keeping its ratio, until it fills the whole area. Parts may be cropped.
containScales the image, keeping its ratio, until it fits entirely inside the area. Gaps may be left.
<length-percentage>One value sets the width and leaves the height auto; two set width then height.

background-repeat

Whether and how each background image is tiled to fill its area. A <repeat-style> is repeat-x, repeat-y, or one or two of repeat, space, round and no-repeat (horizontal, then vertical).

Syntax<repeat-style>#
Initialrepeat
Applies toAll elements
InheritedNo
AnimationDiscrete
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4
ValueEffect
repeatTiles the image; tiles at the edges are clipped.
no-repeatPaints the image once.
spaceTiles as many whole copies as fit and spreads the leftover space between them.
roundStretches or squashes the image so a whole number of copies fits.
repeat-x / repeat-yTiles in one axis only; short for repeat no-repeat and no-repeat repeat.

background-attachment

Whether a background image moves with the element, with the element's scrolled content, or stays fixed to the viewport. An <attachment> is scroll, fixed or local.

Syntax<attachment>#
Initialscroll
Applies toAll elements
InheritedNo
AnimationDiscrete
SupportChrome 1 · Firefox 1 · Safari 1
Speccss-backgrounds-4
ValueEffect
scrollFixed to the element's box; it does not move when the element's own content scrolls.
localFixed to the element's content, so it scrolls along with it.
fixedFixed to the viewport; the element acts as a window onto it.

background-origin

Which box is the background positioning area: the box that background-position and percentage background-size values are measured against. A <visual-box> is border-box, padding-box or content-box.

Syntax<visual-box>#
Initialpadding-box
Applies toAll elements
InheritedNo
AnimationRepeatable list
SupportChrome 1 · Firefox 4 · Safari 3
Speccss-backgrounds-4

It has no effect on a layer with background-attachment: fixed, which is positioned against the viewport.

background-clip

How far the background is painted. A <bg-clip> is a <visual-box>, border-area or text. On the last layer it also clips background-color.

Syntax<bg-clip>#
Initialborder-box
Applies toAll elements
InheritedNo
AnimationRepeatable list
SupportChrome 1 · Firefox 4 · Safari 5
Speccss-backgrounds-4
ValueEffect
border-boxPaints under the border as well as the padding and content.
padding-boxStops at the inside edge of the border.
content-boxPaints only behind the content.
border-areaPaints only where the border strokes are drawn, so a gradient can colour the border. Chrome 150 · Firefox no · Safari 18.2.
textPaints only inside the glyphs of the element's text. Make the text colour transparent to let the background show. Chrome 120 · Firefox 49 · Safari 14.
background: linear-gradient(90deg, teal, purple);
background-clip: text;
color: transparent;
Gradient-filled text.

Colour adjustment

color-scheme

Says which colour schemes an element is designed to be shown in. The browser then picks matching defaults for the canvas, form controls, scrollbars and system colours such as Canvas and CanvasText, and light-dark() resolves against it.

Syntaxnormal | [ light | dark | <custom-ident> ]+ && only?
Initialnormal
Applies toAll elements and text
InheritedYes
AnimationDiscrete
SupportChrome 81 · Firefox 96 · Safari 13
Speccss-color-adjust-1

When several schemes are listed, the browser uses the one that matches the user's preference. normal means the element does not support schemes, so it gets the browser's default (light) colours. only asks the browser not to force a scheme the page did not list.

:root { color-scheme: light dark; }
Opt the whole page into both schemes; the browser follows the user's setting.

forced-color-adjust

Whether the browser may replace an element's colours in a forced colours mode, such as Windows high contrast. Use none sparingly, for things like colour swatches whose colours carry meaning, and pair it with @media (forced-colors: active) styles of your own.

Syntaxauto | none | preserve-parent-color
Initialauto
Applies toAll elements and text
InheritedYes
AnimationNot animatable
SupportChrome 89 · Firefox 113 · Safari no
Speccss-color-adjust-1
ValueEffect
autoThe browser forces the element's colours to the user's palette.
noneThe element keeps its own colours.
preserve-parent-colorLike none, except that an inherited color takes the parent's forced colour. Chrome 106 · Firefox no · Safari no.

color-adjust Deprecated

An older name for print-color-adjust, kept as a shorthand of it for compatibility. Use print-color-adjust instead.

Syntax<'print-color-adjust'>
InitialSee individual properties
Applies toSee individual properties
InheritedSee individual properties
PercentagesSee individual properties
AnimationSee individual properties
SupportChrome no · Firefox 48 · Safari 15.4
Speccss-color-adjust-1

dynamic-range-limit

Limits how bright high dynamic range (HDR) images and video may be shown, relative to the white of ordinary content. Use it to stop HDR thumbnails outshining the page around them.

Syntaxstandard | no-limit | constrained | <dynamic-range-limit-mix()>
Initialno-limit
Applies toAll elements
InheritedYes
AnimationBy dynamic-range-limit-mix()
SupportChrome 136 · Firefox no · Safari 26
Speccss-color-hdr-1
ValueEffect
standardNo brighter than standard dynamic range white.
constrainedSome extra brightness above standard white, but not the display's full range.
no-limitThe display's full HDR range.
dynamic-range-limit-mix()A weighted blend of the keywords, by percentage. Chrome 136 · Firefox no · Safari no.