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.

A screenshot of a list where one item is being hovered, revealing a small tooltip pop-up above it.

Get Source Code Preview

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

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:

View Output