Inset Shadows
You'll learn how to create inner shadows that make elements look pressed-in or recessed using the inset keyword.
What Are Inset Shadows?
By default, box-shadow creates shadows outside an element, making it appear raised. But when you add the inset keyword, the shadow appears inside the element's borders, creating a depressed or carved-in effect.
Think of it like the difference between a button sitting on top of a surface (outer shadow) versus a button pressed into the surface (inner shadow). Inset shadows are perfect for form inputs, pressed button states, or creating depth that goes "into" the page rather than "out of" it.
Basic Syntax
The inset keyword goes at the beginning or end of your box-shadow value:
.pressed-button {
box-shadow: inset 2px 2px 5px rgba(0, 0, 0, 0.3);
}
This creates a shadow inside the element, 2px down and 2px right, with a 5px blur.
Common Use Cases
Recessed Input Fields:
.input-field {
box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}
Pressed Button State:
.button:active {
box-shadow: inset 0 3px 6px rgba(0, 0, 0, 0.2);
}
You can combine inset shadows with regular (outer) shadows from the previous lessons by separating them with commas.
The Key Difference
Without inset, shadows extend outward. With inset, they pull inward, reversing the lighting effect and creating that carved-in appearance.
Key Takeaway: Use the inset keyword in box-shadow to create inner shadows that make elements appear recessed or pressed into the page.