background-color

  • Revision slug: CSS/background-color
  • Revision title: background-color
  • Revision id: 299825
  • Created:
  • Creator: ethertank
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The background-color CSS property 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
  • Media {{ Xref_cssvisual() }}
  • {{ Xref_csscomputed() }} as specified

Syntax

background-color: color | inherit

Values

color
Is a CSS {{ xref_csscolorvalue() }} that describes the uniform color of the background. Even if one or several {{ cssxref("background-image") }} are defined, this color can be affect the rendering, by transparency if the images aren't opaque.

Examples

{{ CSSLiveSample("background-color.html") }}

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

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

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

Specifications

Specification Status Comment
{{ SpecName('CSS3 Backgrounds', '#background-color', 'background-color') }} {{ Spec2('CSS3 Backgrounds') }} Though technically removing the transparent keyword, this doesn't change anything as it has been incorporated as a true {{ xref_csscolorvalue() }}
{{ SpecName('CSS2.1', 'colors.html#propdef-background-color', 'background-color') }} {{ Spec2('CSS2.1') }} No change.
{{ SpecName('CSS1', '#background-color', 'background-color') }} {{ Spec2('CSS1') }}  

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() }}

See also

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>background-color</code> <a href="/en/CSS" title="CSS">CSS</a> property sets the background color of an element, either through a color value or the keyword <code>transparent</code>.</p>
<ul class="cssprop">
  <li><dfn>{{ Xref_cssinitial() }}</dfn> <code>transparent</code></li>
  <li><dfn>Applies to</dfn> all elements</li>
  <li><dfn>{{ Xref_cssinherited() }}</dfn> no</li>
  <li><dfn>Media</dfn> {{ Xref_cssvisual() }}</li>
  <li><dfn>{{ Xref_csscomputed() }}</dfn> as specified</li>
</ul>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval syntaxbox">
background-color: <em>color</em> | <a href="/en/CSS/inherit" title="inherit">inherit</a>
</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <em>color</em></dt>
  <dd>
    Is a CSS {{ xref_csscolorvalue() }} that describes the uniform color of the background. Even if one or several {{ cssxref("background-image") }} are defined, this color can be affect the rendering, by transparency if the images aren't opaque.</dd>
</dl>
<h2 id="Examples" name="Examples">Examples</h2>
<p>{{ CSSLiveSample("background-color.html") }}</p>
<pre class="brush: css; highlight:[2,7,12];">
.exampleOne {
	background-color: teal;
	color: white;
}

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

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

</pre>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS3 Backgrounds', '#background-color', 'background-color') }}</td>
      <td>{{ Spec2('CSS3 Backgrounds') }}</td>
      <td>Though technically removing the <code>transparent</code> keyword, this doesn't change anything as it has been incorporated as a true {{ xref_csscolorvalue() }}</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'colors.html#propdef-background-color', 'background-color') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS1', '#background-color', 'background-color') }}</td>
      <td>{{ Spec2('CSS1') }}</td>
      <td>&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_Compatibility" name="Browser_Compatibility">Browser compatibility</h2>
<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>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ CSS_Reference:Background() }}</li>
  <li><a href="/en/CSS/Multiple_backgrounds" title="en/CSS/Multiple backgrounds">Multiple backgrounds</a></li>
</ul>
Revert to this revision