Backgrounds

Background Properties

PropertyExample
background-color#f1f1f1
background-imageurl("photo.jpg")
background-repeatno-repeat, repeat-x
background-sizecover (fill, may crop), contain (fit, may leave space)
background-positioncenter, top right, 50% 20%
backgroundshorthand for all of the above

Hero Image Example

Example

A full-width banner with a darkened background image and centered text:

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    .hero {
      height: 180px;
      background: linear-gradient(rgba(0,0,0,.45), rgba(0,0,0,.45)),
                  url("https://picsum.photos/id/1018/800/300") center / cover no-repeat;
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      font: bold 28px Arial, sans-serif;
    }
  </style>
</head>
<body>

<div class="hero">Learn CSS</div>

</body>
</html>

Result