CSS · CSS Tutorial · Lesson 7
CSS Backgrounds
Background colors, images, repeat, position and attachment.
The CSS background properties add background effects to elements.
Example
<style>
.hero {
height: 180px;
background-color: #333;
background-image: url("https://picsum.photos/id/1018/800/300");
background-repeat: no-repeat;
background-position: center;
background-size: cover;
color: white;
padding: 20px;
}
</style>
<div class="hero"><h1>Background image</h1></div>
| Property | Purpose |
|---|---|
| background-color | Background color |
| background-image | One or more images |
| background-repeat | repeat, repeat-x, repeat-y, no-repeat |
| background-position | Starting position, e.g. center, right top |
| background-size | cover, contain or a size |
| background-attachment | scroll or fixed |
| background | Shorthand for all of the above |
Keep reading “CSS Backgrounds”
Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.