Shaping elements in CSS

In web design, shape and depth are just as important as color and typography. Rounded corners help elements feel softer and more modern, while shadows create depth and guide the user’s attention.

In this lesson, you’ll learn two essential CSS tools for shaping UI components: border-radius (rounded corners) and box-shadow (depth and emphasis). By the end, you’ll be able to turn plain rectangular elements into polished cards, buttons, and panels.

Desired Outcomes:

  • Understand what border-radius and box-shadow do and when to use them in UI design.
  • Apply border-radius to create rounded corners (including uneven and elliptical corners).
  • Apply box-shadow to create both outer shadows and inner shadows using inset.

Border Radius

The border-radius property is used to add rounded corners to an element. You can specify one value for all four corners or provide individual values for each corner.

Uniform border-radius:

div {
    border-radius: 20px; /* All 4 corners will have the same radius */
}

Individual border-radius:

div {
    /* Clockwise from top-left: top-left, top-right, bottom-right, bottom-left */
    border-radius: 20px 10px 15px 5px; 
}

You can even create elliptical shapes by defining two distinct values for each corner (horizontal and vertical radii).

div {
    border-radius: 50% 25%;
}

When you provide two values, the first controls the horizontal radius and the second controls the vertical radius, creating an elliptical curve.

Creating a circle example:

div {
  width: 200px;
  height: 200px;
  border-radius: 50%;
}



Box Shadow

The box-shadow property is used to cast a shadow behind an element. It's versatile and can be used to produce various effects like depth, focus, or even inner shadows.

The property generally has the following values: horizontal offset, vertical offset, blur radius, spread radius, and color.

Syntax:

/* x-offset | y-offset | blur | spread | color */
box-shadow: 0 10px 30px 0 rgba(0, 0, 0, 0.2);

Simple Shadow:

button {
    box-shadow: 5px 5px 15px rgba(0, 0, 0, 0.3);
    /* Horizontal offset: 5px, 
       Vertical offset: 5px, 
       Blur: 15px, 
       Color: semi-transparent black */
}

Inner Shadow:

button.active {
    /* The 'inset' value makes the shadow appear inside the element */
    box-shadow: inset 0 0 10px #888; 
}

Inner shadows are great for “pressed” button states, input fields, or recessed panels.

The border-radius and box-shadow properties are potent tools in your CSS arsenal. They allow for nuanced changes in design, adding depth, focus, and overall visual appeal. Experiment with different values, combine them, and you'll see how these simple properties can transform your designs from flat and dull to dynamic and engaging.

Updated on:

Part of our complete: Learn to Code CSS guide

-33%

Time remaining:
days 00: 00: 00

Learn to code HTML & CSS

From Zero to Hero

Check out this course on Udemy, now at 75% off! Inside this interactive course, I will teach you how to develop websites from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world websites.

HTML & CSS: From Zero to Hero
Learn to code HTML & CSS

-33%

Time remaining:
days 00: 00: 00

Learn to code JavaScript & jQuery

From Zero to Hero

Check out this course on Udemy, now at 75% off! Inside this interactive course, I will teach you how to develop components from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world reusable components.

JavaScript & jQuery: From Zero to Hero
Learn to code JavaScript & jQuery

-25%

Time remaining:
days 00: 00: 00

Learn Frontend Web Development

From Zero to Hero

Check out this course on Udemy, now at 75% off! A bundle of the previous two courses. Inside this interactive course, I will teach you how to develop websites from scratch moving from beginner to advanced concepts. I take time to explain every detail and finish off by building some real-world websites.

Frontend Web Development: From Zero to Hero
Learn Frontend Web Development