Skip to content

Horizontal Scroll Section

Bootstrap 5 section that pins to the viewport and slides photo cards sideways as the page scrolls down, with a counter and progress bar.

Also known as: horizontal scroll on vertical scroll, sticky horizontal scroller, scroll triggered carousel, pinned scroll section

Horizontal Scroll Section live demo

Open in new tab

Bootstrap 5 code (HTML, CSS, JS)

A Bootstrap 5 scroll-driven section that pins itself to the viewport and slides a row of photo cards sideways while the visitor keeps scrolling down. Use it for travel stories, product timelines, case-study reels or any "chapter" sequence on a landing page.

How it works

The root is section.hs-section. Inside it, .hs-sticky holds a container-xl heading row (.hs-head) with a counter (.hs-current / .hs-total) and a Bootstrap progress bar, followed by .hs-viewport and the ol.hs-track of .hs-panel items. Each panel is a Bootstrap card with a full-height photo (.hs-img) and a card-img-overlay that stacks the outlined number, place, title, text and a pill button.

On DOMContentLoaded the script initialises every .hs-section on the page. When the media query (min-width: 768px) and (prefers-reduced-motion: no-preference) matches, it adds .hs-section--pinned, measures how far the track overflows and stores the section height in --hs-height (overflow width plus one viewport height). .hs-sticky then becomes position: sticky and a requestAnimationFrame-throttled scroll listener converts the vertical scroll position into --hs-shift, which moves the track with translate3d. The same progress value drives --hs-progress (the bar's scaleX) and the 01 / 05 counter. Measurements are refreshed on resize, load and media query changes.

Without JavaScript, on phones or with reduced motion, the section stays at its natural height and .hs-viewport becomes a normal horizontal scroller with scroll-snap-type: x mandatory; when the script runs, the counter and bar then follow scrollLeft.

Customization

  • --hs-accent on .hs-section in style.css: changes the eyebrow, place labels, progress bar and the button color.
  • --hs-bg and --hs-ink: switch the dark navy background and the light text to your brand palette.
  • --hs-panel-w: set the card width (default min(82vw, 360px)); wider cards mean fewer panels on screen and a shorter scroll.
  • --hs-gap: adjust the space between cards; the pinned distance is recalculated automatically.
  • height: min(62vh, 520px) in .hs-card: make the cards taller or shorter.
  • PIN_QUERY at the top of script.js: change the breakpoint where pinning starts, e.g. (min-width: 992px).
  • Add or remove li.hs-panel items; .hs-total is filled from the number of panels.

Use cases

  • Travel stories: photo cards slide sideways while the visitor keeps scrolling down the page
  • Product timelines: a counter and progress bar show where the reader is in the sequence
  • Case-study reels: each card carries a place, title, text and a button inside a pinned section
  • Landing page chapters: on phones or with reduced motion it becomes a swipeable row

Accessibility

The section is labelled by its heading through aria-labelledby, and the cards are an ordered list so screen readers announce the count. The progress bar has role="progressbar", an aria-label and an updated aria-valuenow; the visual counter is aria-hidden. When a keyboard user tabs to a "Read the guide" button in pinned mode, a focusin handler scrolls the page so that panel slides into view, and the button has a white focus ring. Every photo has descriptive alt text, and prefers-reduced-motion: reduce disables both the pinned effect and the image zoom.

Usage notes

Requires Bootstrap 5 (added automatically) and Bootstrap Icons. Place content above and below the section so the pinning is visible on a real page. The photos come from Unsplash; replace them with your own images.

Horizontal Scroll Section at a glance

Framework
Bootstrap 5
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Bootstrap 5, Bootstrap Icons
Layout
Responsive, works on mobile, dark design
Category
Scroll Animations
License
Free for personal and commercial use

Questions about this template

Can I use the Horizontal Scroll Section code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Bootstrap 5 and Bootstrap Icons from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

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">
Horizontal Scroll Section – free Bootstrap 5 scroll animation template
Horizontal Scroll Section · free Bootstrap 5 scroll animation template

More Scroll Animations

Scroll Reveal Animations – free Pure CSS scroll animation template

Scroll Reveal Animations

Elements fade, slide, zoom or flip into view on scroll using IntersectionObserver and data-sr attributes, with stagger delays and reduced-motion support.

Reading Progress Bar – free Tailwind CSS scroll animation template

Reading Progress Bar

Sticky Tailwind CSS reading progress bar with a gradient fill, clickable chapter markers, current section label, minutes left and a circular back-to-top indicator.