It can be done using only CSS. No JavaScript required.
Apply the custom HTML attribute.
for example
***
something here
***
Define the :before pseudoelement of each [data-tooltip] object to be transparent, absolutely positioned and with data-tooltip="" value as content:
***
[data-tooltip]:before {
position : absolute;
content : attr(data-tooltip);
opacity : 0;
}
***
Define :hover:before hovering state of each [data-tooltip] to make it visible:
***
[data-tooltip]:hover:before {
opacity : 1;
}
***
Apply your styles (color, size, position etc) to the tooltip object; end of the story.
In the demo I've defined another rule to specify if the tooltip must disappear when hovering over it but outside of the parent, with another custom attribute, data-tooltip-persistent, and a simple rule:
***
[data-tooltip]:not([data-tooltip-persistent]):before {
pointer-events: none;
}
***