Skip to content

Favourite button with counter

Toggle heart buttons that count favourites, remember them between visits and announce them to screen readers.

  • Tailwind
  • React
  • CSS
  • WordPress
Open in a new tab

Description

On a list of recipes, products or listings, each item carries a heart button: one press adds it to favourites, the heart fills with a small bounce and the counter next to it goes up by one; a second press removes it. The “My favourites” total updates at the top of the list and the choice is kept in the browser’s local storage, with no account or server (in private browsing the buttons work for the visit). It is a real toggle button: aria-pressed gives the state, the accessible name mentions the item, and a role="status" region announces that the item joined or left the favourites. 44 px targets, visible focus outline, active state readable without colour thanks to the filled heart, AA contrast in light and dark mode. The bounce is removed with prefers-reduced-motion. To plug in your own counter, replace data-bfc-base with the value from your database.

Code

Loading the code…

The code of this component in

Archive contents

bouton-favori-compteur-html-tailwind.zip3 files · 5 Ko

  • index.html9 Ko
  • README.md4 Ko
  • LICENSE.md1 Ko

Tags

Updated on December 3, 2026.

Reviews

No reviews yet.

In the same spirit

  • A row of buttons to share the page on Facebook, LinkedIn, WhatsApp or by email, with a copy-link button and no third-party script.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A button that adds an event to Google Calendar, Outlook or any calendar through an .ics file, with no third-party service.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A button that copies an IBAN, a reference, an address or a promo code and confirms "Copied", on screen and to screen readers.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A WhatsApp button pinned to the bottom of the screen that opens a welcome bubble with common topics and a pre-filled message, with no third-party widget.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component