CSS Shadows
Learn how to apply shadow effects to elements, text, and more in CSS to create depth and visual interest.
CSS Shadows can be used to add depth and emphasis to elements by creating subtle or bold shadow effects. The two main types are Box Shadow and Text Shadow.
🧑🎨 What are CSS Shadows?
CSS Shadows are visual effects used to create depth by displaying shadows behind elements or text. These effects help in making UI elements more interactive or dynamic.
📦 Box Shadow (box-shadow)
The box-shadow property allows you to add shadows to elements like div, button, img, etc.
Syntax:
h-offset: Horizontal shadow position (positive for right, negative for left).v-offset: Vertical shadow position (positive for down, negative for up).blur: The blur radius (greater value = more blur).spread: The size of the shadow (positive = grows, negative = shrinks).color: The color of the shadow (e.g.,rgba(0, 0, 0, 0.5)).inset: Optional; changes the shadow to be an inner shadow.
Example:
This applies a shadow 10px right, 10px down, with a blur of 20px and a semi-transparent black color.
🅰️ Text Shadow (text-shadow)
The text-shadow property is used to add shadow effects to text.
Syntax:
h-offset: Horizontal shadow position (positive for right, negative for left).v-offset: Vertical shadow position (positive for down, negative for up).blur: The blur radius (greater value = more blur).color: The color of the shadow.
Example:
This adds a slight shadow 2px right, 2px down, with a blur of 5px and a semi-transparent black color.
🧩 Multiple Shadows
You can apply multiple shadows to a single element by separating them with commas. This works for both box-shadow and text-shadow.
Example: Multiple Box Shadows
This creates a box with two shadows — one in the bottom-right and another in the top-left, creating a more dynamic effect.
Example: Multiple Text Shadows
This applies two text shadows — one with a slight blur and another larger, glowing effect.
🖌️ Customizing Shadows
You can combine shadow effects with other properties like border-radius and background-color to create unique styles.
Example: Rounded Box with Shadow
This creates a box with rounded corners and a shadow that adds depth.
📝 Key Takeaways
Box Shadows and Text Shadows are versatile and can be used to enhance both elements and text.