Box-Shadow, Text-Shadow, & Z-Index
Master CSS Visual Effects and Depth Techniques
Core CSS Visual Effects
Box Shadow
Adds depth and visual separation to elements using horizontal offset, vertical offset, blur radius, and color values.
Text Shadow
Creates shadow effects on text with customizable offset, blur, and color for enhanced typography.
Z-Index Control
Manages element stacking order along the z-axis to control which elements appear in front of others.
Environment Setup
Close All Files
Close all open files in your code editor to avoid confusion when switching to new project files.
Open Project Folder
Navigate to Desktop > Class Files > Advanced HTML CSS Class and open the Box-Shadow and Text-Shadow folder.
Launch Files
Open index.html in your code editor and preview it in Chrome to access DevTools for testing.
The box-shadow property follows a specific order: horizontal offset, vertical offset, blur radius, and color. Positive values place shadows bottom-right, negative values place them top-left.
Shadow Value Effects
| Feature | Positive Values | Negative Values |
|---|---|---|
| Horizontal Offset | Shadow to the right | Shadow to the left |
| Vertical Offset | Shadow below element | Shadow above element |
| Visual Impact | Bottom-right shadow | Top-left shadow |
Box-Shadow Property Values
Relative positioning differs from default static positioning in stacking behavior. Elements with relative position can control their stacking order, while static elements cannot use z-index.
CSS Positioning Options
Static (Default)
Normal document flow positioning. Cannot use z-index property for stacking control.
Relative
Maintains document flow but enables z-index control. Best for keeping elements in normal flow while managing stacking.
Fixed/Absolute
Removes from document flow. Fixed stays in viewport, absolute positions relative to parent container.
Creating Inset Shadow Effects
Add Inset Keyword
Prepend 'inset' to box-shadow values to create inner shadows instead of outer drop shadows.
Manage Element Stacking
Use z-index with negative values to push elements backward in stacking order when needed.
Enable Z-Index Control
Set position to relative or absolute to enable z-index functionality on elements.
Z-index only works with positioned elements (relative, absolute, fixed). Higher positive numbers move elements forward, negative numbers push them backward.
Box-Shadow vs Text-Shadow
| Feature | Box-Shadow | Text-Shadow |
|---|---|---|
| Target | Element containers | Text content only |
| Blur Control | Optional blur radius | Optional blur radius |
| Positioning | Can use inset effects | External shadows only |
| Layering | Single shadow per element | Multiple shadows supported |
Text-Shadow Implementation Checklist
Required parameters that determine shadow direction and distance
Controls shadow sharpness - 0 for hard edges, higher values for softer shadows
Supports hex, RGB, RGBA, HSL, or HSLA color values
Create complex effects by stacking multiple text-shadow declarations
Color can be specified before or after offset and blur values
Box-Shadow Property Values
Text-Shadow Implementation Checklist
Required parameters that determine shadow direction and distance
Controls shadow sharpness - 0 for hard edges, higher values for softer shadows
Supports hex, RGB, RGBA, HSL, or HSLA color values
Create complex effects by stacking multiple text-shadow declarations
Color can be specified before or after offset and blur values
Key Takeaways
