Skip to content

Icon Buttons with Tooltips

Accessible Tailwind CSS icon buttons with tooltips as labels, toggle states, a keyboard-friendly toolbar, a navigation rail and Escape to dismiss.

Also known as: icon toolbar, navigation rail, text formatting toolbar, tooltip buttons

Icon Buttons with Tooltips live demo

Open in new tab

Tailwind CSS code (HTML, CSS, JS)

Icon-only buttons with accessible tooltips, built with Tailwind CSS, a few lines of custom CSS and a small vanilla JavaScript helper. The demo combines three common places for icon buttons: a dark vertical navigation rail, a text formatting toolbar and the action row of a content card. Each button gets its accessible name from its tooltip, so the label you see on hover is exactly what a screen reader announces.

How it works

The root is .tib-demo. Every icon button or link sits in a .tib-wrap span together with a <span role="tooltip" class="tib-tip">, and the button points to that tooltip with aria-labelledby. The tooltips are positioned and animated in style.css: they appear when the wrapper is hovered (after a short delay), when its button has keyboard focus (:has(:focus-visible)), or when the script adds tib-show. An invisible ::before bridge keeps the tooltip open while the pointer moves onto it, and ::after draws the arrow. data-tib-placement on the wrapper switches between the default top position, bottom, and right (used by the rail from 768 px up; on phones the rail is horizontal and its tooltips drop below).

script.js initializes each .tib-demo on DOMContentLoaded. Buttons with data-tib-toggle flip aria-pressed; buttons that share a data-tib-group value (the three alignment buttons) behave as a single choice. The role="toolbar" element gets a roving tabindex, so it is one Tab stop and the arrow keys, Home and End move between buttons. The data-tib-copy button copies the page address, swaps its tooltip to the data-tib-done text and announces it through the data-tib-status region. Pressing Escape adds tib-hide to any visible tooltip until the pointer or focus leaves.

Customization

  • --tib-tip-bg and --tib-tip-fg on .tib-demo in style.css: change the tooltip and arrow colors in one place.
  • --tib-delay: the hover delay before a tooltip appears; set it to 0s for instant tooltips.
  • --tib-gap: the distance between the button and its tooltip.
  • data-tib-placement="bottom" or "right" on .tib-wrap: move a tooltip below or beside its button; omit it for the top position.
  • aria-pressed:bg-teal-600 aria-pressed:text-white on toolbar buttons: restyle the pressed state, for example with indigo.
  • .tib-kbd inside a tooltip: shows a keyboard shortcut; pair it with aria-keyshortcuts on the button.
  • COPIED_MS in script.js: how long the "Link copied" feedback stays visible.

Use cases

  • App sidebars: a dark vertical navigation rail labels each icon with a tooltip
  • Editors: a text formatting toolbar with toggle states and arrow-key navigation
  • Content cards: an action row of icon buttons keeps the layout compact
  • Accessible interfaces: the tooltip text is also the accessible name, dismissed with Escape

Accessibility

Each icon-only control is named by its role="tooltip" element via aria-labelledby, and every SVG is aria-hidden. Shortcut hints are hidden from the accessible name and exposed through aria-keyshortcuts instead. Tooltips appear on keyboard focus as well as hover, stay visible while hovered and can be dismissed with Escape, which meets WCAG 1.4.13. Toggle buttons expose aria-pressed, the toolbar follows the ARIA toolbar keyboard pattern, the active rail link uses aria-current="page", and all controls have a visible focus outline with targets of at least 40 px. Tooltip motion is removed under prefers-reduced-motion.

Usage notes

Tooltip ids must be unique on the page. Keep tooltip text short, because it doubles as the button name.

Icon Buttons with Tooltips at a glance

Framework
Tailwind CSS
Code
HTML, CSS, JavaScript
JavaScript
Vanilla JavaScript, no jQuery
Dependencies
Tailwind CSS
Layout
Responsive, works on mobile
Category
Icon Buttons
License
Free for personal and commercial use

Questions about this template

Can I use the Icon Buttons with Tooltips code for free?

Yes. You can copy or download the code and use it in personal and commercial projects, including client work. No sign-up is needed. Reselling it as part of a component library or template collection is not allowed; see the license.

How do I add it to my website?

Load Tailwind CSS from a CDN (the links are under Requirements). Paste the HTML where the component should appear, add the CSS to your stylesheet and load the JavaScript before the closing </body> tag. Download HTML gives you a complete page with everything already linked.

Does it need jQuery or a JavaScript framework?

No. The script is plain vanilla JavaScript, so it works without jQuery, React or Vue. You can still use the markup inside those frameworks.

Does it work on mobile?

Yes. The layout adapts to small screens. Use the Mobile and Tablet buttons above the live demo to check it at phone and tablet width.

Requirements

Add these to your page (already included in the download):

  • <script src="https://cdn.jsdelivr.net/npm/@tailwindcss/browser@4"></script>

The Tailwind browser build is for prototyping. In production, compile Tailwind with its CLI or your bundler.

Icon Buttons with Tooltips – free Tailwind CSS icon button template
Icon Buttons with Tooltips · free Tailwind CSS icon button template

More Icon Buttons

Icon Buttons with Ripple – free Pure CSS icon button template

Icon Buttons with Ripple

Round icon buttons with a Material-style ripple, toggle states and tooltips: standard, filled, tonal and outlined variants in three sizes.

Like, Share and Bookmark Icon Buttons – free Bootstrap 5 icon button template

Like, Share and Bookmark Icon Buttons

Bootstrap 5 like, share and bookmark toggle buttons with active states, animated icons and live counters in pill and compact round styles.