Scroll Highlight Text
Installation
Copy the element to Webflow
Add custom JavaScript
(() => {
const components = document.querySelectorAll('.p002-scroll-highlight');
if (!components.length) return;
// Respect reduced motion preferences.
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
// Show or hide highlights based on scroll position.
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
entry.target.classList.toggle('is-visible', entry.isIntersecting);
});
},
{
rootMargin: '0px 0px -35% 0px',
threshold: 0,
},
);
components.forEach((component) => {
// Stagger multiple highlights.
component.querySelectorAll('.p002-scroll-highlight_mark').forEach((mark, index) => {
mark.style.setProperty('--p002-delay', `${200 + index * 180}ms`);
});
observer.observe(component);
});
})();Add HTML structure
<div class="p002-scroll-highlight">
<p class="p002-scroll-highlight_text">
We build websites that feel
<span class="p002-scroll-highlight_mark">alive</span>
and turn simple layouts into
<span class="p002-scroll-highlight_mark">memorable</span>
experiences.
</p>
</div>Add custom CSS
.p002-scroll-highlight_mark {
background-image: linear-gradient(rgba(70, 110, 255, 0.28), rgba(70, 110, 255, 0.28));
background-repeat: no-repeat;
background-position: left bottom;
background-size: 0% 100%;
transition: background-size 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}
.p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {
background-size: 100% 100%;
transition-delay: var(--p002-delay, 200ms);
}
@media (prefers-reduced-motion: reduce) {
.p002-scroll-highlight .p002-scroll-highlight_mark,
.p002-scroll-highlight.is-visible .p002-scroll-highlight_mark {
background-size: 100% 100%;
transition: none;
}
}Add custom JavaScript
(() => {
const components = document.querySelectorAll('.p002-scroll-highlight');
if (!components.length) return;
// Respect reduced motion preferences.
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
// Show or hide highlights based on scroll position.
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
entry.target.classList.toggle('is-visible', entry.isIntersecting);
});
},
{
rootMargin: '0px 0px -35% 0px',
threshold: 0,
},
);
components.forEach((component) => {
// Stagger multiple highlights.
component.querySelectorAll('.p002-scroll-highlight_mark').forEach((mark, index) => {
mark.style.setProperty('--p002-delay', `${200 + index * 180}ms`);
});
observer.observe(component);
});
})();Documentation
How to use in Webflow
Copy the component into your Webflow project. Keep the CSS embed "p002-css" inside the component. Inside this embed there is all the necessary CSS code for the animation.
Publish your page to test the menu and replace the placeholder links with your own destinations.
How it works
Selected words and phrases are highlighted as the text scrolls into view. The effect resets when scrolling away and plays again when the text re-enters the viewport.
How to customize
Edit the text and choose which words or phrases you want to highlight.
Webflow: Double-click the text element, select the words you want to highlight, and choose "Wrap in Span". Apply the class "p002-scroll-highlight_mark" to the Span.
Code: Wrap the words in a <span> with the class "p002-scroll-highlight_mark".