Interactivity
Most of what feels interactive on a storefront (tabs, accordions, sliders, hover reveals, lightboxes) can be built with CSS alone. CSS-only sections load instantly, cannot break the page, and need no review of scripts. Reach for JavaScript only for what CSS genuinely cannot do.
Techniques
| Technique | Mechanism | Use it for |
|---|---|---|
| Scroll-snap | scroll-snap-type: x mandatory on an overflow container | Sliders, carousels, swipe rows |
| Native disclosure | <details> / <summary> | Accordions, FAQs, price lists |
| Anchor targeting | :target with #id links | Tabs, lightboxes, step-throughs |
| Checked sibling | hidden <input type="radio"> with :checked ~ | Tabs, filter chips, variant pickers |
| Native controls | <select>, <input type="number"> | Quantity pickers (read by cart-add) |
| Hover / focus-within | :hover, :focus-within | Reveals, hover galleries, tooltips |
| Keyframes | @keyframes with animation | Marquees, tickers, gradient motion |
| Sticky | position: sticky | Stacked-card scroll, sticky rails, sticky buy bars |
| Grid | CSS Grid, grid-auto-flow: dense | Bento, editorial and masonry-ish layouts |
Every one of these falls back to a plain, readable page if the CSS fails. None can leave a section blank.
Tabs
Hidden radio buttons hold the state; :checked ~ shows the matching panel. The labels are the tabs. Click them in the preview.
Runs in your browser on sample data: the same engine and filters as the storefront. Widgets such as add to cart are simulated: clicking one shows what would happen on a store.
Accordion
<details> and <summary> open and close on their own, work with the keyboard, and are announced by screen readers.
Swipe slider
scroll-snap turns an overflowing row into a slider that swipes on phones and scrolls with a trackpad. For arrows, dots and autoplay, use the carousel widget and keep this as its fallback.
Marquee
The content is rendered twice and the track slides by half its width, so the loop is seamless. The second copy is aria-hidden, and the animation stops for visitors who ask for reduced motion.
Lightbox
Each thumbnail links to an id; :target shows the matching overlay and the close link clears it. The preview keeps in-page links working, so you can try it.
When you need a script
These need state that CSS cannot hold:
Countdown timer · Live product filtering or sorting · A dismissible modal that stays dismissed · Animated counters · Drag before/after · Infinite scroll
Build them with a script in the section (see Tags & snippets for the rules), or point merchants to the built-in sections that already do them. For the cart, search, saved items, forms and carousels, use the storefront widgets: they are already on every store and need no script from you.
Do not fake it