Highlight Text on Scroll with JavaScript – 5-Min Setup

Copy a free JavaScript snippet into WPCode, activate it, and instantly highlight text on scroll. Lightweight, mobile-friendly, customizable—live in 5 minutes.

Spread the love
Bikers rights gif via giphy
"bikers rights" portlandia gif via giphy

TL;DR:

  • A free JavaScript snippet creates dynamic text highlighting as visitors scroll, making content feel alive instead of static.
  • You install it using WPCode (WP Code Lite) with 2M+ active installsno theme file editing required.
  • The script uses the IntersectionObserver API for smooth, efficient performance that won't slow your site.
  • You must activate the snippet after saving in WPCode or absolutely nothing will happen.
{“content”:”

Most blog content just sits there. 👋 Static words on a static page and your readers are already halfway to the back button before they even finish your first paragraph. I built a little JavaScript snippet that highlights on scroll and honestly it made a noticeable difference in how people interact with my pages. If you've been looking for ways to make your content more engaging, this one's a winner. 😊

The best part? "Now this is super plug and play. You don't have to do anything at all really. Just copy my code." That's it. No coding degree, no hiring a developer, no sitting through a 45-minute tutorial where the guy spends 20 minutes talking about his setup. Five minutes, tops. ⚡

https://www.youtube.com/watch?v=F7LgCR7Kp2g

TL;DR

Why Your Blog Content Feels Dead (And What This Fixes)

Here's the problem nobody talks about: you spend hours writing a 2,000-word blog post, optimize it for SEO, add images, and then someone lands on it and… nothing happens. There's no movement, no visual feedback—nothing telling the reader's brain to keep going.

Code snippet
Engage readers with this code!

That's what this on-scroll text effect solves. As visitors scroll, bolded text gets highlighted with a smooth pen-like animation that starts fast, slows down in the middle, then speeds up again—just like a real highlighter. Honestly kind of satisfying to watch.

It works on a psychological level: when something moves, your brain notices. It's not obnoxious like a pop-up; it's subtle—a gentle nudge to keep scrolling. These micro-interactions are often overlooked while people chase bigger, flashier things.

\"Info

Fun Fact

The effect uses the IntersectionObserver API to detect visibility efficiently—far more performant than old scroll handlers, so it won't drag your site speed.

What the Dynamic Text Highlighting Actually Looks Like

As a paragraph comes into view, its bolded words and phrases get a colored sweep with pen-like easing that feels natural and precise.

One smart detail: the highlighting skips bullet points and lists on purpose. If everything animates, it stops being engaging and starts being annoying—subtlety keeps it classy.

The effect only triggers on <strong> or <b> tags inside <p> tags. That means you're already controlling the targets as you write—no extra markup required.

The bold text you already use becomes the animated highlight—zero extra steps.

How to Add Custom JavaScript to WordPress (The 5-Minute Setup)

Step 1: Get the Code

Go to Yerain Abreu's tutorial and copy the full snippet—no edits or keys needed. "I'm sharing the link; just copy and paste it to your website."

No modifications, no setup—just copy it and you're done.

Step 2: Install the WPCode Plugin

In WordPress, go to Plugins → Add New → WPCode and install "WPCode – Insert Headers and Footers + Custom Code Snippets" (blue icon), then activate it.

It has over 2 million active installs and a strong rating—the standard way to add JS safely without touching theme files.

Step 3: Create Your Snippet

Go to Code Snippets → Add New → Add Your Custom Code (New Snippet).

Very important: choose JavaScript Snippet as the type (not HTML or PHP) or the code won't run—this trips people up.

Paste your code into the editor and save the snippet.

Step 4: Activate It (Don't Skip This)

After saving, find the toggle and activate the snippet. Then save again and check your site.

\"Error

Critical Warning

Saving the snippet is NOT enough. WPCode defaults new snippets to Inactive—you must explicitly activate or the highlight effect will never appear.

Quick Setup Summary

  1. Copy the code from yerainabreu.com
  2. Install WPCode from the WordPress directory
  3. Create a new snippet and choose "JavaScript Snippet"
  4. Paste and activate (don't just save)

Customizing the Exclude List (So It Doesn't Highlight Everything)

The code includes an exclude list where you can add words or phrases that should not be highlighted.

Example: maybe your "Key Takeaways" line is a bolded paragraph that looks odd when animated—exclude that phrase to keep it static.

Edit the array directly in the snippet to add or remove terms; if you don't need exclusions, delete the section and you're done.

When to Add Exclusions vs. When to Skip

When to Add Exclusions

  • Bolded section headers inside paragraphs that look odd animated
  • Repeated phrases like "Key Takeaway" or "Bottom Line"
  • Brand names or proper nouns you don't want animated

When to Skip Exclusions

  • You use bold for emphasis within sentences
  • Your content doesn't repeat structural phrases
  • You want maximum highlighting coverage

Will This Slow Down My Site?

Short answer: no. The snippet is tiny and relies on the browser's native IntersectionObserver—lightweight by design.

Your bigger risks are unoptimized images, too many plugins, or weak hosting. As r/webdev discussions note, small, purpose-built scripts have negligible impact.

Why WPCode Instead of Editing Theme Files Directly

Yes, you can paste code into header.php or functions.php—but you absolutely shouldn't.

One typo in PHP can crash your site; WPCode can auto-deactivate bad snippets so your site stays up. Plus, code in theme files gets wiped by updates.

This is standard WordPress best practiceuse a snippets plugin for safety and persistence.

\"Success

Safety Net

WPCode provides a safer workflow: isolate snippets, prevent fatals, and keep customizations through theme updates.

Does This Actually Increase Reader Engagement?

No perfect A/B test here, but the principle stands: subtle, purposeful animation helps guide the eye and keep readers engaged.

Signals like dwell time and scroll depth may matter; anything that nudges readers forward is a win. This highlight effect sits firmly in the "useful, not flashy" category.

FAQ

Do you ever find yourself scrolling through content, wishing there was a way to keep your attention longer, or is it just me? 📚
Do you ever find yourself scrolling through content, wishing there was a way to keep your attention longer, or is it just me? 📚

Frequently Asked Questions

Yes—modern mobile browsers support IntersectionObserver, so the highlight triggers on scroll the same way as desktop.

Yes. Change the CSS color (hex or RGB) in the snippet to match your brand; it's a 30-second edit.

Unlikely. It targets standard bold tags inside paragraphs; conflicts are rare and easily reversed by deactivating the snippet.

Use prefers-reduced-motion to disable animations for users who request it; see Google's guide.

Yes. Paste it anywhere your platform allows custom JS—it's not WordPress-specific.

Final Thoughts

You could over-engineer engagement—or copy one snippet into WPCode and have dynamic highlighting running before your coffee gets cold. Don't forget to activate the snippet, then watch your bold text come alive. 🤙

“}

Leave a Comment

Frequently asked questions (FAQ)

LiaisonLabs is your local partner for SEO & digital marketing services in Mount Vernon, Washington. Here are some answers to the most frequently asked questions about our SEO services.

SEO (Search Engine Optimization) is the process of improving your website's visibility in search engines like Google. When potential customers in Mount Vernon or Skagit County search for your products or services, SEO helps your business appear at the top of search results. This drives more qualified traffic to your website—people who are actively looking for what you offer. For local businesses, effective SEO means more phone calls, more foot traffic, and more revenue without paying for every click like traditional advertising.

A local SEO partner understands the unique market dynamics of Skagit Valley and the Pacific Northwest. We know the seasonal patterns that affect local businesses, from tulip festival tourism to agricultural cycles. Local expertise means we understand which keywords your neighbors are searching, which directories matter for your industry, and how to position your business against local competitors. Plus, we're available for in-person meetings and truly invested in the success of our Mount Vernon business community.

SEO is a long-term investment, and most businesses begin seeing meaningful results within 3 to 6 months. Some quick wins—like optimizing your Google Business Profile or fixing technical issues—can show improvements within weeks. However, building sustainable rankings that drive consistent traffic takes time. The good news? Unlike paid advertising that stops the moment you stop paying, SEO results compound over time. The work we do today continues delivering value for months and years to come.

SEO pricing varies based on your goals, competition, and current website health. Local SEO packages for small businesses typically range from $500 to $2,500 per month, while more comprehensive campaigns for competitive industries may require a larger investment. We offer customized proposals based on a thorough audit of your website and competitive landscape. During your free consultation, we'll discuss your budget and create a strategy that delivers measurable ROI—because effective SEO should pay for itself through increased revenue.

Both aim to improve search visibility, but the focus differs significantly. Local SEO targets customers in a specific geographic area—like Mount Vernon, Burlington, Anacortes, or greater Skagit County. It emphasizes Google Business Profile optimization, local citations, reviews, and location-based keywords. Traditional SEO focuses on broader, often national rankings and prioritizes content marketing, backlink building, and technical optimization. Most Mount Vernon businesses benefit from a local-first strategy, though many of our clients combine both approaches to capture customers at every stage of their search journey.

Absolutely! SEO and paid advertising work best as complementary strategies. Google Ads deliver immediate visibility and are great for testing keywords and driving quick traffic. SEO builds sustainable, long-term visibility that doesn't require ongoing ad spend. Together, they create a powerful combination—ads capture immediate demand while SEO builds your organic presence over time. Many of our Mount Vernon clients find that strong SEO actually improves their ad performance by increasing Quality Scores and reducing cost-per-click, ultimately lowering their total marketing costs while increasing results.