background-color

  • Revision slug: CSS/background-color
  • Revision title: background-color
  • Revision id: 21244
  • Created:
  • Creator: Yuichiro
  • Is current revision? No
  • Comment 12 words added

Revision Content

{{ CSSRef() }}

Summary

background-color sets the background color of an element, either through a color value or the keyword transparent.

  • {{ Xref_cssinitial() }}: transparent
  • Applies to: all elements
  • {{ Xref_cssinherited() }}: no
  • Percentages: N/A
  • Media: {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }}: as specified

Syntax

background-color: color | transparent | inherit

Values

color 
The color can be specified as a hexadecimal RGB value, a regular RGB value, or by using one of the pre-defined color keywords.
transparent 
The default value for background-color is transparent meaning the element has no color of its own, instead showing the color of the element behind it.

Examples

{{ CSSRefExampleLink("background-color") }}

.exampleOne {
	background-color: teal;
	color: white;
}

.exampleTwo {
	background-color: rgb(153,102,153);
	color: rgb(255,255,204);
}

.exampleThree {
	background-color: #666699;
	color: #FFFFFF;
}

Notes

Color reference: See color values.

Browser compatibility

{{ CompatibilityTable() }}

Feature Firefox (Gecko) Chrome Internet Explorer Opera Safari (WebKit)
Basic support {{ CompatGeckoDesktop("1.0") }} 1.0 4.0 3.5 1.0 (85)
Feature Firefox Mobile (Gecko) Android IE Phone Opera Mobile Safari Mobile
Basic support {{ CompatGeckoMobile("1.9.2") }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }} {{ CompatVersionUnknown() }}

Specifications

See also

{{ languages( { "de": "de/CSS/background-color", "es": "es/CSS/background-color", "fr": "fr/CSS/background-color", "it": "it/CSS/background-color", "ja": "ja/CSS/background-color", "pl": "pl/CSS/background-color" } ) }}

Revision Source

<p>{{ CSSRef() }}</p>
<h3>Summary</h3>
<p><code>background-color</code> sets the background color of an element, either through a color value or the keyword <code>transparent</code>.</p>
<ul> <li>{{ Xref_cssinitial() }}: transparent</li> <li>Applies to: all elements</li> <li>{{ Xref_cssinherited() }}: no</li> <li>Percentages: N/A</li> <li>Media: {{ Xref_cssvisual() }}</li> <li>{{ Xref_csscomputed() }}: as specified</li>
</ul>
<h3 name="Syntax">Syntax</h3>
<pre class="eval">background-color: <em>color</em> | transparent | inherit
</pre>
<h3 name="Values">Values</h3>
<dl> <dt>color </dt> <dd>The color can be specified as a hexadecimal RGB value, a regular RGB value, or by using one of the pre-defined color keywords.</dd> <dt>transparent </dt> <dd>The default value for <code>background-color</code> is <code>transparent</code> meaning the element has no color of its own, instead showing the color of the element behind it.</dd>
</dl>
<h3 name="Examples">Examples</h3>
<p>{{ CSSRefExampleLink("background-color") }}</p>
<pre>.exampleOne {
	background-color: teal;
	color: white;
}

.exampleTwo {
	background-color: rgb(153,102,153);
	color: rgb(255,255,204);
}

.exampleThree {
	background-color: #666699;
	color: #FFFFFF;
}

</pre>
<h3 name="Notes">Notes</h3>
<p>Color reference: See <a href="/en/CSS/color_value" title="en/CSS/color_value">color values</a>.</p>
<h3 name="Browser_Compatibility">Browser compatibility</h3>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox (Gecko)</th> <th>Chrome</th> <th>Internet Explorer</th> <th>Opera</th> <th>Safari (WebKit)</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatGeckoDesktop("1.0") }}</td> <td>1.0</td> <td>4.0</td> <td>3.5</td> <td>1.0 (85)</td> </tr> </tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table"> <tbody> <tr> <th>Feature</th> <th>Firefox Mobile (Gecko)</th> <th>Android</th> <th>IE Phone</th> <th>Opera Mobile</th> <th>Safari Mobile</th> </tr> <tr> <td>Basic support</td> <td>{{ CompatGeckoMobile("1.9.2") }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> <td>{{ CompatVersionUnknown() }}</td> </tr> </tbody>
</table>
</div>
<h3>Specifications</h3>
<ul> <li><a class="external" href="http://www.w3.org/TR/CSS21/colors.html#propdef-background-color">CSS 2.1 Colors and Backgrounds</a></li> <li><a class="external" href="http://www.w3.org/TR/css3-background/#background-color">CSS 3 Backgrounds &amp; Borders</a></li>
</ul>
<h3>See also</h3>
<ul> <li>{{ CSS_Reference:Background() }}</li> <li><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>
<p>{{ languages( { "de": "de/CSS/background-color", "es": "es/CSS/background-color", "fr": "fr/CSS/background-color", "it": "it/CSS/background-color", "ja": "ja/CSS/background-color", "pl": "pl/CSS/background-color" } ) }}</p>
Revert to this revision