Skip to content

Courses / CSS3 Mastery: Beginner to Advanced / Borders, Outlines, Shadows, Backgrounds and Gradients

2,099 people viewed this

Borders, Outlines, Shadows, Backgrounds and Gradients

Borders, Shadows and Backgrounds

Learning Objectives

  • Style borders and outlines.
  • Create rounded corners and box shadows.
  • Apply background colors and images.
  • Use linear, radial and conic gradients.

1. Borders

.card {
  border: 2px solid #2563eb;
  border-radius: 12px;
}
.dashed { border-style: dashed; }
.bottom-only { border-bottom: 3px solid navy; }

Border shorthand can specify width, style and color. Individual sides and border-radius allow more precise styling.

2. Outlines

button:focus-visible {
  outline: 3px solid orange;
  outline-offset: 3px;
}

Outlines are drawn outside the border and do not normally occupy layout space. They are especially useful for visible keyboard focus indicators.

3. Box Shadows

.card {
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
}
.inset {
  box-shadow: inset 0 1px 4px rgb(0 0 0 / 20%);
}

The common box-shadow syntax includes horizontal offset, vertical offset, blur radius, optional spread radius, color and optional inset.

4. Background Properties

.hero {
  background-color: #eaf2ff;
  background-image: url("hero.jpg");
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

background-size: cover fills the background positioning area while preserving image proportions, potentially cropping the image. Contain fits the whole image and may leave empty space.

5. Linear Gradients

.banner {
  background: linear-gradient(135deg, #2563eb, #9333ea);
}

6. Radial and Conic Gradients

.radial {
  background: radial-gradient(circle, white, steelblue);
}
.conic {
  background: conic-gradient(red, yellow, green, red);
}

Gradients are generated images and can be layered with other background images.

7. Multiple Background Layers

.hero {
  background-image:
    linear-gradient(rgb(0 0 0 / 40%), rgb(0 0 0 / 40%)),
    url("hero.jpg");
  background-position: center;
  background-size: cover;
}

The first background image is painted on top of subsequent background layers. Background shorthand can set multiple properties but may reset omitted background properties to their initial values.

Practice Exercise

Rate this course

No ratings yet — yours can be the first.

Stars show on this course. Your written note stays private.

Your stars