Backgrounds, borders, and shadows

W3C CSS Snapshot 2026

Style the surface and edges of a box.

On this page

Place a background image

background-image accepts url(). Small images tile by default. Use background-repeat, background-position, and background-size to control where and how the image is painted.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Place a background image</title>
  <style>
.card {
  padding: 18px 84px 18px 12px;
  background-color: #def5f5;
  background-image: url("data:image/svg+xml,%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%20160%2080%27%3E%3Crect%20width=%27160%27%20height=%2780%27%20fill=%27teal%27/%3E%3Ccircle%20cx=%2780%27%20cy=%2740%27%20r=%2730%27%20fill=%27orange%27/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right center;
  background-size: 80px 40px;
}
  </style>
</head>
<body>
<p class="card">Desk Lamp</p>
</body>
</html>

What to expect One small illustration appears on the right. Delete no-repeat to see it tile.

Blend colors with linear-gradient()

A gradient is an image generated by CSS. linear-gradient() takes a direction and two or more color stops, then blends the colors along that line.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Blend colors with linear-gradient()</title>
  <style>
.card { padding: 16px; background-image: linear-gradient(to right, #ccfbf1, #fef3c7); }
  </style>
</head>
<body>
<p class="card">Desk Lamp</p>
</body>
</html>

What to expect Pale cyan blends into pale yellow from left to right.

Round corners with border-radius

One border-radius value rounds all four corners. It also rounds the background even if the box has no visible border.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Round corners with border-radius</title>
  <style>
.card { padding: 12px; background: #def5f5; border: 2px solid teal; border-radius: 16px; }
  </style>
</head>
<body>
<p class="card">Desk Lamp</p>
</body>
</html>

What to expect All four corners are rounded. Try 0 to make them square.

Add an edge shadow with box-shadow

The first two lengths offset the shadow horizontally and vertically. The third length softens its edge. The last value is the shadow color.

How to try it Save this example as a new .html file, then open it in your browser. After a change, save and reload.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Add an edge shadow with box-shadow</title>
  <style>
.card { padding: 12px; background: #def5f5; box-shadow: 0 6px 14px rgb(0 40 40 / 27%); }
  </style>
</head>
<body>
<p class="card">Desk Lamp</p>
</body>
</html>

What to expect A soft shadow appears below. Change 6px to -6px to move it up.

Official references