Layout · 19 of 23

Tooltip

Scale/fade hint

HTML · CSS · No dependencies · MIT

HTML

<button class="tooltip-trigger" data-tooltip="Detailed Information">Hover Me</button>

CSS

.tooltip-trigger {
  position: relative;
  padding: 0.6rem 1.2rem;
  background: #7c5cff;
  color: white;
  border: none;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}

/* The tooltip is a ::after pseudo-element reading its text
   from the data-tooltip attribute — no extra markup needed */
.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 120%;
  left: 50%;
  transform: translateX(-50%) scale(0.8);
  background: #222;
  color: #f0f0f5;
  padding: 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  border: 1px solid #444;
}

.tooltip-trigger:hover::after {
  opacity: 1;
  transform: translateX(-50%) scale(1);
}