CSS Shadows Gradients
CSS
CSS Shadows
CSS allows you to create two types of shadows:
1. box-shadow — for elements
Adds shadow to boxes (divs, buttons, cards, etc.)
Syntax:
- box-shadow: offset-x offset-y blur-radius color;
- offset-x → horizontal shadow (right/left)
- offset-y → vertical shadow (down/up)
- blur-radius → smoothness of the shadow
- color → shadow color
You can also add multiple shadows separated by commas.
2. text-shadow — for text
Adds shadow to text
Syntax:
- text-shadow: offset-x offset-y blur-radius color;
CSS Gradients
Gradients allow you to blend two or more colors smoothly.
There are two main types:
1. linear-gradient
Color transition in a straight line.
- background: linear-gradient(to right, red, yellow);
- Diection: to right, to bottom, or in degrees (45deg)
- You can add more than 2 colors
- background: linear-gradient(to bottom, #ff0000, #ffff00, #00ff00);
2. radial-gradient
Color transition from the center outward.
- background: radial-gradient(circle, blue, lightblue);
Example: Button with shadow and gradient
Feature | Used For | Example Syntax |
---|---|---|
box-shadow | Shadows around boxes | 4px 4px 10px rgba(0,0,0,0.3) |
text-shadow | Shadows on text | 2px 2px 5px gray |
linear-gradient | Smooth color transitions in a line | linear-gradient(to right, red, blue) |
radial-gradient | Color transitions from center | radial-gradient(circle, red, orange) |