Skip to content

Hero with Background Overlay

Full-width Bootstrap 5 hero section with a cover background image, dark gradient overlay, fluid headline, two call-to-action buttons and a stats row.

Live preview

Open in new tab

Code

A full-width Bootstrap 5 hero section with a background image, a dark gradient overlay, a pill eyebrow, a large headline, two call-to-action buttons and a row of stats. It suits travel sites, agencies, event pages and any landing page that opens with a strong photo.

How it works

The root section.ho-hero is a flex container with align-items-center and a min-height taken from --ho-min-height, so the content is vertically centered. The background is a real img.ho-hero__bg (a placehold.co placeholder) stretched with position: absolute, inset: 0 and object-fit: cover. Using an image element instead of a CSS background-image lets the browser load it early (fetchpriority="high") and lets you use srcset for responsive images.

On top sits .ho-hero__overlay, an absolutely positioned layer with two stacked gradients: one darkens the bottom edge, the other runs from almost opaque on the left (--ho-overlay-from) to lighter on the right (--ho-overlay-to). The text sits on the darkest part, so contrast stays high even with a bright photo. isolation: isolate on the root keeps the negative z-index of the image and overlay inside the section.

The content uses a Bootstrap container and a col-lg-8 col-xl-7 column. The headline .ho-hero__title scales fluidly with clamp(), and text-wrap: balance evens out its lines. The buttons stack on phones (flex-column) and sit side by side from the sm breakpoint. The .ho-hero__stats list wraps onto several lines on narrow screens. No JavaScript is required.

Customization

  • src of .ho-hero__bg: replace the placeholder with your own photo; adjust object-position in .ho-hero__bg to keep the subject visible on phones.
  • --ho-overlay-from and --ho-overlay-to in .ho-hero: make the overlay darker, lighter or tinted (for example a navy or brand color).
  • --ho-accent and --ho-accent-text in .ho-hero: change the color of the primary button.
  • --ho-min-height in .ho-hero: use 100vh for a full-screen hero or 60vh for a shorter banner.
  • col-lg-8 col-xl-7 on the content column: widen it, or add mx-auto text-center for a centered layout.
  • Remove .ho-hero__stats if you only need a headline and buttons.
  • font-size: clamp(2.25rem, 6vw, 4.25rem) in .ho-hero__title: change the minimum and maximum headline size.

Accessibility

The background image has an empty alt because it is decorative, and the overlay has aria-hidden="true". The section is labelled by its h1 through aria-labelledby. All icons are hidden from screen readers. Text is light on a gradient that stays near 90% black behind the copy, giving strong contrast. Buttons have a clear :focus-visible outline in white, and the hover lift and transitions are disabled with prefers-reduced-motion: reduce.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. If the hero is not the first heading on your page, change the h1 to an h2. Replace the href="#" values with your own links.

Requirements

Add these to your page (already included in the download):

  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css">
  • <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
  • <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
Hero with Background Overlay – Bootstrap 5 hero sections component screenshot
Hero with Background Overlay · Bootstrap 5 Hero Sections

More Hero Sections

Hero with Rotating Words – Pure CSS hero sections preview

Hero with Rotating Words

Dark hero section whose headline cycles through words with a slide-and-fade animation, a pause button and decorative stat cards.

Centered Hero with Announcement Badge – Tailwind CSS hero sections preview

Centered Hero with Announcement Badge

Dark Tailwind CSS hero section with an announcement pill, gradient headline, two CTA buttons, glowing grid background and a row of trust logos.

Hero with Signup Form – Bootstrap 5 hero sections preview

Hero with Signup Form

Bootstrap 5 two-column hero with value points, social proof and a validated signup card that shows a loading state and a success message.

Split Hero with App Screenshot – Tailwind CSS hero sections preview

Split Hero with App Screenshot

Dark Tailwind CSS split hero with gradient headline, two CTA buttons and an animated mock app dashboard built entirely from divs.