box-shadow

  • Revision slug: Web/CSS/box-shadow
  • Revision title: box-shadow
  • Revision id: 460449
  • Created:
  • Creator: NidalR
  • Is current revision? No
  • Comment minor: fixed broken url to <length>

Revision Content

{{ CSSRef }}

Summary

Box-shadow generator

Interactive tool allowing to generate box-shadow.

The box-shadow CSS property describes one or more shadow effects as a comma-separated list. It allows casting a drop shadow from the frame of almost any element. If a {{ cssxref("border-radius") }} is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple text shadows (the first specified shadow is on top).

{{cssbox("box-shadow")}}

Syntax

Formal syntax: none | [inset? && [ <offset-x> <offset-y> <blur-radius>? <spread-radius>? <color>? ] ]#

Values

inset
If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content).
The presence of the inset keyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content.
<offset-x> <offset-y>
These are two {{ Xref_csslength }} values to set the shadow offset. <offset-x> specifies the horizontal distance. Negative values place the shadow to the left of the element. <offset-y> specifies the vertical distance. Negative values place the shadow above the element. See {{ Xref_csslength }} for possible units.
If both values are 0, the shadow is placed behind the element (and may generate a blur effect if <blur-radius> and/or <spread-radius> is set).
<blur-radius>
This is a third {{ Xref_csslength }} value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be 0 (the shadow's edge is sharp).
<spread-radius>
This is a fourth {{ Xref_csslength }} value. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be 0 (the shadow will be the same size as the element).
<color>
See {{ Xref_csscolorvalue }} values for possible keywords and notations.
If not specified, the color used depends on the browser - it is usually the value of the {{ cssxref("color") }} property, but note that Safari currently paints a transparent shadow in this case.

Live examples

box-shadow: 60px -16px teal;
box-shadow: 10px 5px 5px black;
box-shadow: 3px 3px red, -1em 0 0.4em olive;
box-shadow: inset 5em 1em gold;
box-shadow: 0 0 1em gold;
box-shadow: inset 0 0 1em gold;

Specifications

Specification Status Comment
{{ SpecName('CSS3 Backgrounds', '#box-shadow', 'box-shadow') }} {{ Spec2('CSS3 Backgrounds') }}  

Browser compatibility

{{ CompatibilityTable }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 10.0
1.0{{ property_prefix("-webkit") }}
{{ CompatGeckoDesktop("2.0") }}
{{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}
9.0 (See note) 10.5 5.1 (WebKit 534)
3.0 (WebKit 522){{ property_prefix("-webkit") }}
Multiple shadows 10.0
1.0{{ property_prefix("-webkit") }}
{{ CompatGeckoDesktop("2.0") }}
{{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}
9.0 10.5 5.1 (WebKit 534)
3.0 (WebKit 522){{ property_prefix("-webkit") }}
inset keyword 10.0
4.0{{ property_prefix("-webkit") }}
{{ CompatGeckoDesktop("2.0") }}
{{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}
9.0 10.5 5.1 (WebKit 534)
5.0 (WebKit 533){{ property_prefix("-webkit") }}
Spread radius 10.0
4.0{{ property_prefix("-webkit") }}
{{ CompatGeckoDesktop("2.0") }}
{{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}
9.0 10.5 5.1 (WebKit 534)
5.0 (WebKit 533){{ property_prefix("-webkit") }}
Feature iOS Safari Opera Mini Opera Mobile Android Browser
Basic support

5.0
{{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}

{{ CompatUnknown }} {{ CompatUnknown }} {{ CompatUnknown }}
Multiple shadows 5.0
{{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}
{{ CompatUnknown }} {{ CompatUnknown }} {{ CompatUnknown }}
inset keyword 5.0
{{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}
{{ CompatUnknown }} {{ CompatUnknown }} {{ CompatUnknown }}
Spread radius 5.0
{{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}
{{ CompatUnknown }} {{ CompatUnknown }} {{ CompatUnknown }}

Notes

  • Since version 5.5, Internet Explorer supports Microsoft's DropShadow and Shadow Filter. You can use this proprietary extension to cast a drop shadow (though the syntax and the effect are different from CSS3).
  • Shadows affect layout in older Gecko, Presto, and WebKit; e.g. if you cast an outer shadow to a box with a width of 100%, you'll see a scrollbar.
  • Gecko 13 (Firefox 13) removed support for -moz-box-shadow. Since then, only the unprefixed version is supported.
  • In order to get box-shadow in IE9 or later, you need to set {{ cssxref("border-collapse") }} to separate.

Revision Source

<div>
  {{ CSSRef }}</div>
<h2 id="Summary" name="Summary">Summary</h2>
<div class="callout-box">
  <p><strong>Box-shadow generator</strong></p>
  <p><a href="/en-US/docs/Web/CSS/Tools/Box-shadow_generator" title="/en-US/docs/Web/CSS/Tools/Box-shadow_generator">Interactive tool</a> allowing to generate box-shadow.</p>
</div>
<p>The <code>box-shadow</code> CSS property describes one or more shadow effects as a comma-separated list. It allows casting a drop shadow from the frame of almost any element. If a {{ cssxref("border-radius") }} is specified on the element with a box shadow, the box shadow takes on the same rounded corners. The z-ordering of multiple box shadows is the same as multiple <a href="/en-US/CSS/text-shadow" title="text-shadow">text shadows</a> (the first specified shadow is on top).</p>
<p>{{cssbox("box-shadow")}}</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox">
<a href="/en-US/docs/CSS/Value_definition_syntax" title="CSS/Value_definition_syntax">Formal syntax</a>: none | [inset? &amp;&amp; [ &lt;offset-x&gt; &lt;offset-y&gt; &lt;blur-radius&gt;? &lt;spread-radius&gt;? &lt;color&gt;? ] ]#</pre>
<h3 id="Values" name="Values">Values</h3>
<dl>
  <dt>
    <code>inset</code></dt>
  <dd>
    If not specified (default), the shadow is assumed to be a drop shadow (as if the box were raised above the content).<br />
    The presence of the <code>inset</code> keyword changes the shadow to one inside the frame (as if the content was depressed inside the box). Inset shadows are drawn inside the border (even transparent ones), above the background, but below content.</dd>
  <dt>
    <code>&lt;offset-x&gt;</code> <code>&lt;offset-y&gt;</code></dt>
  <dd>
    These are two {{ Xref_csslength }} values to set the shadow offset. <code>&lt;offset-x&gt;</code> specifies the horizontal distance. Negative values place the shadow to the left of the element. <code>&lt;offset-y&gt;</code> specifies the vertical distance. Negative values place the shadow above the element. See {{ Xref_csslength }} for possible units.<br />
    If both values are <code>0</code>, the shadow is placed behind the element (and may generate a blur effect if <code>&lt;blur-radius&gt;</code> and/or <code>&lt;spread-radius&gt;</code> is set).</dd>
  <dt>
    <code>&lt;blur-radius&gt;</code></dt>
  <dd>
    This is a third {{ Xref_csslength }} value. The larger this value, the bigger the blur, so the shadow becomes bigger and lighter. Negative values are not allowed. If not specified, it will be <code>0</code> (the shadow's edge is sharp).</dd>
  <dt>
    <code>&lt;spread-radius&gt;</code></dt>
  <dd>
    This is a fourth {{ Xref_csslength }} value. Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink. If not specified, it will be <code>0</code> (the shadow will be the same size as the element).</dd>
  <dt>
    <code>&lt;color&gt;</code></dt>
  <dd>
    See {{ Xref_csscolorvalue }} values for possible keywords and notations.<br />
    If not specified, the color used depends on the browser - it is usually the value of the {{ cssxref("color") }} property, but note that Safari currently paints a transparent shadow in this case.</dd>
</dl>
<h2 id="Live_examples" name="Live_examples">Live examples</h2>
<ul>
  <li><a class="external" href="http://www.elektronotdienst-nuernberg.de/bugs/box-shadow_inset.html" title="http://www.elektronotdienst-nuernberg.de/bugs/box-shadow_inset.html">box-shadow test</a></li>
  <li><a class="external" href="http://markusstange.wordpress.com/2009/02/15/fun-with-box-shadows/" title="http://markusstange.wordpress.com/2009/02/15/fun-with-box-shadows/">box-shadow tutorial and examples</a></li>
</ul>
<pre style="-moz-box-shadow: 60px -16px teal; -webkit-box-shadow: 60px -16px teal; box-shadow: 60px -16px teal; float: left; margin: 1em;">
box-shadow: 60px -16px teal;</pre>
<pre style="-moz-box-shadow: 10px 5px 5px black; -webkit-box-shadow: 10px 5px 5px black; box-shadow: 10px 5px 5px black; float: left; margin: 1em;">
box-shadow: 10px 5px 5px black;</pre>
<pre style="-moz-box-shadow: 3px 3px red, -1em 0pt 0.4em olive; -webkit-box-shadow: 3px 3px red, -1em 0 0.4em olive; box-shadow: 3px 3px red, -1em 0 0.4em olive; float: left; margin: 1em;">
box-shadow: 3px 3px red, -1em 0 0.4em olive;</pre>
<pre style="-moz-box-shadow: 5em 1em gold inset; -webkit-box-shadow: inset 5em 1em gold; box-shadow: inset 5em 1em gold; float: left; margin: 1em;">
box-shadow: inset 5em 1em gold;</pre>
<pre style="-moz-box-shadow: 0 0 1em gold; -webkit-box-shadow: 0 0 1em gold; box-shadow: 0 0 1em gold; float: left; margin: 1em;">
box-shadow: 0 0 1em gold;</pre>
<pre style="-moz-box-shadow: 0 0 1em gold inset; -webkit-box-shadow: inset 0 0 1em gold; box-shadow: inset 0 0 1em gold; float: left; margin: 1em;">
box-shadow: inset 0 0 1em gold;</pre>
<h2 class="cleared" id="Specifications" name="Specifications">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', '#box-shadow', 'box-shadow') }}</td>
      <td>{{ Spec2('CSS3 Backgrounds') }}</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>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>10.0<br />
          1.0{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatGeckoDesktop("2.0") }}<br />
          {{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}</td>
        <td>9.0 (See note)</td>
        <td>10.5</td>
        <td>5.1 (WebKit 534)<br />
          3.0 (WebKit 522){{ property_prefix("-webkit") }}</td>
      </tr>
      <tr>
        <td>Multiple shadows</td>
        <td>10.0<br />
          1.0{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatGeckoDesktop("2.0") }}<br />
          {{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}</td>
        <td>9.0</td>
        <td>10.5</td>
        <td>5.1 (WebKit 534)<br />
          3.0 (WebKit 522){{ property_prefix("-webkit") }}</td>
      </tr>
      <tr>
        <td><code>inset</code> keyword</td>
        <td>10.0<br />
          4.0{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatGeckoDesktop("2.0") }}<br />
          {{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}</td>
        <td>9.0</td>
        <td>10.5</td>
        <td>5.1 (WebKit 534)<br />
          5.0 (WebKit 533){{ property_prefix("-webkit") }}</td>
      </tr>
      <tr>
        <td>Spread radius</td>
        <td>10.0<br />
          4.0{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatGeckoDesktop("2.0") }}<br />
          {{ CompatGeckoDesktop("1.9.1") }}{{ property_prefix("-moz") }}</td>
        <td>9.0</td>
        <td>10.5</td>
        <td>5.1 (WebKit 534)<br />
          5.0 (WebKit 533){{ property_prefix("-webkit") }}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>iOS Safari</th>
        <th>Opera Mini</th>
        <th>Opera Mobile</th>
        <th>Android Browser</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>
          <p>5.0<br />
            {{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}</p>
        </td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
      </tr>
      <tr>
        <td>Multiple shadows</td>
        <td>5.0<br />
          {{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
      </tr>
      <tr>
        <td><code>inset</code> keyword</td>
        <td>5.0<br />
          {{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
      </tr>
      <tr>
        <td>Spread radius</td>
        <td>5.0<br />
          {{ CompatVersionUnknown }}{{ property_prefix("-webkit") }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
        <td>{{ CompatUnknown }}</td>
      </tr>
    </tbody>
  </table>
</div>
<h3 id="Notes">Notes</h3>
<ul>
  <li>Since version 5.5, Internet Explorer supports Microsoft's <a class="external" href="http://msdn.microsoft.com/en-us/library/ms532985%28VS.85,loband%29.aspx" title="http://msdn.microsoft.com/en-us/library/ms532985(VS.85,loband).aspx">DropShadow</a> and <a class="external" href="http://msdn.microsoft.com/en-us/library/ms533086%28VS.85,loband%29.aspx" title="http://msdn.microsoft.com/en-us/library/ms533086(VS.85,loband).aspx">Shadow</a> Filter. You can use this proprietary extension to cast a drop shadow (though the syntax and the effect are different from CSS3).</li>
  <li>Shadows affect layout in older Gecko, Presto, and WebKit; e.g. if you cast an outer shadow to a box with a <code>width</code> of <code>100%</code>, you'll see a scrollbar.</li>
  <li>Gecko 13 (Firefox 13) removed support for <code>-moz-box-shadow</code>. Since then, only the unprefixed version is supported.</li>
  <li>In order to get <code>box-shadow</code> in IE9 or later, you need to set {{ cssxref("border-collapse") }} to <code>separate</code>.</li>
</ul>
Revert to this revision