Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

background — background shorthand

background sets a color and background image layers in one declaration. Omitted components take their initial values, so the shorthand can clear earlier settings.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

background: <bg-layer>#? , <final-bg-layer>;

background combines background-image, background-position, background-size, background-repeat, background-attachment, background-origin, background-clip, and background-color.

Separate layers with commas; the first is on top. Color is allowed only in the final layer and lies beneath images. Size must follow position and /. One box keyword sets both origin and clip; two mean origin then clip.

Omitted components are reset, not preserved. Thus background: red removes an earlier image if this declaration wins the cascade. To change only the color, use background-color.

Examples

<!doctype html>
<meta charset="utf-8">
<title>background</title>
<style>
  .panel {
    width: 200px;
    height: 120px;
    background: linear-gradient(#006699, #006699)
                center / 80px 40px no-repeat #eeeeee;
  }
</style>
<div class="panel"></div>

Result

A 200 × 120 px light-gray rectangle containing a centered 80 × 40 px solid blue rectangle.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources