Trying out Tooltips!
Tags: tooltips, codenewbie, html
Published: 2021-05-03 00:34:47

Hello! I am back here with another blog in relation to my coding adventure!

I recently saw a post in regards to tooltips! The post was mainly CSS and I realized that I have never really got a chance to utilize tooltips before! As I read some articles and resources about it, it piqued my interest to try and play around to see how tooltips work!

There are a lot of ways to display tooltips! But first what is a tooltip?

According to [Techopedia](https://www.techopedia.com/definition/5482/tooltip), tooltip is a graphical user interface (GUI) element used in conjunction with the cursor or mouse pointer to display information about an item without needing to click on it. The typical scenario for summoning a tooltip is to hover the mouse cursor over another GUI element such as a tool icon in a software application, and it is also prevalently used in websites.

A tooltip is also known as a hint, infotip or screentip.
I see it a lot without realizing those are tooltips! A good example is this on Github:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oculmnylik1ne3oamtun.png)

##Uses
1. Provides more information for your user.
   * This can either be a subtitle tooltip for a page full of images or display a preview of a link before having the user click on it.
2. Makes your website more reader-friendly.
   * Less text might be better for UI. Tucking away tips or text they don't necessarily need to see ASAP, will look cleaner or streamlined.
3. Lessens confusion on users.
   * Tooltips can give guidance to users on parts of the page that might be confusing. A good example is tips on using uncommon buttons or showing the meaning of uncommon icons. Might be even a big part of giving your website more accessibility features.
4. Call-to-Action.
   * Tooltips can provide a quicker way to integrate micro-interactions into the flow of your UI. 

Check out some of these articles for more references about tooltips!

**[Tooltip snippets](https://speckyboy.com/free-css-tooltip-snippets/)** - If you wanted to save time and just needed a quick HTML/CSS snippet of tooltips, definitely check this one out.

**[Creating tooltips](
https://www.bitdegree.org/learn/css-tooltip#creating-tooltips-with-css)** - If you're looking into a step-by-step method on creating a tooltip and style it, this one might be a good one to bookmark.

##Ways to create tooltips
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m00yujxqaro6j3kjs8c1.png)
* [Bootstrap- Tooltips](https://react-bootstrap.github.io/components/overlays/#tooltips), [Material UI-Tooltip](https://material-ui.com/components/tooltips/), [Semantic UI- Popup](https://react.semantic-ui.com/modules/popup/) - Out of all I have tried, these might be the easiest one for me. Since everything is all set up just need to import components on your code, styling might just be a little limited.


* HTML/CSS - Toggling it's visibility. This was so tricky to me somehow. T_T Positioning the tooltip once triggered was tricky when <span> was used unlike using a <div>. But my code ended up looking like this;

```html
<div class="tooltip-ex">
  <span style="color: black !important;" id="hoverme">Hover here!</span>
  <div class="tooltip-ex-text">
   <span style="color: black;">I am a tooltip</span>
  </div>
</div>
```
CSS: 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzmb6lii6l3wc87ae6dz.png)

* Click here to run the code - [BitDegree](https://www.bitdegree.org/learn/best-code-editor/IooHTxuV/1)

* HTML - data-text/ data-tooltip - I didn't know that there was a built-in class you can apply through HTML! Syntax would be like this:

```html
    <button  
      class="tooltip" 
      data-tooltip="I am using data-tooltip and CSS">
      Data Text
    </button>
```

Neat right? You can put any message on the data-tooltip attribute and control how it looks on CSS. Didn't want to do a CSS code dump again so if you want to check it out, here's my [CodePen](https://codepen.io/tolentinoel/pen/LYxwxdZ).

The unique thing I noticed with using this method is on CSS, there is a declaration that is called `content` with a value of `attr(data-tooltip)`. It also utilizes the `::before` and `::after` pseudoelements on CSS.

The result would look like this;
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dkj1ev1533iq0gqze9xt.png)

Here's my CodePen with all of the mentioned above;
{% codepen https://codepen.io/tolentino/pen/LYxwxdZ %}

And that is it! So far that is all I've discovered about tooltips! Maybe it's something you want to incorporate with your website if you haven't since there is probably more use of it we never got to try.

####Let me know in the comments below if you've used tooltips in a different way than the ones above!