Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Box Shadow Utilities with Tailwind CSS
📖 Scenario: You are building a simple product card for an online store. You want to add different shadow effects to the card to make it look nice and stand out on the page.
🎯 Goal: Create a product card using Tailwind CSS that uses box shadow utilities to add subtle and strong shadows. The card should have a title, a description, and a button. The shadows should change the look of the card.
📋 What You'll Learn
Use Tailwind CSS box shadow utilities to style the card
Create a card container with a subtle shadow using shadow-sm
Add a button inside the card with a stronger shadow using shadow-lg
Use semantic HTML elements for accessibility
Make sure the card is responsive and looks good on small and large screens
💡 Why This Matters
🌍 Real World
Box shadows are used in web design to create depth and highlight important elements like cards, buttons, and modals. This makes interfaces more visually appealing and easier to understand.
💼 Career
Knowing how to use Tailwind CSS utilities for shadows helps front-end developers quickly build attractive and accessible UI components without writing custom CSS.
Progress0 / 4 steps
1
Create the basic HTML structure for the product card
Write the HTML code to create a <section> element with a class max-w-sm mx-auto p-4 bg-white rounded. Inside it, add an <h2> with the text "Product Name" and a <p> with the text "This is a great product.".
Tailwind
Hint
Use a <section> for the card container. Add a heading and a paragraph inside it.
2
Add a subtle shadow to the card container
Add the Tailwind CSS class shadow-sm to the <section> element to give it a subtle box shadow.
Tailwind
Hint
Simply add shadow-sm to the existing class list on the <section>.
3
Add a button with a strong shadow inside the card
Inside the <section>, add a <button> element with the text "Buy Now". Give the button the Tailwind CSS classes mt-4 px-4 py-2 bg-blue-600 text-white rounded shadow-lg to style it and add a strong shadow.
Tailwind
Hint
Use the shadow-lg class on the button to create a stronger shadow effect.
4
Make the card responsive and accessible
Add the attribute aria-label="Product card" to the <section> element. Also, add the Tailwind CSS class sm:max-w-md to the <section> to make it wider on small screens and above.
Tailwind
Hint
Use aria-label for accessibility and add sm:max-w-md to the class list for responsiveness.
Practice
(1/5)
1. What does the Tailwind class shadow-lg do to an element?
easy
A. Adds a small inner shadow inside the element
B. Removes any shadow from the element
C. Adds a large shadow around the element to create depth
D. Changes the element's background color to gray
Solution
Step 1: Understand the purpose of shadow-lg
The shadow-lg class in Tailwind adds a large box shadow around an element, making it appear elevated.
Step 2: Compare with other shadow classes
Unlike shadow-none which removes shadows, or shadow-inner which adds inner shadows, shadow-lg adds a bigger outer shadow.
Final Answer:
Adds a large shadow around the element to create depth -> Option C
Quick Check:
shadow-lg means large shadow [OK]
Hint: Remember: 'lg' means large shadow outside [OK]
Common Mistakes:
Confusing shadow-lg with shadow-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
A. shadow-none
B. shadow-remove
C. no-shadow
D. shadow-clear
Solution
Step 1: Recall Tailwind class for removing shadows
Tailwind uses shadow-none to remove all box shadows from an element.
Step 2: Verify other options
Classes like shadow-remove, no-shadow, and shadow-clear do not exist in Tailwind's box shadow utilities.
Final Answer:
shadow-none -> Option A
Quick Check:
shadow-none removes 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-shadow is valid
3. What visual effect will the following Tailwind classes produce?
A. A medium-sized outer shadow with padding around the content
B. A medium-sized inner shadow inside the element with padding
C. No shadow visible because inner and outer shadows cancel out
D. A large outer shadow with no padding
Solution
Step 1: Analyze the classes shadow-inner and shadow-md
shadow-inner adds an inner shadow inside the element. shadow-md adds a medium outer shadow. Since shadow-md comes after shadow-inner in 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
The p-4 adds padding inside the element around the content.
Final Answer:
A medium-sized outer shadow with padding around the content -> Option A
Quick Check:
shadow-md overrides 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
A. The button will have a small outer shadow as intended
B. The button will have a shadow inside its edges, not outside
C. No shadow will appear on the button
D. The button's shadow will be very large and blurry
Solution
Step 1: Understand shadow-inner vs shadow-sm
shadow-inner adds a shadow inside the element edges, creating an inset effect. shadow-sm adds a small outer shadow around the element.
Step 2: Identify the visual impact of using shadow-inner
Using shadow-inner instead of shadow-sm means 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 B
Quick Check:
shadow-inner = inside shadow, not outside [OK]
Hint: shadow-inner means inside shadow, not outside [OK]
Common Mistakes:
Thinking shadow-inner adds 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
A. shadow-sm md:shadow-none
B. shadow-md sm:shadow-none
C. shadow-inner md:shadow-lg
D. shadow-none md:shadow-sm
Solution
Step 1: Understand responsive prefixes in Tailwind
Classes prefixed with md: 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-sm means 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-none reverses the logic, showing shadow on small screens and none on medium. shadow-md sm:shadow-none uses sm: which applies at small screens, not medium. shadow-inner md:shadow-lg uses shadow-inner and large shadow which is not subtle.
Final Answer:
shadow-none md:shadow-sm -> Option D
Quick Check:
Use shadow-none then md:shadow-sm for responsive shadows [OK]
Hint: Use shadow-none then md:shadow-sm for responsive shadows [OK]
Common Mistakes:
Mixing up responsive prefixes like sm: and md:
Applying shadow classes in wrong order
Using inner shadows instead of outer for subtle effect