Introduction
CSS shadows can be applied to elements to create visual depth and dimension, enhancing their appearance and making them stand out on the page.
Key Points About CSS Shadows
- Box Shadows:
- CSS offers the
box-shadow
property to add shadows to elements. Box shadows create a shadow effect around the border box of an element, giving it a lifted or floating appearance.
- CSS offers the
- Inset Shadows:
- In addition to box shadows, CSS supports
inset
shadows, which create shadows inside the border box of an element. Inset shadows are commonly used to create inner shadow effects, such as depth or inset borders.
- In addition to box shadows, CSS supports
- Text Shadows:
- CSS also provides the
text-shadow
property to add shadows to text elements. Text shadows create a shadow effect behind text characters, improving readability and adding visual interest to typography.
- CSS also provides the
CSS Text Shadow
The CSS text-shadow
property applies shadow to text.
h1 {
text-shadow: 3px 3px;
}
JavaScriptOutput:-
add a blur effect to the shadow:
h1 {
text-shadow: 2px 2px 4px green;
}
JavaScriptOutput
add more than one shadow to the text, you can add a comma-separated list of shadows.
h1 {
text-shadow: 0 0 3px #FF0000, 0 0 5px #0000FF;
}
JavaScriptOutput
use the text-shadow property to create a plain border around some text (without shadows):
h1 {
color: coral;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
JavaScriptOutput
box-shadow Property in CSS
Horizontal and a Vertical Shadow
In its simplest use, you only specify a horizontal and a vertical shadow.
div {
width: 300px;
height: 100px;
padding: 15px;
color:blue;
background-color: green;
box-shadow: 5px 5px;
}
JavaScriptOutput
Specify a Color for the Shadow
div {
box-shadow: 10px 10px lightblue;
}
JavaScriptAdd a Blur Effect to the Shadow
div {
box-shadow: 10px 10px 5px lightblue;
}
JavaScriptOutput
Set inset Parameter in CSS shadows
The inset
parameter changes the shadow from an outer shadow (outset) to an inner shadow.
div {
width: 300px;
height: 100px;
padding: 15px;
color:blue;
background-color: green;
box-shadow: 10px 10px 5px lightblue inset;
}
JavaScriptOutput
Conclusion
CSS shadows are useful for adding depth and visual interest to web elements. The box-shadow
property creates external shadows, giving elements a floating appearance. Inset shadows
add inner shadows for depth effects. The text-shadow
property enhances text readability and appearance. These properties offer versatile ways to enhance the design of web pages.
Frequently Asked Question
Yes, it allows you to apply multiple box shadows to an element by separating each shadow definition with a comma within the box-shadow property. This enables developers to create layered shadow effects for elements.
To create inset shadows in it, you can use the inset keyword before the shadow definition within the box-shadow property. Inset shadows are commonly used for creating inner shadow effects, such as depth or inset borders.
RGBA values allow developers to specify a color for the box shadow with an additional alpha channel, controlling the opacity of the shadow. This provides flexibility in adjusting the intensity of the shadow and creating subtle or transparent shadow effects.