Simulated tooltips contain informative content that is displayed when hovering over an element with the mouse or the focus is set on an element. They can also be displayed when the element is activated.
They are referred to as “simulated” as they do not use the title attribute included in HTML, often to make them more visually attractive.
aria-label
attribute should nevertheless be correctly interpreted in the near future.
While waiting for improved compatibility, the following solutions are available:
he basic HTML code for a simulated tooltip is very simple:
<a href="#" aria-label="Content of the simulated tooltip">Link heading </a>
<note attention>Warning
Without JavaScript, the proposed content in the tooltip will not be accessible for those who do not use screen readers.
You need to make sure that users can access this content, (for example, by including the content on the target page of the link), or show the content on the initial page, in the event that JavaScript is deactivated.
When the user hovers with the mouse over the element, or the focus is set on the element:
<span>
or <div>
is created in the DOM. This container will be used as the tooltip.aria-label
of the element is duplicated into the newly created container.When the mouse-over moves off the element or the focus is lost, the container is deleted from the DOM.
This behaviour may be applied when the element is activated. Consequently, when the element is deactivated, the simulated tooltip is then deleted from the DOM.