List with Tooltips Template
An elegant list where hovering over an item displays a helpful, non-intrusive tooltip.
This template is perfect for providing definitions, hints, or extra information without cluttering the main interface. The tooltip content is stored in a data attribute.

About this Template
This component demonstrates a modern, pure-CSS approach to creating tooltips. The text for each tooltip is stored in a data-tooltip
attribute directly in the HTML of the list item. The tooltip itself is generated using the ::before
and ::after
pseudo-elements, which means no extra HTML elements are required. The visibility and animation of the tooltip are controlled entirely by the :hover
pseudo-class and CSS transitions.
Features
- Pure CSS Tooltips: The entire effect is created without any JavaScript.
- Content from Data Attributes: Tooltip text is pulled from an HTML
data-tooltip
attribute using the CSSattr()
function. - Animated & Positioned: Tooltips fade and scale into view smoothly and include a small "arrow" pointing to their parent item.
- Self-Contained: The component is fully self-contained and ready to drop into any project.
- Accessible Placeholder: While these CSS-only tooltips are not fully accessible to all users (especially non-sighted keyboard users), they serve as an excellent starting point. A fully accessible version would require JavaScript to create and manage the tooltip with ARIA roles.
Code Breakdown
Each list item, li
, has a class of .tooltip-item
and a data-tooltip
attribute containing the tooltip text. We set position: relative
on the list item so we can position its pseudo-elements relative to it.
The main body of the tooltip is created with the ::before
pseudo-element. The content
property is set to attr(data-tooltip)
to pull in the text. By default, it's hidden with opacity: 0
. The small triangular arrow is created using the ::after
pseudo-element, using a clever border trick.
When the user hovers over a .tooltip-item
, the .tooltip-item:hover::before
and .tooltip-item:hover::after
rules are activated. These change the opacity
to 1
, making the tooltip and its arrow visible. The transition
property on the base pseudo-elements ensures this change happens smoothly.
Code
Here's the full code for the template: