Languages
[Edit]
EN

HTML - display tooltip text for link element on mouse hover

0 points
Created by:
Wiktor-Sribiew
860

In this article, we would like to show you how to

Practical example

To create a tooltip for link (a element) we take the following steps:

  1. create a new style for tooltip class inside a element (using . selector),
  2. set the tooltip to be invisible at the start using visibility: hidden,
  3. for the container (in our case a element) use the :hover pseudo-class with visibility: visible property inside to show up the tooltip text when you hover it.
// ONLINE-RUNNER:browser;

<!DOCTYPE html>
<html>
<style>
  
  a {
      position: relative;
      display: inline-block;
  }

  a .tooltip {
      visibility: hidden;
      width: 120px;
      background: gray;
      color: white;
      text-align: center;
      border-radius: 3px;
      padding: 5px 0;

      /* tooltip positioning */
      position: absolute;
      z-index: 1;
      margin-left: 5px;
  }

  a:hover .tooltip {
      visibility: visible;
  }

</style>
<body>
  <a href="https://www.dirask.com/">Hover over me to see the tooltip
    <span class="tooltip">Tooltip text...</span>
  </a>
</body>
</html>

 

References

  1. position - CSS: Cascading Style Sheets | MDN
  2. :hover - CSS: Cascading Style Sheets | MDN
  3. Pseudo-classes - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. HTML - display hint text for link element on mouse hover
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join