Skip to main content
The Cart Counter section displays a shopping bag icon with a real-time badge showing the number of items in the customer’s cart. This functional component is automatically integrated into the header and updates dynamically as items are added or removed, providing instant visual feedback to customers about their cart status. This header-only component requires no configuration - it works automatically once added to your theme.

What this section controls

This section controls cart icon displays with the following capabilities:
  • Shopping bag icon in header navigation
  • Real-time item count badge
  • Dynamic updates on cart changes (add/remove/quantity)
  • Auto-hide badge functionality when cart is empty
  • High count display (100+ shows ”+” symbol)
  • Automatic integration with header
  • No configuration required - works automatically

How It Works

The Cart Counter provides essential cart feedback to customers:

Shopping Bag Icon

Displays a theme bag icon that serves as the cart access point in navigation

Item Count Badge

Shows the total number of items currently in the cart

Dynamic Updates

Automatically updates when items are added, removed, or quantity changes

Auto-Hide Empty

Badge disappears when cart is empty for cleaner visual presentation

Display Behavior

Badge Display Logic

  • Shopping bag icon remains visible
  • Count badge is hidden
  • Clean, minimal appearance
  • Badge displays exact item count
  • Example: 3 for 3 items in cart
  • Small caption styling for compact display
  • Badge displays + symbol
  • Indicates more than 99 items
  • Prevents badge overflow on large quantities

Visual Elements

The cart counter consists of three components:
  1. Icon: Theme bag icon (SVG graphic)
  2. Badge: Circular count indicator positioned over icon
  3. Screen Reader Text: Accessibility label (“Cart” or localized equivalent)

Accessibility

Includes visually-hidden text that announces “Cart” to screen reader users, ensuring accessible navigation for all customers.
Cart count changes are announced to assistive technologies when items are added or removed (handled by cart drawer/notification system).
Cart icon is fully keyboard accessible as part of the header navigation, allowing keyboard-only users to access cart.

Integration Points

The Cart Counter automatically integrates with:

Header Section

Embedded in header navigation, typically in top-right corner

Cart Drawer

Opens cart drawer when clicked (desktop) or navigates to cart page (mobile)

Add to Cart Actions

Updates automatically when “Add to Cart” is triggered anywhere on the site

Cart Updates

Reflects quantity changes and item removals in real-time

Technical Details

Real-Time Updates

The cart counter uses Shopify’s cart object ({{ cart.item_count }}) to display the current cart state:
  • Server-rendered initial state: Shows correct count on page load
  • JavaScript updates: Refreshes dynamically during session without page reload
  • No configuration needed: Automatically tracks all cart mutations

Badge Styling

  • Size: Caption small (compact, readable)
  • Visibility: Hidden when count = 0, visible otherwise
  • Overflow handling: Shows + for counts exceeding 99
  • Position: Overlays top-right of shopping bag icon

Use Cases

Desktop Navigation

Prominent cart indicator in header for quick cart access and visual feedback

Mobile Menu

Essential cart visibility on mobile devices with limited screen space

Quick Add Feedback

Immediate visual confirmation when products are added from collection pages

Shopping Progress

Helps customers track how many items they’ve selected during browsing

Best practices

Header placement

Position the cart counter in a consistent location, typically top-right of the header, with adequate spacing from other elements. Make the icon large enough for mobile touch targets (44px minimum) and maintain visibility across all header variants and states.

Visual design

Use sufficient color contrast for the badge against your header background, ensuring it’s visible over the icon without obscuring it completely. Style the badge to match your theme’s button or accent colors, and consider subtle animations like a pulse or scale effect when the count changes.

Performance

The cart counter is lightweight with minimal performance impact, as updates are handled efficiently through Shopify’s cart API. No lazy loading is needed since this is an essential UI component that should always be immediately visible.

User experience

Clicking the counter should open a cart drawer or navigate to the cart page with clear visual feedback through hover and active states. Consider showing a mini cart preview on hover for desktop users, and ensure mobile users can easily tap and access their cart.

Customization

While the Cart Counter section has no built-in settings, developers can customize it through theme code:

Icon Customization

Replace the default bag icon by modifying the icon name parameter:
{% render 'icon', icon_name: 'your-custom-icon' %}

Badge Threshold

Adjust the 99+ threshold by changing the conditional logic:
{%- if cart.item_count > 99 -%}+{%- else -%}{{- cart.item_count -}}{%- endif -%}

Badge Visibility

Modify when the badge appears by adjusting the hidden class condition:
{% if cart.item_count == 0 %} hidden{% endif %}
Code customizations require theme development knowledge and should be tested thoroughly across all devices and cart states.

Troubleshooting

Possible Causes:
  • Cart is empty (badge auto-hides at 0 items)
  • CSS styling hiding the badge
  • JavaScript not updating cart count
Solutions:
  1. Add item to cart to verify badge appears
  2. Check browser console for JavaScript errors
  3. Verify cart object is accessible in theme
Possible Causes:
  • JavaScript cart functions not working
  • Page caching preventing updates
  • Theme customizations breaking cart API
Solutions:
  1. Hard refresh page (Cmd+Shift+R / Ctrl+Shift+R)
  2. Check browser console for errors
  3. Test in incognito mode to rule out caching
  4. Verify cart drawer/notification scripts are loaded
Possible Causes:
  • Multiple tabs with same cart session
  • Variant quantity vs line item count confusion
  • Cart data not syncing properly
Note: cart.item_count shows total quantity of all items, not number of unique products. For example, 3x Product A + 2x Product B = count of 5.


Quick Summary

  • Type: Functional component (no configuration)
  • Location: Header navigation
  • Display: Icon + badge (auto-hides when empty)
  • Updates: Real-time cart tracking
  • Count Display: 1-99 exact, 100+ shows ”+”
  • Accessibility: Full screen reader support
  • Customization: Code-level only (no Theme Customizer settings)
The Cart Counter is essential for e-commerce UX - ensure it’s prominently visible and working correctly across all pages and devices.