webdevpuneet.com

Bootstrap Hero Section with Gradient Background — Free Snippet

Bootstrap Hero Section with Gradient Background · Heroes · Plain HTML, CSS & JS · Live preview

CategoryHeroes

Copy & paste

Source Code

<section class="bshero-section">
  <div class="container py-5">
    <div class="row align-items-center gy-4">
      <div class="col-lg-6 text-center text-lg-start">
        <span class="badge rounded-pill bshero-badge mb-3">New · v2.4 launched</span>
        <h1 class="bshero-title">Ship your product page in an afternoon.</h1>
        <p class="bshero-sub">A Bootstrap 5 hero section with a real, working email capture form — type an address, submit, and watch it get validated and added to the list below, no page reload.</p>
        <form id="bsheroForm" class="row g-2 justify-content-center justify-content-lg-start bshero-form" novalidate>
          <div class="col-sm-7">
            <input type="email" class="form-control form-control-lg" id="bsheroEmail" placeholder="[email protected]" required>
            <div class="invalid-feedback" id="bsheroError">Enter a valid email address.</div>
          </div>
          <div class="col-sm-auto">
            <button class="btn btn-light btn-lg fw-bold text-nowrap" type="submit">Get early access</button>
          </div>
        </form>
        <div class="bshero-signups" id="bsheroSignups">
          <span class="text-white-50 small">No signups yet — be the first.</span>
        </div>
      </div>
      <div class="col-lg-6">
        <div class="bshero-card">
          <div class="bshero-card-dots"><span></span><span></span><span></span></div>
          <div class="bshero-card-body">
            <div class="bshero-stat">
              <div class="bshero-stat-label">Weekly signups</div>
              <div class="bshero-stat-value" id="bsheroCount">0</div>
            </div>
            <div class="bshero-bars">
              <div class="bshero-bar" style="--h:40%"></div>
              <div class="bshero-bar" style="--h:65%"></div>
              <div class="bshero-bar" style="--h:52%"></div>
              <div class="bshero-bar" style="--h:80%"></div>
              <div class="bshero-bar bshero-bar-active" style="--h:95%"></div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</section>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Real Bootstrap 5.3 grid (row/col-lg-6) and form-control classes, loaded from the actual CDN
Genuine native HTML5 email validation via checkValidity(), driving Bootstrap's is-invalid state
Live signup list rendered as Bootstrap badges from real, validated form submissions
Animated counter with a scale-pop confirmation on every successful signup
Five-bar chart built from plain divs and a CSS custom property, no charting library
Three-stop CSS linear-gradient background, easy to swap for any brand palette
Glassmorphism stat card using backdrop-filter over a translucent background
Fully responsive — stacks to a single column below Bootstrap's lg breakpoint

About this UI Snippet

Bootstrap Hero Section with Gradient Background — HTML, CSS & JavaScript

Screenshot of the Bootstrap Hero Section with Gradient Background snippet rendered live

A landing page hero has one job: get a visitor to take the first step, usually entering an email address or clicking a primary CTA. This snippet builds that hero as a real Bootstrap 5.3 layout — a two-column row/col-lg-6 grid, Bootstrap's own form controls and validation classes, loaded from the actual Bootstrap CDN — with a genuinely working email capture form on the left and a live, animating stat card on the right, instead of static placeholder numbers.

Real validation, not a decorative form

The form is a real <form> with an email input marked required. On submit, emailInput.checkValidity() runs Bootstrap-compatible native HTML5 validation — an invalid or empty address adds Bootstrap's .is-invalid class (which drives both a red focus ring and, if you add a sibling .invalid-feedback, an inline error message) and the submission stops there. A valid address clears any error state, gets added to a running list rendered as badges under the form, and bumps a signup counter with a small scale "pop" animation — a genuine confirmation that something happened, not just an emptied input box.

The stat card is driven by the same submit event

Rather than a chart library, the bar chart on the right is five plain divs sized with a CSS custom property (--h) controlling height via inline style. Each successful signup nudges the last (highlighted) bar's height up slightly, capped at 100% — a small, honest piece of "your action changed something" feedback rather than a chart that's purely decorative.

The gradient and glass card

The background is a three-stop linear-gradient (indigo → violet → pink) applied to the whole <section>, and the stat card on the right uses backdrop-filter: blur(6px) over a translucent white background — a common combination for making a card read as "floating" above a colored gradient rather than sitting flatly on top of it.

Step by step

How to Use

  1. 1
    Load the snippetClick "Bootstrap Hero Section with Gradient Background" in the sidebar Library tab. The preview loads with a zero-signup stat card.
  2. 2
    Submit an invalid emailType something that isn't a valid email (or leave it blank) and click "Get early access" — the input gets a red Bootstrap invalid state and the form does not submit.
  3. 3
    Submit a real emailType a properly formatted address and submit — it appears as a badge below the form, the counter increments with a pop animation, and the highlighted bar in the stat card grows slightly.
  4. 4
    Submit a few moreRepeat with different addresses to watch the signup list, counter, and bar chart all update live from real form submissions.
  5. 5
    Restyle the gradientIn the CSS panel, edit the linear-gradient on .bshero-section to swap in your own brand colors.
  6. 6
    Export in your formatClick "HTML" for a standalone file, "JSX" for React, or "Tailwind" for React + Tailwind CSS.

Real-world uses

Common Use Cases

SaaS product launch and waitlist pages
A genuinely functional email-capture hero for a pre-launch or early-access page, with real validation instead of a form that silently accepts anything.
Learning Bootstrap's native validation classes
See exactly how is-invalid and invalid-feedback pair with checkValidity() to produce a working validated form, without a validation library.
Marketing pages needing a bold, colorful first impression
The gradient background and glass stat card give a hero section visual weight appropriate for a landing page's very first fold.
A/B testing hero copy and CTA framing
Swap the headline, subhead, and badge text to test different value propositions while keeping the working form and stat card intact.

Got questions?

Frequently Asked Questions

It's real. The submit handler calls the input's native checkValidity(), which enforces the browser's built-in email format rules. An invalid or empty address is rejected with Bootstrap's is-invalid styling; only a properly formatted address is accepted and added to the signup list.

Nowhere outside the page — this is a front-end demo, so submissions are held in a plain JavaScript array and rendered as badges. Wire the submit handler to your own API endpoint (fetch/POST) to actually collect signups.

Each bar is a div whose height is set via a CSS custom property (--h) read by its own height: var(--h) rule. The highlighted bar's --h value is nudged upward by a few percent on each successful signup, with a CSS transition producing the smooth grow animation.

Yes — edit the linear-gradient() value on .bshero-section in the CSS panel. Any valid CSS gradient works; keep at least two stops with enough contrast for the white text to stay readable.

Yes — it uses Bootstrap's standard row/col-lg-6 grid, so the two columns stack vertically on screens narrower than Bootstrap's lg breakpoint (992px), with the copy and form centered.

Yes — add a second Bootstrap button (e.g. btn btn-outline-light) inside or beside the form row; it won't interfere with the existing submit handler as long as it doesn't have type="submit" unless you want it to trigger the same validation.