Favourite button with counter in HTML and CSS
Toggle heart buttons that count favourites, remember them between visits and announce them to screen readers.
Here is an excerpt of this component's code in HTML and CSS. The full code is free for members, ready to copy into your project.
This component also comes in
The code in HTML and CSS
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Bouton favori avec compteur</title>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<main class="demo">
<section class="bfc" data-bfc aria-labelledby="bfc-titre">
<header class="bfc-head">document.querySelectorAll("[data-bfc]").forEach((root) => {
const on = (el, type, fn) => el.addEventListener(type, fn);
const KEY = "forge-bfc-favoris";
const buttons = [...root.querySelectorAll("[data-bfc-id]")];
const status = root.querySelector("[data-bfc-status]");
let saved = [];
try {
saved = JSON.parse(localStorage.getItem(KEY) ?? "[]");
} catch {
saved = [];
}
:root {
--bfc-card: #ffffff;
--bfc-text: #2a1f22;
--bfc-muted: #5f5053;
--bfc-line: #efe4e6;
--bfc-heart: #be123c;
--bfc-heart-bg: #fff1f3;
--demo-bg: #f7f1f2;
--demo-text: #2a1f22;
}
@media (prefers-color-scheme: dark) {Free component: copy it freely, including for commercial projects.
Other buttons components in HTML and CSS
Buttons components in HTML and CSS
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

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

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

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

A bar pinned to the bottom of mobile screens with Call and Directions buttons and a live open-now status, built for trades and local shops.
- Tailwind
- React
- CSS
- WordPress

Circular icon buttons with an accessible tooltip on hover and focus.
- Tailwind
- React
- CSS
- WordPress