Lesson 47 of 60 – Bootstrap Shadows
78%

Bootstrap Shadows

Bootstrap Shadow Utilities are classes that add or remove box shadows from HTML elements. Shadows can make cards, buttons, images, and other components look more separated from the background.

Note: Bootstrap provides shadow utilities such as shadow, shadow-sm, shadow-lg, and shadow-none. These utilities can be combined with cards, containers, images, buttons, and other Bootstrap components.

1. What Are Shadow Utilities?

Shadow utilities are Bootstrap classes used to add visual depth to elements.

They are useful for:

  • Cards.
  • Navigation elements.
  • Images.
  • Buttons.
  • Modals and panels.
  • Dashboard widgets.
  • Important content sections.

2. The shadow Class

The shadow class adds a standard box shadow to an element.

<div class="shadow p-4">

    Standard Shadow

</div>

It is useful when you want a visible but moderate shadow effect.

3. The shadow-sm Class

The shadow-sm class adds a smaller and more subtle shadow.

<div class="shadow-sm p-4">

    Small Shadow

</div>

It is useful for elements that need a light visual separation from the background.

4. The shadow-lg Class

The shadow-lg class adds a larger and more noticeable shadow.

<div class="shadow-lg p-4">

    Large Shadow

</div>

It can be useful for prominent cards, panels, or other important interface elements.

5. The shadow-none Class

The shadow-none class removes the box shadow from an element.

<div class="shadow shadow-none p-4">

    No Shadow

</div>

It is useful when an existing component has a shadow that you want to remove.

6. Comparing Shadow Sizes

Bootstrap provides three common visible shadow sizes:

  • shadow-sm — small shadow.
  • shadow — standard shadow.
  • shadow-lg — large shadow.
<div class="shadow-sm p-3">
    Small
</div>

<div class="shadow p-3">
    Standard
</div>

<div class="shadow-lg p-3">
    Large
</div>

7. Shadow on a Card

Cards are one of the most common places to use Bootstrap shadows.

<div class="card shadow">

    <div class="card-body">

        <h4>
            Bootstrap Course
        </h4>

        <p>
            Learn Bootstrap step by step.
        </p>

    </div>

</div>

8. Small Shadow on a Card

Use shadow-sm when you want a subtle card effect.

<div class="card shadow-sm">

    <div class="card-body">

        Small Card Shadow

    </div>

</div>

9. Large Shadow on a Card

Use shadow-lg when you want a more prominent card effect.

<div class="card shadow-lg">

    <div class="card-body">

        Large Card Shadow

    </div>

</div>

10. Shadow with Padding

A shadow is often combined with padding so the content does not touch the edges of the element.

<div class="shadow p-4">

    <h4>
        Shadow Box
    </h4>

    <p>
        This box has padding and a shadow.
    </p>

</div>

11. Shadow with Rounded Corners

Shadows and rounded corners can be combined to create modern cards.

<div
class="shadow
rounded
p-4">

    Rounded Shadow Box

</div>

The rounded class controls the corners while shadow controls the box shadow.

12. Shadow with Border

A shadow can be combined with a border.

<div
class="border
shadow
p-4">

    Border and Shadow

</div>

The border defines the edge of the component while the shadow adds visual depth outside it.

13. Shadow on an Image

You can apply a shadow directly to an image.

<img
src="photo.jpg"
class="img-fluid shadow"
alt="Example photo">

This can help visually separate an image from its background.

14. Small Shadow on an Image

Use shadow-sm when you want a subtle image shadow.

<img
src="photo.jpg"
class="img-fluid shadow-sm"
alt="Example photo">

15. Large Shadow on an Image

The shadow-lg class creates a more prominent shadow around an image.

<img
src="photo.jpg"
class="img-fluid shadow-lg"
alt="Example photo">

16. Shadow on Buttons

Shadow utilities can also be applied to buttons.

<button
class="btn btn-primary shadow">

    Start Learning

</button>

Use this effect carefully so that buttons remain visually clear and accessible.

17. Small Button Shadow

A subtle shadow can be applied to a button using shadow-sm.

<button
class="btn btn-success shadow-sm">

    Save

</button>

18. Large Button Shadow

A large shadow can be applied with shadow-lg.

<button
class="btn btn-primary shadow-lg">

    Get Started

</button>

Large shadows should be used carefully because they can make small controls look visually heavy.

19. Shadow on a Container

A container or custom section can use a shadow to visually separate it from the page.

<div
class="container
shadow
p-5">

    <h2>
        Course Section
    </h2>

    <p>
        Bootstrap learning content.
    </p>

</div>

20. Shadow with Background Color

Shadows are often combined with background utilities.

<div
class="bg-light
shadow
p-4">

    Light Background with Shadow

</div>

A suitable background can make the shadow easier to notice.

21. Shadow and Spacing

Spacing utilities can create space between multiple shadowed components.

<div class="shadow p-4 mb-4">

    First Box

</div>

<div class="shadow p-4">

    Second Box

</div>

Here, mb-4 adds bottom margin to the first element.

22. Multiple Shadowed Cards

You can use shadow utilities on multiple cards in a layout.

<div class="row g-4">

    <div class="col-md-4">

        <div class="card shadow-sm">

            <div class="card-body">
                Card One
            </div>

        </div>

    </div>


    <div class="col-md-4">

        <div class="card shadow-sm">

            <div class="card-body">
                Card Two
            </div>

        </div>

    </div>


    <div class="col-md-4">

        <div class="card shadow-sm">

            <div class="card-body">
                Card Three
            </div>

        </div>

    </div>

</div>

23. Shadow and Navigation

A navigation bar can use a shadow to visually separate it from the content below.

<nav
class="navbar
navbar-expand-lg
bg-body-tertiary
shadow-sm">

    <div class="container">

        <a
        class="navbar-brand"
        href="#">

            My Website

        </a>

    </div>

</nav>

A small shadow is often enough for navigation elements.

24. Shadow and Dashboard Cards

Dashboard applications commonly use small shadows on statistic cards.

<div class="card shadow-sm">

    <div class="card-body">

        <h6>
            Total Students
        </h6>

        <h2>
            250
        </h2>

    </div>

</div>

25. Removing a Component Shadow

If an element has a shadow and you want to remove it, use shadow-none.

<div
class="card
shadow-none">

    <div class="card-body">

        No Shadow Card

    </div>

</div>

This is useful when creating a flatter design.

26. Shadow and Responsive Design

Shadow utilities can be combined with responsive Bootstrap classes, but the basic shadow utilities themselves are not breakpoint-specific.

<div
class="shadow-sm
p-4">

    Responsive Card

</div>
Important: If you need a shadow to change at a particular breakpoint, Bootstrap's standard shadow utility classes do not provide responsive variants such as shadow-md. You would need another layout approach or custom CSS for breakpoint-specific shadow behavior.

27. Common Shadow Mistakes

Avoid these common mistakes:

  • Using large shadows on every element.
  • Using shadows where a simple border would be clearer.
  • Creating too much visual depth on a page.
  • Using a shadow without enough spacing around the element.
  • Using strong shadows on small controls unnecessarily.
  • Assuming Bootstrap shadow utilities provide custom colors.
  • Creating breakpoint-specific shadow classes that Bootstrap does not provide by default.

28. Shadow Design Tips

Good shadow usage can make a website easier to understand visually.

  • Use subtle shadows for normal cards.
  • Use larger shadows for important elements.
  • Keep shadow usage consistent across similar components.
  • Combine shadows with appropriate spacing.
  • Use borders when a clear edge is more important than depth.
  • Make sure text and controls remain easy to see.
  • Avoid using shadows on every element of a page.

29. Practical Course Card

The following example creates a simple course card with a small shadow.

<div
class="card
shadow-sm
rounded-3">


    <div class="card-body">


        <h3 class="card-title">

            Bootstrap Course

        </h3>


        <p class="card-text">

            Learn Bootstrap
            step by step.

        </p>


        <span
        class="badge
        bg-success
        rounded-pill">

            60 Lessons

        </span>


        <div class="mt-3">


            <button
            class="btn btn-primary">

                Start Learning

            </button>


        </div>


    </div>


</div>

30. Complete Bootstrap Shadow Example

This complete example combines shadow, border, rounded corners, spacing, background, badges, and buttons.

<div class="container py-5">


    <div
    class="card
    shadow-lg
    border-0
    rounded-4
    overflow-hidden">


        <div
        class="card-header
        bg-primary
        text-white
        p-4">

            <h2 class="mb-0">

                Bootstrap Course

            </h2>

        </div>


        <div class="card-body p-4">


            <span
            class="badge
            bg-success
            rounded-pill
            mb-3">

                60 Lessons

            </span>


            <h3>

                Learn Bootstrap

            </h3>


            <p>

                Learn Bootstrap
                from beginner to
                advanced level.

            </p>


            <button
            class="btn btn-primary
            rounded-pill">

                Start Learning

            </button>


        </div>


    </div>


</div>

Bootstrap Course

60 Lessons

Learn Bootstrap

Learn Bootstrap from beginner to advanced level.

📌 Key Points

  • shadow-sm creates a small shadow.
  • shadow creates a standard shadow.
  • shadow-lg creates a large shadow.
  • shadow-none removes a shadow.
  • Shadows can be used on cards, images, buttons, containers, and navigation elements.
  • Shadows can be combined with borders.
  • Shadows can be combined with rounded corners.
  • Spacing utilities can make shadowed elements look cleaner.
  • Small shadows are useful for subtle visual separation.
  • Large shadows should generally be used for more prominent components.
  • Bootstrap's standard shadow utilities are not breakpoint-specific.
  • Use shadows consistently throughout a website.
  • Avoid excessive shadows because they can make a design visually heavy.
  • Good spacing around a shadow improves the visual result.
  • Shadow utilities do not require custom CSS.
  • Shadows can improve visual hierarchy when used carefully.

🧠 Quick Quiz

Question: Which Bootstrap class adds a large box shadow?