Skip to content

Product Grid with Filters

Tailwind CSS category page with a collapsible filter sidebar, live result count, empty state and a product grid sortable by price, rating or date.

Also known as: product filter, filter sidebar, ecommerce category page, product listing with filters

Product Grid with Filters live demo

Open in new tab

Tailwind CSS code (HTML, JS)

A Tailwind CSS category page with a filter sidebar and a sortable product grid, the classic layout for online stores, catalogs and marketplace listings. Shoppers can narrow ten sample products by category, price range, color and stock, sort them five ways, and see the result count update instantly, all handled by a small vanilla JavaScript file.

How it works

The root is .tpg-shop. Below the breadcrumb, the header holds the page title, a live result count (data-tpg-count), a mobile "Filters" button (data-tpg-toggle) and the sort select (data-tpg-sort). The body is a two-column grid from lg up (lg:grid-cols-[15rem_minmax(0,1fr)]): the aside#tpg-filters with a form (data-tpg-form) and the product list (data-tpg-grid).

Every product is an li.tpg-item that stores its facts in data attributes: data-category, data-price, data-color, data-stock, data-rating and data-added. The script reads them once on DOMContentLoaded and keeps the original order as the "Featured" sort.

A single change listener on the form re-runs the filter: checked categories and colors are combined with OR inside each group and AND across groups, the price radio value such as 50-199 is split into a min and max, and "In stock only" drops items whose data-stock is false. Non-matching items get the hidden attribute, the visible ones are re-appended in the chosen sort order, and the count text is rewritten. When nothing matches, the grid hides and the data-tpg-empty panel appears with a data-tpg-clear button. The form's native reset button clears everything. Below lg, the sidebar starts collapsed and the toggle button shows the number of active filters in data-tpg-active.

Customization

  • data-price, data-category and the other data attributes on each .tpg-item: describe your own products; the filters read them, not the visible text.
  • value on the price radios (for example 0-49): set any min-max range in whole currency units.
  • SORTERS in script.js: add a new sort function and a matching option in data-tpg-sort, such as sorting by name.
  • md:grid-cols-3 xl:grid-cols-4 on data-tpg-grid: change the number of columns per breakpoint.
  • lg:grid-cols-[15rem_minmax(0,1fr)]: widen or narrow the sidebar column.
  • accent-emerald-700 and the emerald utilities: swap to another Tailwind color to rebrand checkboxes, badges and focus rings.
  • Replace the placehold.co images with your product photos; keep width, height and aspect-square to avoid layout shift.

Use cases

  • Online stores: let shoppers filter by category, price, color and stock
  • Catalogs and marketplaces: a listing page with live result count and sorting
  • Empty-state handling: shows a clear message when no product matches the filters

Accessibility

Filters are grouped in fieldset elements with a legend, using native checkboxes and radios, so they work with the keyboard and screen readers. Color swatches are visually hidden checkboxes with readable names. The result count is a role="status" region, so every filter change is announced. The mobile toggle uses aria-expanded and aria-controls and moves focus into the panel when it opens. All links and controls show an emerald focus outline. The image hover zoom is disabled with motion-reduce:transition-none.

Usage notes

Filtering happens in the browser and suits catalogs of up to a few hundred items. For larger catalogs, send the form values to your server with fetch() in the update function and render the returned items instead.

Product Grid with Filters at a glance

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

Questions about this template

Can I use the Product Grid with Filters 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 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 Grid with Filters – free Tailwind CSS product grid template
Product Grid with Filters · free Tailwind CSS product grid template

More Product Grids

Product Listing Grid – free Bootstrap 5 product grid template

Product Listing Grid

Responsive Bootstrap 5 product grid with sale, new, bestseller and sold-out badges, color swatches, wishlist buttons, sorting and client-side pagination.

Product Grid with Quick Add on Hover – free Tailwind CSS product grid template

Product Grid with Quick Add on Hover

Tailwind CSS product grid where a quick add bar slides up over each photo on hover or focus, with a live bag counter and wishlist toggle.