CSS Definition Tooltip
Explains a term inside a sentence: a dotted-underlined word that reveals a short definition on hover or focus.
The layout uses subgridA grid item that lines up its children with the parent grid's tracks. so the card titles align.
<p class="define-text">
The layout uses
<span class="define" tabindex="0" aria-describedby="define-subgrid">subgrid</span><span class="define-tip" role="tooltip" id="define-subgrid">A grid item that lines up its children with the parent grid's tracks.</span>
so the card titles align.
</p>
.define-text {
position: relative;
max-width: 260px;
margin: 0;
color: #451a03;
font: 17px/1.6 Georgia, "Times New Roman", serif;
}
.define {
text-decoration: underline dotted #b45309 2px;
text-underline-offset: 4px;
cursor: help;
}
.define:focus-visible {
outline: 2px solid #b45309;
outline-offset: 2px;
border-radius: 2px;
}
.define-tip {
position: absolute;
top: calc(100% + 8px);
left: 0;
z-index: 10;
width: 100%;
padding: 10px 12px;
box-sizing: border-box;
border-left: 3px solid #f59e0b;
border-radius: 4px 10px 10px 4px;
background: #fff;
box-shadow: 0 10px 24px -10px rgba(120, 53, 15, 0.35);
color: #78350f;
font: 14px/1.45 system-ui, sans-serif;
opacity: 0;
visibility: hidden;
transition: opacity 0.15s ease, visibility 0.15s;
}
.define:hover + .define-tip,
.define:focus + .define-tip {
opacity: 1;
visibility: visible;
}
@media (prefers-reduced-motion: reduce) {
.define-tip {
transition: none;
}
}
About this CSS Definition Tooltip
This CSS Definition Tooltip is 50 lines of pure CSS (1.0 KB) with no JavaScript and no dependencies. It uses transitions, box shadows, keyboard focus styles and reduced-motion support. It works in current versions of Chrome, Edge, Safari and Firefox. It works in any stack: plain HTML, React, Vue, Svelte, Astro, WordPress or Webflow.
CSS features used
Customize it
The colors in this snippet. Search and replace them to match your brand:
#451a03#b45309#f59e0b#fff#78350f
How to use this definition tooltip
- Copy the HTML and paste it where you want the element to appear.
- Copy the CSS into your stylesheet, or inside a
<style>tag. - Keep the
.define-textclass name, or rename it in both places. Then tweak colors, sizes and timing to match your design. - Using React or Next.js? Change
classtoclassNamein the HTML. The CSS works as is, including in Tailwind projects (put it in your global stylesheet).
Building with an AI tool?
“Copy for AI” copies a short prompt for Cursor, Claude Code, Lovable, Bolt or v0. Your AI tool opens the Markdown version of this snippet and reads the HTML, CSS and setup notes there. If your tool can't open links, with the code instead. More ways to use copy CSS with AI.