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> |
|---|---|
| Initial | CanvasText |
| Applies to | All elements and text |
| Inherited | Yes |
| Animation | By computed value type |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-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> |
|---|---|
| Initial | 1 |
| Applies to | All elements |
| Inherited | No |
| Percentages | Map to the range [0,1] |
| Animation | By computed value type |
| Support | Chrome 1 · Firefox 1 · Safari 2 |
| Spec | css-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> |
|---|---|
| Initial | See individual properties |
| Applies to | All elements |
| Inherited | No |
| Percentages | See individual properties |
| Animation | See individual properties |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-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;
background-color
A solid colour painted beneath all the background images, filling the area set by background-clip.
| Syntax | <color> |
|---|---|
| Initial | transparent |
| Applies to | All elements |
| Inherited | No |
| Animation | By computed value |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-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># |
|---|---|
| Initial | none |
| Applies to | All elements |
| Inherited | No |
| Animation | Discrete |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-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);
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># |
|---|---|
| Initial | 0% 0% |
| Applies to | All elements |
| Inherited | No |
| Percentages | Refer to the size of the background positioning area minus the size of the background image |
| Animation | Repeatable list |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-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.
| Syntax | background-position-x: [ center | [ [ left | right | x-start | x-end ]? <length-percentage>? ]! ]#background-position-y: [ center | [ [ top | bottom | y-start | y-end ]? <length-percentage>? ]! ]# |
|---|---|
| Initial | 0% |
| Applies to | All elements |
| Inherited | No |
| Percentages | Refer to the width (for background-position-x) or height (for background-position-y) of the background positioning area minus that of the background image |
| Animation | Repeatable list |
| Support | Chrome 1 · Firefox 49 · Safari 1 |
| Spec | css-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># |
|---|---|
| Initial | auto |
| Applies to | All elements |
| Inherited | No |
| Percentages | Relative to the background positioning area |
| Animation | Repeatable list |
| Support | Chrome 3 · Firefox 4 · Safari 5 |
| Spec | css-backgrounds-4 |
| Value | Effect |
|---|---|
auto | The image's natural size, or its natural ratio if only one axis is given. |
cover | Scales the image, keeping its ratio, until it fills the whole area. Parts may be cropped. |
contain | Scales 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># |
|---|---|
| Initial | repeat |
| Applies to | All elements |
| Inherited | No |
| Animation | Discrete |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-backgrounds-4 |
| Value | Effect |
|---|---|
repeat | Tiles the image; tiles at the edges are clipped. |
no-repeat | Paints the image once. |
space | Tiles as many whole copies as fit and spreads the leftover space between them. |
round | Stretches or squashes the image so a whole number of copies fits. |
repeat-x / repeat-y | Tiles 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># |
|---|---|
| Initial | scroll |
| Applies to | All elements |
| Inherited | No |
| Animation | Discrete |
| Support | Chrome 1 · Firefox 1 · Safari 1 |
| Spec | css-backgrounds-4 |
| Value | Effect |
|---|---|
scroll | Fixed to the element's box; it does not move when the element's own content scrolls. |
local | Fixed to the element's content, so it scrolls along with it. |
fixed | Fixed 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># |
|---|---|
| Initial | padding-box |
| Applies to | All elements |
| Inherited | No |
| Animation | Repeatable list |
| Support | Chrome 1 · Firefox 4 · Safari 3 |
| Spec | css-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># |
|---|---|
| Initial | border-box |
| Applies to | All elements |
| Inherited | No |
| Animation | Repeatable list |
| Support | Chrome 1 · Firefox 4 · Safari 5 |
| Spec | css-backgrounds-4 |
| Value | Effect |
|---|---|
border-box | Paints under the border as well as the padding and content. |
padding-box | Stops at the inside edge of the border. |
content-box | Paints only behind the content. |
border-area | Paints only where the border strokes are drawn, so a gradient can colour the border. Chrome 150 · Firefox no · Safari 18.2. |
text | Paints 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;
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.
| Syntax | normal | [ light | dark | <custom-ident> ]+ && only? |
|---|---|
| Initial | normal |
| Applies to | All elements and text |
| Inherited | Yes |
| Animation | Discrete |
| Support | Chrome 81 · Firefox 96 · Safari 13 |
| Spec | css-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; }
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.
| Syntax | auto | none | preserve-parent-color |
|---|---|
| Initial | auto |
| Applies to | All elements and text |
| Inherited | Yes |
| Animation | Not animatable |
| Support | Chrome 89 · Firefox 113 · Safari no |
| Spec | css-color-adjust-1 |
| Value | Effect |
|---|---|
auto | The browser forces the element's colours to the user's palette. |
none | The element keeps its own colours. |
preserve-parent-color | Like none, except that an inherited color takes the parent's forced colour. Chrome 106 · Firefox no · Safari no. |
print-color-adjust
Whether the browser may change an element's colours to suit the output device, for example by leaving out background colours and images when printing to save ink. exact asks it to keep them.
| Syntax | economy | exact |
|---|---|
| Initial | economy |
| Applies to | All elements |
| Inherited | Yes |
| Animation | Discrete |
| Support | Chrome 136 · Firefox 97 · Safari 15.4 |
| Spec | css-color-adjust-1 |
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'> |
|---|---|
| Initial | See individual properties |
| Applies to | See individual properties |
| Inherited | See individual properties |
| Percentages | See individual properties |
| Animation | See individual properties |
| Support | Chrome no · Firefox 48 · Safari 15.4 |
| Spec | css-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.
| Syntax | standard | no-limit | constrained | <dynamic-range-limit-mix()> |
|---|---|
| Initial | no-limit |
| Applies to | All elements |
| Inherited | Yes |
| Animation | By dynamic-range-limit-mix() |
| Support | Chrome 136 · Firefox no · Safari 26 |
| Spec | css-color-hdr-1 |
| Value | Effect |
|---|---|
standard | No brighter than standard dynamic range white. |
constrained | Some extra brightness above standard white, but not the display's full range. |
no-limit | The display's full HDR range. |
dynamic-range-limit-mix() | A weighted blend of the keywords, by percentage. Chrome 136 · Firefox no · Safari no. |