Skip to content

Toggle button toolbar in HTML and CSS

A group of icon buttons with a single active choice, like text alignment.

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

Open in a new tab

The code in HTML and CSS

index.html
<!doctype html>
<html lang="fr">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Barre de boutons bascule</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <main class="demo">
      <div class="toolbar" role="toolbar" aria-label="Alignement du texte" data-toolbar>
        <button type="button" class="toolbar__button" aria-pressed="true" aria-label="Aligner à gauche">
style.css
:root {
  --toolbar-bg: #ffffff;
  --toolbar-border: #d4d4d8;
  --toolbar-icon: #52525b;
  --toolbar-active-bg: #18181b;
  --toolbar-active-icon: #ffffff;
  --toolbar-hover: #f4f4f5;
  --toolbar-ring: #2563eb;
  --demo-bg: #f4f4f5;
  --demo-text: #18181b;
}
toolbar.js
document.querySelectorAll("[data-toolbar]").forEach((toolbar) => {
  const buttons = [...toolbar.querySelectorAll("button")];

  function select(button) {
    buttons.forEach((candidate) => {
      const active = candidate === button;
      candidate.setAttribute("aria-pressed", String(active));
      candidate.tabIndex = active ? 0 : -1;
    });
  }

  buttons.forEach((button, index) => {

Free component: copy it freely, including for commercial projects.

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
    Component
  • Toggle heart buttons that count favourites, remember them between visits and announce them to screen readers.

    • 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
  • 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
    Component