Skip to content

Recently Viewed Products for Shopify

Shopify section that remembers the products a shopper opened and shows them in a scroll-snap row, with prices, arrow buttons and a clear history button.

Also known as: shopify recently viewed products section, recently viewed products without app, shopify recently viewed liquid, shopify browsing history section, recently viewed products carousel

Preview with sample data

Open in new tab

Liquid code

A recently viewed products section for Shopify that needs no app. It remembers the products a shopper opens and shows them as a compact, swipeable row with prices and a Clear history button. Use it on product pages, the home page or the cart page to help shoppers get back to items they looked at. Copy section.liquid into your theme's sections folder and add it from the theme editor as "WDS Recently viewed".

How it works

On a product page, the section saves the product's handle in the browser's localStorage, newest first, keeping the last 12. On any page, it reads that list and loads each product from Shopify's /products/{handle}.js endpoint, then builds cards with image, title, price, compare-at price and a Sold out note. The product being viewed is left out of its own row.

The section stays hidden until there is something to show, so first-time visitors never see an empty block. Deleted products are dropped from the list on their own. Cards sit in a scroll-snap row: shoppers swipe on phones, and on wider screens round arrow buttons page through the row once it overflows.

Clear history removes the saved list and replaces the row with a short confirmation. In the theme editor, sample cards and a note show the layout, because your own browsing history is usually empty there.

Customization

In the theme editor:

  • Heading and Subheading.
  • Products to show (2 to 8).
  • Hide the product being viewed and Show "Clear history" button.
  • Labels: Clear history button, Message after clearing, Sold out, the price prefix for variable prices and the hidden screen reader texts.
  • Background, Text, Accent (focus outlines), Card borders and Sale price colors.
  • Side padding, Top padding and Bottom padding.

Accessibility

The row is a list named by the section heading, and every card is a single link with the product title as its text. The arrow buttons have screen reader labels and are disabled at the ends of the row. After Clear history, focus moves to the confirmation message, which is announced as a status. Focus outlines are visible, and smooth scrolling is turned off for people who prefer reduced motion.

Usage notes

This section requires an Online Store 2.0 theme. Add it to your product template so views are recorded; add it to other templates too if you want the row there.

The history lives only in the shopper's browser: it does not follow them to another device and is lost when they clear site data. Prices are formatted in the browser with your store's money format; if you sell in several currencies, check that the row shows prices the way your theme does.

The preview shows sample products from an invented store with photos from Unsplash written into the page; on your store the cards come from real browsing history. Its links go nowhere.

Recently Viewed Products for Shopify at a glance

Framework
Shopify
Code
Liquid
JavaScript
Not needed
Dependencies
fonts.googleapis.com
Layout
Responsive, works on mobile
Category
Product Grids
License
Free for personal and commercial use

Questions about this section

Can I use the Recently Viewed Products for Shopify code for free?

Yes. You can copy or download the Liquid 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 Shopify store?

Create a new section named shopify-recently-viewed in your theme code editor, paste the Liquid code and save. Then add the section to a page in the theme editor. It works with Online Store 2.0 themes.

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.

How to install

  1. In your Shopify admin, go to Online Store > Themes, open the theme's menu and choose Edit code.
  2. Under Sections, add a new section named shopify-recently-viewed, replace its contents with the Liquid code above and save.
  3. Open the theme editor, choose Add section and add it to the page.

Requires an Online Store 2.0 theme. Try it on a copy of your theme first. WebDevSnippets is not affiliated with or endorsed by Shopify.

Recently Viewed Products for Shopify – free Shopify product grid template
Recently Viewed Products for Shopify · free Shopify 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.

Collection Tabs Product Grid for Shopify – free Shopify product grid template

Collection Tabs Product Grid for Shopify

Shopify section with pill tabs for up to four collections, each showing a product grid with sale and compare-at prices, sold out badges and a View all link.

Build Your Own Bundle Section for Shopify – free Shopify product grid template

Build Your Own Bundle Section for Shopify

Shopify section where shoppers pick a set number of products from a collection, see them in a bundle tray with a live total, and add the whole bundle to the cart at once.

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

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.