color

  • Revision slug: Web/CSS/color
  • Revision title: color
  • Revision id: 436547
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{CSSRef}}

Summary

The CSS color property sets the foreground color of an element's text content, and its decorations. It doesn't affect any other characteristic of the element; it should really be called text-color and would have been named so, save for historical reasons and its appearance in CSS Level 1.

Note that the color value must be a uniform color, which may include a transparency value from CSS3 onwards. It can't be a {{xref_cssgradient}} which is an {{xref_cssimage}} in CSS.

{{cssbox("color")}}#ff6633

Syntax

Formal syntax: {{csssyntax("color")}}
color: red;                     // A CSS Level 1 color.
color: orange;                  // The only color added in CSS Level 2 (Revision 1).
color: antiquewhite;            // A CSS Level 3 color, sometimes called a SVG or X11 color.
color: #0f0;                    // The color 'lime' defined using the 3-character dash notation.
color: #00ff00;                 // The color 'lime' defined using the 6-character dash notation.
color: rgba( 34, 12, 64, 0.3);  // A color defined using the available functional notations.
color: currentColor;            // The special keyword representing the color's value of its direct ancestor.

color: inherit;

Values

<color>
Is a {{Xref_csscolorvalue}} value giving the color of the textual elements of the element.

Examples

The following are all ways to make the element's text red:

element { color: red }
element { color: #f00 }
element { color: #ff0000 }
element { color: rgb(255,0,0) }
element { color: rgb(100%, 0%, 0%) }
element { color: hsl(0, 100%, 50%) }

/* 50% translucent */
element { color: rgba(255, 0, 0, 0.5) } 
element { color: hsla(0, 100%, 50%, 0.5) }

Specifications

Specification Status Comment
{{SpecName('CSS3 Transitions', '#animatable-css', 'color')}} {{Spec2('CSS3 Transitions')}} Defines color as animatable.
{{SpecName('CSS3 Colors', '#color', 'color')}} {{Spec2('CSS3 Colors')}} Deprecated system-colors; added SVG colors; added rgba(), hsl(), hsla() functional notation.
{{SpecName('CSS2.1', 'colors.html#colors', 'color')}} {{Spec2('CSS2.1')}} Added the orange color and the system-colors.
{{SpecName('CSS1', '#color', 'color')}} {{Spec2('CSS1')}}  

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{CompatGeckoDesktop("1")}} 3.0 3.5 1.0
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support 1.0 {{CompatGeckoMobile("1")}} 6.0 6.0 1.0

See also

  • The {{Xref_csscolorvalue}} data type

Revision Source

<div>
  {{CSSRef}}</div>
<h2 id="Summary">Summary</h2>
<p>The <a href="/en-US/docs/Web/CSS">CSS</a> <code>color</code> property sets the foreground <a href="/en-US/docs/Web/CSS/color_value">color</a> of an element's text content, and its <a href="/en-US/docs/Web/CSS/text-decoration">decorations</a>. It doesn't affect any other characteristic of the element; it should really be called <code>text-color</code> and would have been named so, save for historical reasons and its appearance in CSS Level 1.</p>
<p>Note that the color value must be a uniform color, which may include a transparency value from CSS3 onwards. It can't be a {{xref_cssgradient}} which is an {{xref_cssimage}} in CSS.</p>
<div>
  {{cssbox("color")}}#ff6633</div>
<h2 id="Syntax">Syntax</h2>
<pre class="twopartsyntaxbox">
<a href="/en-US/docs/Web/CSS/Value_definition_syntax">Formal syntax</a>: {{csssyntax("color")}}</pre>
<pre>
color: red;                     // A CSS Level 1 color.
color: <code>orange;</code>                  // The only color added in CSS Level 2 (Revision 1).
color: <code>antiquewhite;</code>            // A CSS Level 3 color, sometimes called a SVG or X11 color.
color: #0f0;                    // The color 'lime' defined using the 3-character <em>dash</em> notation.
color: #00ff00;                 // The color 'lime' defined using the 6-character <em>dash</em> notation.
color: rgba( 34, 12, 64, 0.3);  // A color defined using the available functional notations.
color: currentColor;            // The special keyword representing the color's value of its direct ancestor.

color: inherit;
</pre>
<h3 id="Values">Values</h3>
<dl>
  <dt>
    <code>&lt;color&gt;</code></dt>
  <dd>
    Is a {{Xref_csscolorvalue}} value giving the color of the textual elements of the element.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>The following are all ways to make the element's text red:</p>
<pre class="brush: css">
element { color: red }
element { color: #f00 }
element { color: #ff0000 }
element { color: rgb(255,0,0) }
element { color: rgb(100%, 0%, 0%) }
element { color: hsl(0, 100%, 50%) }

/* 50% translucent */
element { color: rgba(255, 0, 0, 0.5) } 
element { color: hsla(0, 100%, 50%, 0.5) }
</pre>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr style="background-color: rgb(255, 204, 255);">
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{SpecName('CSS3 Transitions', '#animatable-css', 'color')}}</td>
      <td>{{Spec2('CSS3 Transitions')}}</td>
      <td>Defines <code>color</code> as animatable.</td>
    </tr>
    <tr>
      <td>{{SpecName('CSS3 Colors', '#color', 'color')}}</td>
      <td>{{Spec2('CSS3 Colors')}}</td>
      <td>Deprecated system-colors; added SVG colors; added <code>rgba()</code>, <code>hsl()</code>, <code>hsla()</code> functional notation.</td>
    </tr>
    <tr style="vertical-align: top;">
      <td style="vertical-align: top;">{{SpecName('CSS2.1', 'colors.html#colors', 'color')}}</td>
      <td style="vertical-align: top;">{{Spec2('CSS2.1')}}</td>
      <td style="vertical-align: top;">Added the orange color and the system-colors.</td>
    </tr>
    <tr>
      <td style="vertical-align: top;">{{SpecName('CSS1', '#color', 'color')}}</td>
      <td style="vertical-align: top;">{{Spec2('CSS1')}}</td>
      <td style="vertical-align: top;">&nbsp;</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<div>
  {{CompatibilityTable}}</div>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoDesktop("1")}}</td>
        <td>3.0</td>
        <td>3.5</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoMobile("1")}}</td>
        <td>6.0</td>
        <td>6.0</td>
        <td>1.0</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="See_also">See also</h2>
<ul>
  <li>The {{Xref_csscolorvalue}} data type</li>
</ul>
Revert to this revision