<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ #box-shadow - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ #box-shadow - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Sun, 31 May 2026 14:26:45 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/box-shadow/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Box Shadow CSS Tutorial – How to Add a Drop Shadow to Any HTML Element ]]>
                </title>
                <description>
                    <![CDATA[ By Joe Liang We can add a drop shadow to any HTML element using the CSS property box-shadow. Here's how. ##Adding a Basic Drop Shadow Let's first set up some basic HTML elements to add our drop shadows to: ```html Box1 Box2 Box3 Then add some basic ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/css-tutorial-drop-shadow/</link>
                <guid isPermaLink="false">66d45f65706b9fb1c166b989</guid>
                
                    <category>
                        <![CDATA[ #box-shadow ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS ]]>
                    </category>
                
                    <category>
                        <![CDATA[ css properties ]]>
                    </category>
                
                    <category>
                        <![CDATA[ CSS3 ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Pure CSS ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 18 May 2020 13:00:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/feature.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Joe Liang</p>
<p>We can add a drop shadow to any HTML element using the CSS property <code>box-shadow</code>. Here's how.</p>
<p>##Adding a Basic Drop Shadow</p>
<p>Let's first set up some basic HTML elements to add our drop shadows to:</p>
<p>```html</p>
<div id="box1" class="box">Box1</div>
<div id="box2" class="box">Box2</div>
<div id="box3" class="box">Box3</div>

<p>Then add some basic CSS:</p>
<p>```css
p {
    padding: 10px;
}
.box {
    padding: 20px;
    width: 50%;
    margin: 30px auto;
    background: #000;
    color: #fff;
}</p>
<p>The result is just three black boxes that will be easy for us to add drop shadows to by calling their unique id's:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/html-elements-1.png" alt="HTML elements setup" width="600" height="400" loading="lazy">
<em>HTML elements setup</em></p>
<p>To add a basic drop shadow, let's use the <code>box-shadow</code> property on the Box 1:</p>
<p>```css
/<em> offset-x | offset-y | color </em>/</p>
<p>#box1 {
    box-shadow: 6px 12px yellow;
}</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/box1.png" alt="Adding a basic drop shadow to Box 1" width="600" height="400" loading="lazy">
<em>Adding a basic drop shadow to Box 1</em></p>
<p>We have 3 parameters here. The first 2 are, respectively, the x-offset and y-offset. They set the location of the drop shadow.</p>
<p>The offset is relative to the origin, which in HTML is always the top left corner of an element. A positive x-offset will move the shadow to the right, and a positive y-offset will move the shadow downwards.</p>
<p>The third parameter is the color of your drop shadow.</p>
<p>Keep in mind that although we used <code>&lt;div&gt;</code> elements here, the <code>box-shadow</code> property can be applied to any other HTML element as well.</p>
<p>##Adding a Blur Radius</p>
<p>If we want the shadow to look a little more realistic, we will want to experiment with the <code>blur-radius</code> parameter.</p>
<p>This parameter controls how much to blur the shadow such that it becomes bigger and lighter. Let's apply it to Box 2:</p>
<p>```css
/<em> offset-x | offset-y | blur-radius | color </em>/</p>
<p>#box2 {
    box-shadow: 6px 12px 4px red;
}</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/box2-blur.png" alt="Adding a blur radius to Box 2" width="600" height="400" loading="lazy">
<em>Adding a blur radius to Box 2</em></p>
<p>The value of 4px sets the radius of the blur to apply to our drop shadow.</p>
<p>##Adding a Spread Radius</p>
<p>If we want to control the size of the shadow, we can use the <code>spread-radius</code> parameter which controls how much a shadow grows or shrinks.</p>
<p>Let's add a spread radius of 8px to Box 2:</p>
<p>```css
/<em> offset-x | offset-y | blur-radius | spread-radius | color </em>/</p>
<p>#box2 {
    box-shadow: 6px 12px 4px 8px red;
}</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/box2-blur-and-spread.png" alt="Adding a spread radius in addition to a blur to Box 2" width="600" height="400" loading="lazy">
<em>Adding a spread radius in addition to a blur to Box 2</em></p>
<p>Remember the order of these parameters!</p>
<p>##Combining Multiple Shadows in a Single Property</p>
<p>If we want to get fancy, we can add multiple drop shadows to an element using a single <code>box-shadow</code> property.</p>
<p>Let's do that with Box 3 by simultaneously adding a blue and green drop shadow:</p>
<p>```css
/<em> Any number of shadows, separated by commas </em>/</p>
<p>#box3 {
    box-shadow: 6px 12px 2px 2px blue, -6px -12px 2px 2px green;
}</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/box3.png" alt="combine multiple drop shadows" width="600" height="400" loading="lazy">
<em>Adding multiple drop shadows to Box 3</em></p>
<p>##Bonus: Create an Inset Shadow</p>
<p>While it will not create a drop shadow, the <code>inset</code> parameter can also be used with the <code>box-shadow</code> property.</p>
<p>As the name suggests, this parameter creates an inset shadow (i.e. shadow inside a box).</p>
<p>The <code>inset</code> parameter can be placed either at the beginning or the end of the 
<code>box-shadow</code> property. Here we demonstrate its use with a <code>blockquote</code> element.</p>
<p>HTML:</p>
<p>```html</p>
<blockquote>
  <q>The key to success is to start before you're ready.</q>
  <p>— Marie Forleo</p>
</blockquote>

<p>CSS:</p>
<p>```css
blockquote {
  width: 50%;
  margin: 50px auto;
  padding: 20px;
  font-size: 24px;
  box-shadow: inset 10px 5px black;
}</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/blockquote.png" alt="Create an inset shadow" width="600" height="400" loading="lazy">
<em>Create an inset shadow</em></p>
<p>Of course you can add some blur and spread to enhance the shadow, or even multiple shadows:</p>
<p>```css
 box-shadow: inset 10px 5px 25px 5px black, 5px 5px 12px 2px black;</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2020/05/blockquote-enhanced.png" alt="Inset shadow combined with drop shadow" width="600" height="400" loading="lazy">
<em>Inset shadow combined with drop shadow</em></p>
<p>With the <code>box-shadow</code> property, we can easily make elements on a web page stand out to create a nice 3D lighting effect.</p>
<p>If you want to do some experimenting yourself, here's a <a target="_blank" href="https://codepen.io/1000mileworld/pen/dyYeggy">code pen</a> I created with the examples used in this tutorial.</p>
<p>Play around and see what you can come up with!</p>
<p>##Want to See More Web Development Tips and Knowledge?</p>
<ul>
<li><a target="_blank" href="https://1000mileworld.com/#post">Subscribe</a> to my weekly newsletter</li>
<li>Visit my blog at  <a target="_blank" href="https://1000mileworld.com/">1000 Mile World</a></li>
<li><a target="_blank" href="https://twitter.com/1000mileworld">Follow me</a> on Twitter</li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
