Arrow to the left of the tooltip with CSS

Creating an arrow pointing to the left of a tooltip helps users understand that the tooltip relates to the element they're hovering over. This arrow is created using CSS pseudo-elements and border properties to form a triangular shape.

Syntax

.tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    border-width: size;
    border-style: solid;
    border-color: transparent color transparent transparent;
}

Example

The following example creates a tooltip with an arrow pointing to the left −

<!DOCTYPE html>
<html>
<head>
<style>
    .mytooltip {
        position: relative;
        display: inline-block;
        margin-left: 50px;
        background-color: #007bff;
        color: white;
        padding: 10px 15px;
        border-radius: 4px;
        cursor: pointer;
    }
    
    .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: -5px;
        left: 110%;
    }
    
    .mytooltip .mytext::after {
        content: "";
        position: absolute;
        top: 50%;
        right: 100%;
        margin-top: -5px;
        border-width: 5px;
        border-style: solid;
        border-color: transparent #333 transparent transparent;
    }
    
    .mytooltip:hover .mytext {
        visibility: visible;
    }
</style>
</head>
<body>
    <div class="mytooltip">Hover over me
        <span class="mytext">This is my tooltip!</span>
    </div>
</body>
</html>
A blue button appears with "Hover over me" text. When you hover over it, a dark tooltip with white text "This is my tooltip!" appears to the right with a left-pointing arrow connecting it to the button.

Key Points

  • The arrow is created using the ::after pseudo-element with CSS borders
  • border-color: transparent #333 transparent transparent creates a left-pointing triangle
  • right: 100% positions the arrow at the left edge of the tooltip
  • top: 50%; margin-top: -5px centers the arrow vertically

Conclusion

Creating a left-pointing arrow for tooltips enhances user experience by clearly indicating the relationship between the tooltip and its trigger element. The technique uses CSS borders and pseudo-elements to create clean, scalable arrows.

Updated on: 2026-03-15T12:49:08+05:30

868 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements