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
Empty Cart (0 items)
Empty Cart (0 items)
- Shopping bag icon remains visible
- Count badge is hidden
- Clean, minimal appearance
Standard Count (1-99 items)
Standard Count (1-99 items)
- Badge displays exact item count
- Example:
3for 3 items in cart - Small caption styling for compact display
High Count (100+ items)
High Count (100+ items)
- Badge displays
+symbol - Indicates more than 99 items
- Prevents badge overflow on large quantities
Visual Elements
The cart counter consists of three components:- Icon: Theme bag icon (SVG graphic)
- Badge: Circular count indicator positioned over icon
- Screen Reader Text: Accessibility label (“Cart” or localized equivalent)
Accessibility
Screen Reader Support
Screen Reader Support
Includes visually-hidden text that announces “Cart” to screen reader users, ensuring accessible navigation for all customers.
Live Updates
Live Updates
Cart count changes are announced to assistive technologies when items are added or removed (handled by cart drawer/notification system).
Keyboard Navigation
Keyboard Navigation
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:Badge Threshold
Adjust the 99+ threshold by changing the conditional logic:Badge Visibility
Modify when the badge appears by adjusting the hidden class condition:Troubleshooting
Badge Not Showing
Badge Not Showing
Possible Causes:
- Cart is empty (badge auto-hides at 0 items)
- CSS styling hiding the badge
- JavaScript not updating cart count
- Add item to cart to verify badge appears
- Check browser console for JavaScript errors
- Verify cart object is accessible in theme
Count Not Updating
Count Not Updating
Possible Causes:
- JavaScript cart functions not working
- Page caching preventing updates
- Theme customizations breaking cart API
- Hard refresh page (Cmd+Shift+R / Ctrl+Shift+R)
- Check browser console for errors
- Test in incognito mode to rule out caching
- Verify cart drawer/notification scripts are loaded
Wrong Item Count
Wrong Item Count
Possible Causes:
- Multiple tabs with same cart session
- Variant quantity vs line item count confusion
- Cart data not syncing properly
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.Related Components
Cart Drawer
The slide-out cart panel that opens when cart counter is clicked
Header
Primary navigation section where cart counter is embedded
Predictive Search
Another header component providing real-time search functionality
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)