Skip to content

Horizontal Image Accordion

Row of five photo panels that expand horizontally on hover, focus or tap, with vertical titles, smooth @property transitions and a stacked mobile layout.

Also known as: expanding image panels, image accordion gallery, horizontal accordion, expanding photo cards, hover expand gallery

Horizontal Image Accordion live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A horizontal image accordion in pure CSS with an optional dash of JavaScript: five photo panels sit in a row, and the one you hover, focus or tap stretches open to reveal its title and a short description, while the others shrink into slim strips with vertical labels. It works well for destination pickers, portfolio categories and feature showcases.

How it works

The root section.ha-gallery contains a heading and the ul.ha-list. Each li.ha-panel holds an img.ha-img, a .ha-link with the .ha-num and .ha-title, and a .ha-text paragraph. The link's ::after is stretched over the whole panel, so the entire photo is clickable.

All motion is driven by one registered custom property, --ha-o, declared with @property as a number. It is 0 for a closed panel and 1 for an open one, and every visual value is calculated from it: the flex grow factor, the image zoom and saturation, the title size and rotation, the text height and opacity, and the accent bar. Because the property is registered, transition: --ha-o animates all of them together.

A panel is open when it has .ha-panel--open (the default, so the first-load state is never empty), on :hover or on :focus-within. A :has() rule closes the default panel while another one is hovered or focused. The script is a progressive enhancement: on pointerenter (mouse), focusin and click it moves .ha-panel--open, so the last chosen panel stays open, and the first tap on a closed panel opens it instead of following the link.

Customization

  • --ha-grow on .ha-gallery: how much wider the open panel gets than a closed one.
  • --ha-height: height of the row on screens from 720px.
  • --ha-speed: duration of the open and close animation.
  • --ha-accent: color of the numbers, the accent bar and the focus ring.
  • --ha-turn: rotation of closed titles on desktop; set it to 0deg for horizontal labels.
  • Move .ha-panel--open to another li to open a different panel on load.
  • Change the src of each .ha-img. The photos come from Unsplash and should be replaced with your own images.

Use cases

  • Travel sites: destination photos expand on hover to show a title and short description
  • Portfolios: category panels with vertical labels open to reveal each work type
  • Feature showcases: five panels let visitors explore options in a compact row
  • Touch devices: the first tap opens a panel and the second follows the link
  • Mobile layouts: panels stack vertically and expand in height on small screens

Accessibility

The list keeps native list semantics, and each panel is a real link whose aria-describedby points to its .ha-text, so screen readers hear the description even when it is visually collapsed. Tabbing to a link opens its panel through :focus-within, and a bright outline is drawn around the whole panel. Every image has descriptive alt text, width and height. With prefers-reduced-motion: reduce the transition is removed and panels switch instantly.

Usage notes

Below 720px the panels stack vertically and expand in height. Several galleries can live on one page; the script scopes itself to each .ha-list.

Horizontal Image Accordion at a glance

Framework
Pure CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
None
Layout
Responsive, works on mobile, dark design
Category
Accordions
License
Free for personal and commercial use

Questions about this template

Can I use the Horizontal Image Accordion 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?

There is nothing to install. 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

No dependencies. Pure HTML, CSS and JavaScript.

Horizontal Image Accordion – Pure CSS accordions component screenshot
Horizontal Image Accordion · Pure CSS Accordions

More Accordions

Accordion with details and summary – Pure CSS accordions preview

Accordion with details and summary

No-JavaScript FAQ accordion built on native details and summary elements with smooth height animation and one-open-at-a-time behavior.

Accordion with Icons – Bootstrap 5 accordions preview

Accordion with Icons

Bootstrap 5 FAQ accordion with leading icon tiles, subtitles, rounded cards, a rotating plus icon and a warm accent color.

Plus/Minus Accordion – Tailwind CSS accordions preview

Plus/Minus Accordion

Tailwind CSS accordion with a rotating plus/minus icon, smooth height animation, keyboard navigation and a switch for single-open or multi-open mode.