Your event cards have rounded borders and a soft shadow now, but every box on the events page is still filled with one flat color. The top of the page, where Upcoming Events sits on plain white, is the first thing a visitor sees, and it doesn’t look like a garden yet.
In this lesson, you’ll put the garden’s photo behind that heading, make the photo fill its box whatever the window’s shape, and lay a gradient over it so the text stays readable. You’ll also learn to predict how much of a background image shows and why it never changes a box’s size. Start by giving the heading a box of its own.
Put a Photo Behind the Heading
Rosa would like the events page to open with a banner: the garden’s overview photo behind the page’s heading and its welcome line. A background belongs to a box, so the heading and the line need a box that holds both of them.
In upcoming.html, wrap the <h1> and the paragraph after it, at the top of <main>, in a <header> element:
<header class="events-banner">
<h1>Upcoming Events</h1>
<p>Everyone's welcome at every event.</p>
</header>
A <header> inside <main> introduces the main content, so it’s the right element here. It’s a different header from the one at the top of the page, which holds the garden’s name and the navigation for the whole site. The class events-banner says what this one is.
The background-image property paints an image inside a box, and url() says where the image file is. Add a rule at the end of events.css:
events/events.css
.events-banner {
padding: 48px 24px;
background-image: url("../images/garden-overview.jpg");
}
The padding gives the photo room to show around the text. Watch out for the path. Inside a stylesheet, a relative url() starts from the stylesheet’s own folder, not from the page’s.
Here, events.css and upcoming.html are both in events/, so the path is the same ../images/ that the seed swap’s <img> uses. When the course’s project moves this rule into the site’s style.css, at the root of garden/, the path becomes images/garden-overview.jpg.
Save, and the photo appears behind the heading:

You see trees and sky, but not the garden. The photo is 1,200 by 670 pixels, and the browser paints it at that size, starting from the banner’s top-left corner. The banner is only as tall as its text and padding, so everything below that strip is cut off. If your window is wider than 1,200 pixels, you’ll also see the photo start again at the banner’s right end. That’s the browser repeating it, which you’ll meet again in a moment.
That’s the key difference from an <img>. An image element is content, so its box grows to fit it. A background is painted inside a box whose size comes from its content, padding, and border, and it never changes that size. Like a shadow, it takes up no space, so the banner pushed the cards down only as far as its text and padding needed.
It also means that a background image is decoration. It has no alt text, and screen readers don’t announce it. A photo that tells the visitor something, like the seed swap’s tables, stays an <img> with an alt attribute.
Fit the Photo to the Box
A photo painted at its own size works only when the box happens to match it, and this banner is far wider than it is tall. The background-size property scales the image to the box instead. Add it to the banner rule:
events/events.css
.events-banner {
padding: 48px 24px;
background-image: url("../images/garden-overview.jpg");
background-size: cover;
}
The value cover scales the photo, keeping its shape, until it covers the whole box. Whatever doesn’t fit is cut off. Save, and the photo shrinks to the banner’s width, so you see much more of it: the trees, the sky, and the houses beyond the garden:

The photo still starts at the banner’s top edge, so the part that’s cut off is the bottom, where the garden is. The background-position property moves the image inside the box. Add background-position: center; to the rule, and save:

Now the middle of the photo shows, with the shed and the raised beds. The value center lines up the middle of the image with the middle of the box, so the same amount is cut off at the top and the bottom.
The other value that keeps the photo’s shape is contain. It scales the image until the whole of it fits inside the box, so nothing is cut off. Change cover to contain, save, and look at what fills the rest of the banner:

The whole photo fits, but it’s small, and the browser repeats it across the banner to fill the space on either side. Repeating is the default for every background image, which suits a small pattern better than a photo. You can stop it with background-repeat: no-repeat, and the space beside the photo is left empty instead.
So cover fills the box and crops the photo, while contain shows the whole photo and, with repetition disabled, leaves gaps. For a banner, filling the box matters more, so change contain back to cover, and save.
How much cover crops and where contain leaves gaps depend on the shape of the box, and a banner’s shape changes with the window. To see how, drag the box’s width and height in the explorer below, switch between the sizes, and move the position.
The explorer gives its box a fixed width and height to stand in for the window’s shape, while your banner still takes its size from its text and padding. It also sets background-repeat: no-repeat, so any space the photo leaves shows as stripes, and the faded photo outside the box is the part that’s cut off:
Whatever the box’s shape, cover matches one side of the box exactly and cuts the photo off along the other, while contain matches one side and leaves empty space along the other. The matched side changes when the box’s proportions shift from wider than the photo’s to taller than the photo’s, and background-position decides where the cut or the empty space goes.
A box that’s taller than it is wide is where predictions most often go wrong, because cover then crops the photo’s sides instead of its top and bottom. To check your predictions for both values in a box of any shape, click the button below to ask the mentor for a few boxes to think through:
Lay a Gradient Over the Photo
The photo is in place, but the green heading and the welcome line are hard to read against the leaves and the beds. You can fix that by using a gradient to darken the photo and making the text white.
A gradient is an image that the browser draws itself, a smooth change from one color to another. The linear-gradient() function draws one from the top of the box to the bottom by default. Because a gradient is an image, it goes in background-image, and that property takes a list of images, separated by commas. Change the banner rule to this:
events/events.css
.events-banner {
padding: 48px 24px;
background-color: var(--green-dark);
background-image:
linear-gradient(
oklch(0 0 0 / 0.3),
oklch(0 0 0 / 0.7)
),
url("../images/garden-overview.jpg");
background-size: cover;
background-position: center;
}
The first image in the list is drawn on top, so the gradient lies over the photo. It runs from black at an alpha of 0.3 at the top to 0.7 at the bottom, so the photo shows through, a little darker at the top and a lot darker at the bottom. The background-size and background-position properties apply to both images, and the gradient fills the box whatever its size.
The background-color is a fallback. It’s painted under all the images, so you see it through the translucent gradient while the photo is still loading or if the path in url() is wrong. Dark green keeps white text readable in both cases.
Now make the text white. The h1 and header p rules in your stylesheet color it green, so add a rule with more specific selectors after the banner rule:
events/events.css
.events-banner h1,
.events-banner p {
color: white;
}
Save, and the heading and the welcome line stand out in white against the darkened garden:

The photo is still recognizably the garden, and the text no longer competes with it. The banner is the same size as before, too, because neither the gradient nor the color takes up any space.
A gradient can run in other directions, too. A first value such as to right changes the direction, and radial-gradient() spreads the colors out from a point instead. These gradients all go in background-image the same way.
Text over a photo is the hardest kind of text to keep readable, because the colors behind it change from one spot to the next. To learn how to check that your text stands out everywhere on the banner, ask the mentor:
The events page now opens on the garden, and you can predict how much of a background shows. A background fills the box it’s given, cover and contain decide how the photo is scaled to it, and a relative url() starts from the stylesheet’s folder.
Next comes the course’s first exercise, Exercise: Style the Seed Swap Notice, where you’ll turn the seed swap notice into a finished card with its own photo behind a gradient. Write the CSS in the browser and click Run Tests to check it with automated tests. Run them early and often, and read each failure for clues. For more room, click the expand button at the top right, whose tooltip reads Full screen, and the exercise fills your screen.