DEV Community

Oleksandr Demian
Oleksandr Demian

Posted on

4

React tooltip

import React from "react";
import styled from "styled-components";

const TooltipContainer = styled.span`
    position: relative;

    &:hover > .tip {
        display: block;
    }

    & > .tip {
        display: none;
        position: absolute;

        background: #1F2531;
        opacity: 0.9;
        border-radius: 5px;

        color: #FFFFFF;
        padding: 12px 8px;
        width: 100%;
        min-width: 100px;
    }

    & > .tip::after {
        content: "";
        position: absolute;
        opacity: 0.9;
        top: -10px;
        left: 50%;
        margin-left: -5px;
        border-width: 5px;
        border-style: solid;
        border-color:  transparent transparent black transparent;
    }
`;

const Tooltip = ({children, tip}) => {
    return <TooltipContainer>
        {children}
        <span className="tip">{tip}</span>
    </TooltipContainer>
};

export default Tooltip;
Enter fullscreen mode Exit fullscreen mode

Usage:

<Tooltip tip="I'm a tooltip">
    <p>Example paragraph</p>
</Tooltip>
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Checkly

Incident Management 101: What Devs Need to Know in 2025

  • Detect issues before your users do
  • Use synthetic checks for proactive coverage
  • Automate root cause workflows
  • Communicate incidents clearly to your team
  • Learn how to triage, escalate, and resolve faster

Watch session

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay