At the end of this Tutorial you will be able to:
You can view a finished version of the sample web page you will be working with in this Tutorial by clicking the image or text link below. The finished sample will open in a new tab of your web browser.
hero-images.htmlThe most common design approach to hero blocks on web pages is to use a full-width background image. Typically, the text in front of the background image is centre-aligned. See the examples below.
You will also see examples where the text is left-aligned.
In this Tutorial, you will work with four examples of hero blocks with background images.
Your first task is to download the following web page and a stylesheet:
You will need some sample images to work with. Right-click on the images below, choose Save Image As from the context menu, and download them to your C:/websites/bootstrap/assets/img sub-folder.
You have now saved the all the files you need for this exercise.
In this section, you will add a background image to the hero-6 block within your sample files.
.hero-6 { background-image: url('../img/hotel-dark.jpg'); background-position: center center; background-size: cover; background-repeat: no-repeat; }
In this section, you will add a background image to the hero-7 block within your sample files.
.hero-7 { background-image: url('../img/bike-tours.jpg'); background-position: center center; background-size: cover; background-repeat: no-repeat; }
To make the text easier to read against the background image, let's add a shadow effect to the heading and sub-heading.
Note: The three dots ... simply refers to all the other styles for the CSS selector.
.hero-7 h1 { ... text-shadow: 2px 2px #222; }
.hero-7 h2 { ... text-shadow: 2px 2px #222; }
To make the text even easier to read against the background image, let's add a semi-opaque overlay in front of the image and behind the heading and sub-heading.
background-image: linear-gradient(rgba(0,0,0,0.3),rgba(0,0,0,0.3)),url('../img/bike-tours.jpg');
In this section, you will add a background image to the hero-8 block within your sample files.
.hero-8 { background-image: url('../img/meeting.jpg'); background-position: center center; background-size: cover; background-repeat: no-repeat; }
To make the text easier to read against the background image, let's add a shadow effect to the heading and sub-heading.
.hero-8 h1 { ... text-shadow: 2px 2px #222; }
.hero-8 h2 { ... text-shadow: 2px 2px #222; }
To make the text even easier to read against the background image, let's add a blue-tinted semi-opaque overlay in front of the image and behind the heading and sub-heading.
background-image: linear-gradient(rgba(0,0,255,0.5),rgba(0,0,255,0.5)),url('../img/meeting.jpg');
In this section, you will add a background image to the hero-9 block within your sample files.
.hero-9 { background-image: url('../img/hook-head.jpg'); background-position: center center; background-size: cover; background-repeat: no-repeat; }
To offer a different image for mobile screens, follow these steps.
/* Desktop - Background image */ @media (min-width: 768px) { .hero-9 { background-image: url('../img/hook-head.jpg'); } } /* Mobile - Background image */ @media (max-width: 767px) { .hero-9 { background-image: url('../img/hook-head-mobile.jpg'); } }
Success!. You have now completed this Tutorial.
You can see an example of the finished web page at the link below.
hero-images.htmlFollow these steps below to upload your entire Bootstrap folder to your website on GitHub.
Your uploaded web page is published on GitHub at a web address similar to the following, where username is the username you have chosen for your GitHub account:
https://username.github.io/bootstrap/hero-images.html
It may take a few minutes for your uploaded files to appear on GitHub.
20 inspiring hero image websites
By Rebeca Costa at the Just in Mind Blog.
What is a hero image?
By Mary Stribley at Canva Learn.
A Look at Hero Images in Web Design
By Marina Yalanska at the Tubik Studio Blog.
How to Select Hero Images that Boost Conversions and Move Audiences
From the Neil Patel Blog.
Return to Contents.