data-tooltip
attribute with your desired hover text to any element.To add hover text (tooltips) across your Webflow site using reusable code, you'll need to use a combination of custom attributes, Webflow elements, and a single custom code block.
data-tooltip
This keeps your HTML clean and allows for reusability.
tooltip-container
.tooltip-text
.position: absolute
, hidden by default (e.g., display: none
, opacity: 0
), with a background, padding, and small shadow.tag).
<script>document.addEventListener("DOMContentLoaded", function () { const tooltip = document.createElement('div'); tooltip.className = 'tooltip-text'; tooltip.style.position = 'absolute'; tooltip.style.pointerEvents = 'none'; tooltip.style.display = 'none'; tooltip.style.padding = '6px 8px'; tooltip.style.background = 'rgba(0,0,0,0.75)'; tooltip.style.color = '#fff'; tooltip.style.fontSize = '12px'; tooltip.style.borderRadius = '4px'; tooltip.style.transition = 'opacity 0.2s ease'; tooltip.style.zIndex = '9999'; document.body.appendChild(tooltip); document.querySelectorAll('[data-tooltip]').forEach(el => { el.addEventListener('mouseenter', e => { tooltip.textContent = el.getAttribute('data-tooltip'); tooltip.style.display = 'block'; tooltip.style.opacity = '1'; }); el.addEventListener('mousemove', e => { tooltip.style.top = (e.clientY + 12) + 'px'; tooltip.style.left = (e.clientX + 12) + 'px'; }); el.addEventListener('mouseleave', e => { tooltip.style.display = 'none'; tooltip.style.opacity = '0'; }); });});</script>
This script checks all elements with data-tooltip
, and displays a small tooltip wherever the cursor hovers.
data-tooltip
attribute to any new element with your desired tooltip text.Use the data-tooltip
custom attribute for each target element, then add a single JavaScript snippet to create reusable hover text functionality across your Webflow site. This approach is clean, scalable, and works on any element.