A load more button with an item counter, built with Tailwind CSS and a few lines of vanilla JavaScript. It reveals a grid of color palette cards in batches and keeps a "Showing 6 of 18 palettes" line and a thin progress bar in sync, so visitors always know how much is left. Use it for galleries, product listings or archives where numbered pagination feels too heavy.
How it works
The root is section.lmc-root. All cards are already in the markup as li.lmc-item elements inside #lmc-list, so the content is crawlable and fully visible when JavaScript is off. The .lmc-footer with the counter, the role="progressbar" track and the [data-lmc-button] starts with the hidden attribute and only appears once the script runs.
On DOMContentLoaded the script initializes every .lmc-root. It reads the batch size from data-lmc-step, hides every item beyond that number and fills [data-lmc-shown] and [data-lmc-total]. A click on the button sets aria-busy, shows the .lmc-spinner and changes the label to "Loading…". After the simulated LOAD_DELAY the next batch is unhidden, the counter, aria-valuenow and the width of [data-lmc-bar] are updated, and focus moves to the first newly revealed card. When nothing is left, the button is disabled and reads "All palettes loaded".
Customization
data-lmc-step="6"on.lmc-root: set how many items are shown at first and added per click; the button label follows automatically, e.g. "Load 4 more".LOAD_DELAYat the top ofscript.js: shorten or remove the fake delay. To load from a server, replace thesetTimeoutinloadMore()with afetch()call and append the returned items as newli.lmc-itemelements before callingrender().bg-teal-700on[data-lmc-bar]andhover:bg-teal-800on the button: swaptealfor your brand color.bg-[#f6f1e9]on the root: change the warm paper background, or usebg-whitefor a neutral page.sm:grid-cols-2 lg:grid-cols-3on#lmc-list: switch tolg:grid-cols-4anddata-lmc-step="8"for a denser grid.- "All palettes loaded" and "palettes" in
script.jsand[data-lmc-counter]: rename to products, posts or photos. - Each palette is an
articlewith fivebg-[#hex]swatches; replace the article contents with your own card markup and keep thelmc-itemclass on theli.
Use cases
- Product listings: a grid reveals more items in batches instead of using page numbers
- Blog archives: a Showing X of Y counter tells readers how much is left
- Portfolios and galleries: a progress bar shows how much of the collection is visible
- Search results: visitors keep control by loading only when they want more
Accessibility
The counter paragraph is an aria-live="polite" region, so screen readers announce the new total after each batch. The progress track uses role="progressbar" with aria-valuemin, aria-valuemax and aria-valuenow, and the button points to the list with aria-controls and reports aria-busy while loading. Moving focus to the first new card (each card is an article with tabindex="-1" and an aria-label) lets keyboard users continue reading without tabbing through old items. Each swatch strip is a single role="img" with the hex codes as its label, the heart icons are aria-hidden with a sr-only "likes" suffix, focus rings are visible, and the spinner and transitions stop under prefers-reduced-motion.
Usage notes
For several lists on one page, give each copy unique id values for #lmc-list and #lmc-title; the script scopes all queries to its own .lmc-root.