Skip to content

Tabs with Photo Preview Panels

Tailwind CSS feature tabs that swap a large photo preview with a caption for each selected tab, with full keyboard support.

Also known as: tabs with images, feature tabs, image tab panels, tabbed photo showcase

Tailwind CSS Tabs Responsive #accessible #features #image #responsive #tabs

Tabs with Photo Preview Panels live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A feature tab section built with Tailwind CSS and a few lines of vanilla JavaScript, where every tab swaps in a large photo preview with a floating caption. It suits venue and coworking pages, product tours, hotel room types or any "explore our spaces" block where a picture explains each option better than a paragraph.

How it works

The root is section.tpp-tabs, a two-column grid from the lg breakpoint (lg:grid-cols-[minmax(0,5fr)_minmax(0,7fr)]) that stacks on phones. The left column holds the heading and a role="tablist" with four button.tpp-tab elements. Each tab shows an icon tile and a title; the short description underneath appears from sm up. Active styling comes entirely from Tailwind's aria-selected: and group-aria-selected: variants, so the white card and the green icon tile follow the ARIA state without extra classes.

The right column is a one-cell grid where every .tpp-panel sits in the same col-start-1 row-start-1 slot. Each panel is a figure with a 4:3 object-cover photo and a frosted figcaption showing the space name and key facts. Inactive panels carry the hidden attribute.

On DOMContentLoaded the script initializes every .tpp-tabs root. A click or arrow key calls select(), which updates aria-selected, sets a roving tabIndex and toggles hidden on the panel named in aria-controls. style.css plays the tpp-reveal fade and a subtle tpp-zoom on the photo whenever a panel becomes visible. Without JavaScript the first space stays visible.

Customization

  • Add a space: copy one button.tpp-tab and one .tpp-panel, then give them matching id, aria-controls and aria-labelledby values.
  • bg-emerald-800 in the group-aria-selected: classes and outline-emerald-700: change the accent of the active icon tile and focus rings.
  • aspect-[4/3] on each img: use aspect-video for a wider preview or aspect-square for a more compact layout.
  • lg:grid-cols-[minmax(0,5fr)_minmax(0,7fr)] on the inner wrapper: give the photo more or less room next to the tabs.
  • grid-cols-2 and sm:grid-cols-1 on the tablist: keep the two-column tab grid on larger phones or use a single column everywhere.
  • rounded-[2rem] on .tpp-panel and its figure: reduce it to rounded-xl for a sharper look.
  • animation: tpp-zoom 0.9s in style.css: shorten or remove the zoom-in when a photo appears.

Use cases

  • Coworking and venue pages: each tab swaps in a large photo of a different space with key facts
  • Hotel sites: visitors explore room types through a photo preview and floating caption
  • Product tours: tabs with icons and short descriptions explain each feature next to its picture
  • Keyboard-friendly sections: arrow keys, Home and End move between tabs

Accessibility

The markup follows the WAI-ARIA tabs pattern: role="tablist" with an aria-label, role="tab" buttons linked to role="tabpanel" regions through aria-controls and aria-labelledby. Only the active tab is in the Tab order; Arrow keys move between tabs (both directions, so the two-column phone layout works too), and Home and End jump to the first and last tab. Panels are focusable with tabindex="0" so keyboard users can reach them, every focusable element has a visible emerald outline, icons are aria-hidden and each photo has a descriptive alt. Animations are disabled under prefers-reduced-motion: reduce.

Usage notes

The photos come from Unsplash and are placeholders; replace them with your own images and update the alt text. Only the first photo loads eagerly. For several tab sections on one page, give each copy unique id values.

Tabs with Photo Preview Panels at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Tabs
License
Free for personal and commercial use

Questions about this template

Can I use the Tabs with Photo Preview Panels 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 Tailwind CSS 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):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Tabs with Photo Preview Panels – Tailwind CSS tabs component screenshot
Tabs with Photo Preview Panels · Tailwind CSS Tabs

More Tabs

Scrollable Tabs for Mobile – Bootstrap 5 tabs preview

Scrollable Tabs for Mobile

Bootstrap 5 tabs that scroll horizontally on small screens, with fade edges, arrow buttons, scroll snapping and the active tab centered automatically.

Animated Pill Tabs – Pure CSS tabs preview

Animated Pill Tabs

Segmented pill tabs with a sliding, springy background, ARIA tabs keyboard support and fading panels, shown on an analytics card. Pure CSS and vanilla JS.

Vertical Tabs – Bootstrap 5 tabs preview

Vertical Tabs

Bootstrap 5 vertical nav-pills tabs styled as a settings panel with a dark sidebar, icons, fading content panes and a scrollable mobile tab strip.

Underline Tabs – Tailwind CSS tabs preview

Underline Tabs

Accessible Tailwind CSS tabs with a sliding underline indicator, arrow-key and Home/End navigation, count badge and scrollable tab bar on mobile.