WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS Tooltip


Create tooltips with CSS.


Demo: Tooltip Examples

A tooltip is regularly used to determine additional data about something when the client moves the mouse pointer over an element:

Top Tooltip text
Right Tooltip text
Bottom Tooltip text
Left Tooltip text


Basic Tooltip

Create a tooltip that shows up when the client moves the mouse over an element:

Example

<style>
/* Tooltip compartment */
.tooltip {
    position: relative;
    show: inline-block;
    outskirt base: 1px dabbed dark;/* If you need spots under the hoverable content */
}

/* Tooltip content */
.tooltip .tooltiptext {
    perceivability: hidden;
    width: 130px;
    foundation shading: black;
    shading: #f4ece3;
    content adjust: center;
    cushioning: 5px 0;
    outskirt range: 6px;
 
    /* Position the tooltip content - see models underneath! */
    position: absolute;
    z-record: 1;
}

/* Show the tooltip content when you mouse over the tooltip holder */
.tooltip:hover .tooltiptext {
    perceivability: visible;
}
</style>

<div class="tooltip">Hover over me
  <span class="tooltiptext">Tooltip text</span>
</div>
Try it Yourself »

Positioning Tooltips

In this model, the tooltip is put to one side (left:105%) of the "hoverable" content (<div>). Likewise note that top:- 5px is utilized to put it amidst its holder component. We utilize the number 5 in light of the fact that the tooltip content has a best and base cushioning of 5px. On the off chance that you increment its cushioning, additionally increment the estimation of the top property to guarantee that it remains in the center (if this is something you need). The equivalent applies on the off chance that you need the tooltip set to the left.

Right Tooltip

.tooltip .tooltiptext {
    top: - 5px;
    left: 105%;
}

Result:

Hover over me Tooltip text
Try it Yourself »

Left Tooltip

.tooltip .tooltiptext {
    top: - 5px;
    right: 105%;
}

Result:

Hover over me Tooltip text
Try it Yourself »

If you need the tooltip to show up to finish everything or on the base, see models underneath. Note that we utilize the margin-left property with an estimation of short 60 pixels. This is to focus the tooltip above/underneath the hoverable content. It is set to the half of the tooltip's width (120/2 = 60).

Top Tooltip

.tooltip .tooltiptext {
    width: 120px;
    base: 100%;
    left: half;
    edge left: - 60px;/* Use half of the width (120/2 = 60), to focus the tooltip */
}

Result:

Hover over me Tooltip text
Try it Yourself »

Bottom Tooltip

.tooltip .tooltiptext {
    width: 120px;
    top: 100%;
    left: half;
    edge left: - 60px;/* Use half of the width (120/2 = 60), to focus the tooltip */
}

Result:

Hover over me Tooltip text
Try it Yourself »

Tooltip Arrows

To make a bolt that ought to show up from a particular side of the tooltip, include "void" content after tooltip, with the pseudo-component class ::after together with the content property. The bolt itself is made utilizing fringes. This will make the tooltip resemble a discourse bubble.

This model shows how to add a bolt to the base of the tooltip:

Bottom Arrow

.tooltip .tooltiptext::after {
    content: " ";
    position: absolute;
    top: 100%; /* At the base of the tooltip */
    left: 50%;
    edge left: - 5px;
    fringe width: 5px;
    outskirt style: solid;
    fringe shading: dark straightforward transparent;
}

Result:

Hover over me Tooltip text
Try it Yourself »

Top Arrow

.tooltip .tooltiptext::after {
    content: " ";
    position: absolute;
    base: 100%; /* At the highest point of the tooltip */
    left: 50%;
    edge left: - 5px;
    fringe width: 5px;
    outskirt style: solid;
    fringe shading: straightforward dark transparent;
}

Result:

Hover over me Tooltip text
Try it Yourself »

This model shows how to add a bolt to one side of the tooltip:

Left Arrow

.tooltip .tooltiptext::after {
    content: " ";
    position: absolute;
    top: 50%;
    right: 100%;/* to one side of the tooltip */
    edge top: - 5px;
    outskirt width: 5px;
    fringe style: solid;
    outskirt shading: straightforward dark straightforward transparent;
}

Result:

Hover over me Tooltip text
Try it Yourself »

This precedent shows how to add a bolt to the directly of the tooltip:

Right Arrow

.tooltip .tooltiptext::after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 100%;/* To the directly of the tooltip */
    edge top: - 5px;
    outskirt width: 5px;
    fringe style: solid;
    outskirt shading: straightforward black;
}

Result:

Hover over me Tooltip text
Try it Yourself »

Fade In Tooltips (Animation)

If you need to blur in the tooltip content when it is going to be noticeable, you can utilize the CSS3 transition property together with the opacity property, and go from being totally imperceptible to 100% unmistakable, in various determined seconds (1 second in our example):

Example

.tooltip .tooltiptext {
    haziness: 0;
    progress: mistiness 1s;
}

.tooltip:hover .tooltiptext {
    haziness: 1;
}
Try it Yourself »