Skip to content

Product Detail with Gallery

Dark Tailwind CSS product page section with a thumbnail image gallery, finish options, quantity stepper and add to cart button with loading state.

Also known as: product page gallery, product image gallery with thumbnails, single product page layout, add to cart section

Product Detail with Gallery live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

A dark Tailwind CSS product detail section with an image gallery, finish options, a quantity stepper and an "Add to cart" button with a loading state. It is the core of any single-product page in an online store, shown here for a pair of wireless headphones on a zinc and lime palette.

How it works

The root is .tpd-product. From lg up the layout splits into two columns: the gallery on the left and the product information on the right; on phones they stack.

The gallery (.tpd-gallery) has one large image marked data-tpd-main plus four thumbnail buttons marked data-tpd-thumb. Each thumbnail stores the full-size URL and alt text in data-src and data-alt. Clicking a thumbnail, pressing the data-tpd-prev / data-tpd-next arrows or using the arrow keys on a focused thumbnail calls show(), which swaps the image, moves aria-current="true" to the active thumbnail, updates the data-tpd-counter text and replays the tpd-fade animation through the .tpd-main--swap class. Tailwind's aria-[current=true]: variants draw the lime ring on the active thumbnail.

Finishes are visually hidden radio buttons with pill labels styled through peer-checked:; a change listener writes the chosen name into data-tpd-finish. The quantity input (data-tpd-qty) sits between two data-tpd-step buttons; clampQty() keeps the value between the input's min and max and disables a button at either limit. Submitting the form disables data-tpd-add, shows the .tpd-spinner, waits 800 ms to simulate a request and then announces the result in data-tpd-status. The Features and Shipping panels are native details elements, so they work without JavaScript.

Customization

  • data-src, data-alt and the inner img on each data-tpd-thumb: point to your own photos; add or remove li items freely, the counter adapts.
  • max="5" on #tpd-qty: change the per-order limit for the stepper.
  • The setTimeout in the submit handler of script.js: replace it with a fetch() call to your cart endpoint.
  • lime-300 utilities (for example bg-lime-300 on data-tpd-add): swap for sky-400 or amber-300 to rebrand the accent.
  • lg:flex-row-reverse on .tpd-gallery plus lg:w-20 and lg:grid-cols-1 on the thumbnail list: remove them to keep the thumbnails under the main image on desktop.
  • Add the open attribute to the second details element to show shipping information by default.

Use cases

  • Online stores: the core of a single-product page with a thumbnail gallery beside the product information
  • Electronics and gadget shops: shoppers pick a finish, set the quantity and add to cart with a loading state
  • Product launch pages: arrows and thumbnails swap the main image while a counter shows the current photo
  • Dropshipping shops: collapsible Features and Shipping panels keep the page compact without any JavaScript

Accessibility

The gallery is a labelled region; thumbnails are real buttons with visually hidden names, and the active one carries aria-current. The image counter is a polite live region, and the main image's alt text changes with each photo. Finish options are native radios inside a fieldset with a legend, the quantity field has a label and both stepper buttons have names. The cart result is announced via role="status". Lime focus outlines are visible against the dark background, and the fade, spinner and icon rotations stop under prefers-reduced-motion: reduce.

Usage notes

For several products on one page, give each instance unique id values (tpd-title, tpd-qty). The finish radios can keep name="tpd-finish" because each instance has its own form, and the script scopes every query to its .tpd-product root.

Product Detail with Gallery at a glance

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

Questions about this template

Can I use the Product Detail with Gallery 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.

Product Detail with Gallery – free Tailwind CSS product detail page template
Product Detail with Gallery · free Tailwind CSS product detail page template

More Product Details

Bootstrap Product Page – free Bootstrap 5 product detail page template

Bootstrap Product Page

Bootstrap 5 product details page with image gallery, color and size pickers, quantity stepper, and tabs for description, specifications and customer reviews.

Frequently Bought Together Section for Shopify – free Shopify product detail page template

Frequently Bought Together Section for Shopify

Shopify section that shows the current product with up to 3 picked products, checkboxes, variant selects, a live total and one button that adds everything checked to the cart.

Sticky Add to Cart Bar for Shopify – free Shopify product detail page template

Sticky Add to Cart Bar for Shopify

Shopify section: a bar fixed to the bottom of product pages that appears once the main add-to-cart button scrolls away, with image, price, variant select and a real product form.

Product Detail with Image Zoom Lens – free Tailwind CSS product detail page template

Product Detail with Image Zoom Lens

Tailwind CSS product detail section with a round magnifier lens that zooms the photo on hover or arrow keys, plus adjustable 2x to 4x levels.