Box shadows add depth and focus to elements on a webpage. They make things look like they are lifted off the page.
Box shadow utilities in Tailwind
Start learning this pattern below
Jump into concepts and practice - no test required
or
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Syntax
Tailwind
shadow-{size}
Examples:
shadow-sm
shadow-md
shadow-lg
shadow-xl
shadow-2xl
shadow-inner
shadow-noneUse shadow-none to remove shadows.
Sizes go from small (shadow-sm) to very large (shadow-2xl).
Examples
Tailwind
<div class="shadow-sm p-4">Small shadow</div>Tailwind
<div class="shadow-lg p-4">Large shadow</div>Tailwind
<div class="shadow-inner p-4">Inner shadow</div>Tailwind
<div class="shadow-none p-4">No shadow</div>Sample Program
This page shows different Tailwind box shadow utilities on white boxes with some padding and rounded corners. The background is light gray to see the shadows clearly.
Tailwind
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Tailwind Box Shadow Example</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="bg-gray-100 flex flex-col items-center gap-6 p-8 min-h-screen"> <h1 class="text-2xl font-bold mb-4">Tailwind Box Shadow Utilities</h1> <div class="shadow-sm bg-white p-6 rounded">Small shadow</div> <div class="shadow-md bg-white p-6 rounded">Medium shadow</div> <div class="shadow-lg bg-white p-6 rounded">Large shadow</div> <div class="shadow-xl bg-white p-6 rounded">Extra large shadow</div> <div class="shadow-2xl bg-white p-6 rounded">2XL shadow</div> <div class="shadow-inner bg-white p-6 rounded">Inner shadow</div> <div class="shadow-none bg-white p-6 rounded">No shadow</div> </body> </html>
Important Notes
Box shadows help users see which parts of the page are clickable or important.
Use shadows sparingly to keep the design clean and not too busy.
Test shadows on different screen sizes to ensure they look good everywhere.
Summary
Box shadow utilities add depth by creating shadows around or inside elements.
Tailwind offers multiple sizes and an option for inner shadows.
Use shadow-none to remove shadows when needed.
Practice
1. What does the Tailwind class
shadow-lg do to an element?easy
Solution
Step 1: Understand the purpose of
Theshadow-lgshadow-lgclass in Tailwind adds a large box shadow around an element, making it appear elevated.Step 2: Compare with other shadow classes
Unlikeshadow-nonewhich removes shadows, orshadow-innerwhich adds inner shadows,shadow-lgadds a bigger outer shadow.Final Answer:
Adds a large shadow around the element to create depth -> Option CQuick Check:
shadow-lgmeans large shadow [OK]
Hint: Remember: 'lg' means large shadow outside [OK]
Common Mistakes:
- Confusing
shadow-lgwithshadow-inner - Thinking it removes shadows instead of adding
- Assuming it changes background color
2. Which Tailwind class correctly removes any box shadow from an element?
easy
Solution
Step 1: Recall Tailwind class for removing shadows
Tailwind usesshadow-noneto remove all box shadows from an element.Step 2: Verify other options
Classes likeshadow-remove,no-shadow, andshadow-cleardo not exist in Tailwind's box shadow utilities.Final Answer:
shadow-none -> Option AQuick Check:
shadow-noneremoves shadows [OK]
Hint: Use
shadow-none to clear shadows [OK]Common Mistakes:
- Using non-existent classes like
shadow-remove - Confusing with background or border classes
- Assuming
no-shadowis valid
3. What visual effect will the following Tailwind classes produce?
<div class="shadow-inner shadow-md p-4">Content</div>
medium
Solution
Step 1: Analyze the classes
shadow-innerandshadow-mdshadow-inneradds an inner shadow inside the element.shadow-mdadds a medium outer shadow. Sinceshadow-mdcomes aftershadow-innerin the class attribute, Tailwind applies it later and it overrides the box-shadow property, resulting in a medium outer shadow.Step 2: Consider padding and shadow layering
Thep-4adds padding inside the element around the content.Final Answer:
A medium-sized outer shadow with padding around the content -> Option AQuick Check:
shadow-mdoverrides as last shadow class [OK]
Hint: Last shadow class in class attribute wins [OK]
Common Mistakes:
- Assuming both inner and outer shadows show simultaneously
- Ignoring padding effect on shadow placement
- Thinking shadows cancel each other out
4. You want to add a small shadow around a button but accidentally use
shadow-inner instead of shadow-sm. What is the main visual difference?medium
Solution
Step 1: Understand
shadow-innervsshadow-smshadow-inneradds a shadow inside the element edges, creating an inset effect.shadow-smadds a small outer shadow around the element.Step 2: Identify the visual impact of using
Usingshadow-innershadow-innerinstead ofshadow-smmeans the shadow appears inside the button edges, not outside, changing the intended look.Final Answer:
The button will have a shadow inside its edges, not outside -> Option BQuick Check:
shadow-inner= inside shadow, not outside [OK]
Hint:
shadow-inner means inside shadow, not outside [OK]Common Mistakes:
- Thinking
shadow-inneradds outer shadow - Expecting no shadow to appear
- Confusing shadow sizes with shadow placement
5. You want a card with a subtle shadow that disappears on small screens but appears on medium and larger screens. Which Tailwind classes achieve this?
hard
Solution
Step 1: Understand responsive prefixes in Tailwind
Classes prefixed withmd:apply at medium screen sizes and above. Without prefix, classes apply to all screen sizes.Step 2: Identify the correct class combination
shadow-none md:shadow-smmeans no shadow on small screens, and a small shadow starting at medium screens. This matches the requirement.Step 3: Check other options
shadow-sm md:shadow-nonereverses the logic, showing shadow on small screens and none on medium.shadow-md sm:shadow-noneusessm:which applies at small screens, not medium.shadow-inner md:shadow-lgusesshadow-innerand large shadow which is not subtle.Final Answer:
shadow-none md:shadow-sm-> Option DQuick Check:
Useshadow-nonethenmd:shadow-smfor responsive shadows [OK]
Hint: Use
shadow-none then md:shadow-sm for responsive shadows [OK]Common Mistakes:
- Mixing up responsive prefixes like
sm:andmd: - Applying shadow classes in wrong order
- Using inner shadows instead of outer for subtle effect
