# Borders, Radius & Shadows

> Transform harsh rectangular boxes into physical, touchable objects with curved corners and realistic depth.

Subject: CSS | Lesson 16 of 44 | 5 min read
Interactive lesson: https://codewithanimation.in/css/borders-radius-and-shadows
Previous: [Backgrounds & Gradients](https://codewithanimation.in/css/backgrounds-and-gradients.md) | Next: [Positioning Schemes](https://codewithanimation.in/css/position-schemes.md)

## What it is

Every element in CSS is inherently a harsh rectangle. The `border-radius` property allows you to curve the corners of these rectangles.

The `box-shadow` property allows you to cast a shadow from the element, simulating a light source and giving the element a sense of physical elevation.

## Why it matters

Modern UI design relies heavily on 'elevation'. A modal dialog feels important because it has a large shadow, making it appear closer to the user.

Similarly, rounded corners make interfaces feel softer and more approachable. Mastering these two properties is the fastest way to make your design feel premium.

## How it works

**Border Radius**:
`border-radius: 8px` curves all four corners equally. You can also specify individual corners, or use `border-radius: 9999px` to ensure the element forms a perfect 'pill' shape regardless of its width.

**Box Shadow**:
The syntax requires several values: `box-shadow: x-offset y-offset blur spread color`.

For example, `box-shadow: 0px 4px 12px rgba(0,0,0,0.1)` casts a shadow straight down (4px), blurs it by 12px, and colors it a very sheer black.

## Common mistake: The era of image slicing

Before these properties existed, creating a rounded box with a shadow was excruciating. Developers had to use Photoshop to create a box, slice it into 9 separate images (4 corners, 4 edges, 1 center), and reassemble them using an HTML `<table>`.

Today, what used to take 2 hours and 9 network requests takes a single line of code.

## Tip: Layering multiple shadows

Just like gradients, you can layer multiple box shadows by separating them with a comma. The best designers combine a tight, dark shadow (for the physical edge) with a wide, sheer shadow (for the ambient light block).

You can also use the `inset` keyword to cast the shadow inside the element, creating a hollowed-out or 'pressed' effect.

## Try it: Try it

Use the controls to adjust the border radius and elevation shadow. Notice how a higher Y-offset and Blur makes the card feel like it's lifting off the screen.

The animation is on the lesson page and is not part of this text version: https://codewithanimation.in/css/borders-radius-and-shadows

## Check yourself

### Question 1

Which CSS value is commonly used to create a perfect 'pill' shape (like a modern rounded button) regardless of the element's width?

- A. border-radius: 9999px
- B. border-radius: 100%
- C. border-radius: max

Correct answer: A

Using an absurdly high pixel value like 9999px forces the browser to round the corners as much as physically possible, creating a perfect semi-circle on the short edges (a pill shape).

- Why not B: Using 100% on a wide rectangle creates an elliptical oval, not a pill shape.
- Why not C: There is no 'max' keyword for border-radius.

### Question 2

In the rule box-shadow: 0px 4px 10px black;, what does the '10px' represent?

- A. The blur radius
- B. The Y offset
- C. The spread radius

Correct answer: A

The standard order is X-offset, Y-offset, Blur radius, then Color. So 10px dictates how soft and feathered the shadow edge becomes.

- Why not B: The Y offset is the second value (4px), which pushes the shadow down.
- Why not C: The spread radius is an optional 4th value that expands or shrinks the size of the shadow before it blurs.

### Question 3

How do you make a shadow appear inside the element (creating a pressed-in look) instead of outside?

- A. Add the keyword 'inset'
- B. Use negative offset values
- C. Set the blur radius to 0

Correct answer: A

Adding the 'inset' keyword (e.g., box-shadow: inset 0 2px 4px black) instructs the browser to draw the shadow on the inner walls of the element.

- Why not B: Negative offsets just move the shadow up and to the left, but it still remains outside the element.
- Why not C: Setting blur to 0 just makes the shadow have a hard, sharp edge.

## Remember this

- `border-radius` curves corners. Use `9999px` for a perfect pill shape.
- `box-shadow` creates elevation. Order: x-offset, y-offset, blur, spread, color.
- Add the `inset` keyword to draw the shadow inside the box.
- You can layer multiple shadows by separating them with commas.
