A set of Bootstrap 5 like, share and bookmark icon buttons with toggleable active states and live counters, shown in two styles: outlined pills under a post card and a compact dark bar of round buttons. Use them on blog posts, social feeds, recipe pages or any content that people can react to and save.
How it works
The root section.lsb-demo holds an article.lsb-post and a second .lsb-actions--round bar. Each .lsb-actions element is a role="group" containing three button.lsb-btn elements. Every button carries its state in aria-pressed, its raw number in data-lsb-count, the outline and filled Bootstrap Icons in data-lsb-icon and data-lsb-icon-active, and two short messages in data-lsb-on and data-lsb-off.
The script runs on DOMContentLoaded and loops over every .lsb-actions group. On click it flips aria-pressed, adds or subtracts one from the count, writes the formatted number into .lsb-count (values from 1000 are shortened by formatCount(), so 1194 becomes "1.2k") and swaps the icon class, for example bi-heart to bi-heart-fill. Activating a button adds .lsb-pop, which scales the icon with the lsb-pop keyframes. Each click also dispatches a bubbling lsb:change event with { active, count } in detail, the place to connect your own API.
The CSS gives every button a --lsb-tone color. When aria-pressed="true" the pill takes that color and a 12% tinted background through color-mix(). In the round variant the icon circle fills with the tone instead.
Customization
--lsb-like,--lsb-shareand--lsb-savein.lsb-demo: change the active color of each button type.--lsb-bg,--lsb-cardand--lsb-inkin.lsb-demo: recolor the page background, the post card and the dark compact bar.--lsb-radiusin.lsb-demo: make the post card corners rounder or square.data-lsb-counton a.lsb-btn: set the starting number; keep the visible.lsb-counttext in sync.aria-pressed="true"on a button plus the filled icon class: show it as already liked, shared or saved on load.data-lsb-iconanddata-lsb-icon-active: use other Bootstrap Icons, such asbi-hand-thumbs-upandbi-hand-thumbs-up-fill.- Remove
ms-autofrom.lsb-btn--saveto keep the bookmark button next to the others instead of pushing it right. - Listen for
lsb:changeon the root and callfetch()to store the state on your server.
Use cases
- Blog posts: like, share and bookmark pills sit under the article with live counters
- Social feeds: each post gets its own independent group of toggle buttons
- Recipe sites: visitors save favorites with a bookmark button that fills when active
- Content platforms: a lsb:change event reports every toggle so you can store it through your API
Accessibility
All controls are native button elements with aria-pressed, so screen readers announce them as toggle buttons. Each has a visually-hidden label (Like, Share, Bookmark) followed by the count, and the icons are aria-hidden. A visually hidden .lsb-status element with role="status" in each group announces messages such as "Saved to bookmarks". Buttons have a 44px touch target and a 3px :focus-visible outline in the button's tone. Text colors pass WCAG AA on the light card. The pop animation and color transitions are turned off with prefers-reduced-motion: reduce.
Usage notes
Requires Bootstrap 5 and Bootstrap Icons. Copy one .lsb-actions group per post; groups work independently, so a feed can contain any number of them.