Set right tooltip with CSS

To create a right tooltip in CSS, you position the tooltip to appear on the right side of an element. The key is using the left property with a value of 100% to push the tooltip completely to the right of its parent element.

Syntax

.tooltip .tooltiptext {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
}

Example

The following example creates a tooltip that appears on the right side when you hover over the text −

<!DOCTYPE html>
<html>
<head>
<style>
    .mytooltip {
        position: relative;
        display: inline-block;
        cursor: pointer;
        background-color: #f0f0f0;
        padding: 10px;
        border-radius: 5px;
    }
    
    .mytooltip .mytext {
        visibility: hidden;
        width: 140px;
        background-color: #333;
        color: #fff;
        text-align: center;
        border-radius: 6px;
        padding: 8px;
        position: absolute;
        z-index: 1;
        top: 50%;
        left: 100%;
        margin-left: 10px;
        transform: translateY(-50%);
        opacity: 0;
        transition: opacity 0.3s;
    }
    
    .mytooltip:hover .mytext {
        visibility: visible;
        opacity: 1;
    }
    
    /* Arrow pointing left */
    .mytooltip .mytext::before {
        content: "";
        position: absolute;
        top: 50%;
        right: 100%;
        margin-top: -5px;
        border: 5px solid transparent;
        border-right-color: #333;
    }
</style>
</head>
<body>
    <div class="mytooltip">Hover over me
        <span class="mytext">Right side tooltip!</span>
    </div>
</body>
</html>
A gray box with "Hover over me" text appears. When you hover over it, a dark tooltip with "Right side tooltip!" appears on the right side with a smooth fade-in animation and a small arrow pointing back to the element.

Key Properties

  • left: 100% − Positions the tooltip to the right of the parent element
  • margin-left − Adds spacing between the element and tooltip
  • transform: translateY(-50%) − Centers the tooltip vertically
  • position: absolute − Removes the tooltip from document flow

Conclusion

Right tooltips are created by setting left: 100% on the absolutely positioned tooltip element. Adding margins and transforms helps with proper spacing and alignment for a professional appearance.

Updated on: 2026-03-15T12:47:37+05:30

134 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements