A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/CSS/background below:

background - CSS | MDN

background

Baseline Widely available

The background shorthand CSS property sets all background style properties at once, such as color, image, origin and size, or repeat method. Component properties not set in the background shorthand property value declaration are set to their default values.

Try it
background: content-box radial-gradient(crimson, skyblue);
background: no-repeat url("/shared-assets/images/examples/lizard.png");
background: left 5% / 15% 60% repeat-x
  url("/shared-assets/images/examples/star.png");
background:
  center / contain no-repeat
    url("/shared-assets/images/examples/firefox-logo.svg"),
  #eee 35% url("/shared-assets/images/examples/lizard.png");
<section id="default-example">
  <div id="example-element"></div>
</section>
#example-element {
  min-width: 100%;
  min-height: 100%;
  padding: 10%;
}
Constituent properties Syntax
/* Using a <background-color> */
background: green;

/* Using a <bg-image> and <repeat-style> */
background: url("test.jpg") repeat-y;

/* Using a <visual-box> and <'background-color'> */
background: border-box red;

/* A single image, centered and scaled */
background: no-repeat center/80% url("../img/image.png");

/* Global values */
background: inherit;
background: initial;
background: revert;
background: revert-layer;
background: unset;

The background property is specified as one or more background layers, separated by commas.

The syntax of each layer is as follows:

Values
<attachment>

See background-attachment. Default: scroll.

<visual-box>

See background-clip and background-origin. Default: border-box and padding-box respectively.

<'background-color'>

See background-color. Default: transparent.

<bg-image>

See background-image. Default: none.

<bg-position>

See background-position. Default: 0% 0%.

<repeat-style>

See background-repeat. Default: repeat.

<bg-size>

See background-size. Default: auto.

The following three lines of CSS are equivalent:

background: none;
background: transparent;
background: repeat scroll 0% 0% / auto padding-box border-box none transparent;
Formal definition Formal syntax
background = 
<bg-layer>#? , <final-bg-layer>

<bg-layer> =


<bg-image> ||
<bg-position> [ / <bg-size> ]? ||
<repeat-style> ||
<attachment> ||
<visual-box> ||
<visual-box>

<final-bg-layer> =


<bg-image> ||
<bg-position> [ / <bg-size> ]? ||
<repeat-style> ||
<attachment> ||
<visual-box> ||
<visual-box> ||
<'background-color'>

<bg-image> =


<image> |
none

<bg-position> =


[ left | center | right | top | bottom | <length-percentage> ] |
[ left | center | right | <length-percentage> ] [ top | center | bottom | <length-percentage> ] |
[ center | [ left | right ] <length-percentage>? ] && [ center | [ top | bottom ] <length-percentage>? ]

<bg-size> =


[ <length-percentage [0,∞]> | auto ]{1,2} |
cover |
contain

<repeat-style> =


repeat-x |
repeat-y |
[ repeat | space | round | no-repeat ]{1,2}

<attachment> =


scroll |
fixed |
local

<visual-box> =


content-box |
padding-box |
border-box

<background-color> =


<color>

<image> =


<url> |
<gradient>

<length-percentage> =


<length> |
<percentage>

<url> =


<url()> |
<src()>

<url()> =


url( <string> <url-modifier>* ) |
<url-token>

<src()> =


src( <string> <url-modifier>* )
Accessibility

Browsers do not provide any special information on background images to assistive technology. This is important primarily for screen readers, as a screen reader will not announce its presence and therefore convey nothing to its users. If the image contains information critical to understanding the page's overall purpose, it is better to describe it semantically in the document.

Examples Setting backgrounds with color keywords and images HTML
<p class="top-banner">
  Starry sky<br />
  Twinkle twinkle<br />
  Starry sky
</p>
<p class="warning">Here is a paragraph</p>
<p></p>
CSS
.warning {
  background: pink;
}

.top-banner {
  background: url("star-solid.gif") #99f repeat-y fixed;
}
Result Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4