Skip to content

Responsive Product Grid with Sort Bar

Pure CSS product grid with photo cards, a results count and a sort dropdown that reorders items by price, rating or date with vanilla JS.

Also known as: product listing grid, product grid with sorting, shop product cards grid, sortable product list, ecommerce product listing

Responsive Product Grid with Sort Bar live demo

Open in new tab

Pure CSS code (HTML, CSS, JS)

A responsive product grid in pure CSS with a sort bar above it: a results count on the left and a "Sort by" dropdown on the right that reorders the cards by price, rating or date with a few lines of vanilla JavaScript. Use it for shop category pages, new-arrival sections and catalog listings.

How it works

The root section.psb-shop holds a heading, the .psb-bar and a ul.psb-grid. The bar contains .psb-count (with .psb-count-num and .psb-count-sort) and a native select.psb-select wrapped in .psb-select-wrap, which draws a custom chevron with a pseudo-element. Each product is an li.psb-item with an article.psb-card: a .psb-media box with the photo and an optional .psb-badge, then .psb-body with category, name, .psb-price and .psb-rating. The product name link .psb-link uses a stretched ::after, so the whole card is clickable while the markup keeps a single link.

The sort data lives on each li.psb-item as data-order (featured position), data-price, data-rating and data-date (ISO date). On DOMContentLoaded the script sets the count from the number of items. When the select fires change, it sorts the items with the matching compare function, falls back to data-order for ties, re-appends them in one fragment, briefly adds .is-sorting for a fade-in and updates the "sorted by" text. It also dispatches a psb:sort event with detail.sort, so you can load server-side results instead. Without JavaScript the grid simply stays in the featured order.

Customization

  • --psb-cols on .psb-shop: the number of columns. It is 2 on phones, 3 from 720px and 4 from 1024px; change the values in the media queries.
  • --psb-accent: badge, eyebrow, star and focus color; --psb-sale colors the .psb-badge--sale discount badge.
  • --psb-bg, --psb-card and --psb-media-bg: page, card and image placeholder backgrounds.
  • --psb-max: the maximum content width; the side padding grows on wide screens so the background stays full width.
  • aspect-ratio: 5 / 4 on .psb-media: use 1 / 1 for square photos or 3 / 4 for portrait fashion shots.
  • Add an <option> to .psb-select and a function with the same key in the sorters object in script.js to support a new sort such as name.

The photos come from Unsplash; replace them with your own product images and keep the width and height attributes.

Use cases

  • Online shops: photo product cards show in a responsive grid with a results count
  • Category pages: a sort dropdown reorders items by price, rating or date
  • Marketplaces: shoppers browse large catalogs with quick client-side sorting
  • Store prototypes: vanilla JavaScript sorting works without a framework or backend

Accessibility

The sort control is a real select with a visible label, so it works with the keyboard and screen readers on every platform. .psb-count is an aria-live="polite" region, so the new order is announced after a change. Ratings include visually hidden text ("out of 5 stars") and the old price is marked "was". Each card shows a clear focus ring through the stretched link, and the select has its own outline. Hover lifts and the sorting fade are disabled with prefers-reduced-motion: reduce.

Usage notes

Several grids can share a page; the script scopes each one to its own .psb-shop. Give each select a unique id.

Responsive Product Grid with Sort Bar at a glance

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

Questions about this template

Can I use the Responsive Product Grid with Sort Bar 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.

Responsive Product Grid with Sort Bar – free Pure CSS product grid template
Responsive Product Grid with Sort Bar · free Pure CSS product grid template

More Product Grids

Product Grid with Filters – free Tailwind CSS product grid template

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.

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.