Link to a Sentence: Text Fragment URLs

A text fragment is an addition to a web address, #:~:text= followed by words from the page, that makes the browser scroll to those words and highlight them. Chrome's Copy link to highlight menu item writes one for you, and you can build them by hand with optional start, end, prefix and suffix parts.

First browser versions that support text fragments (caniuse, October 2026)
BrowserSupported from
Chrome81
Edge83
Safari16.1
Firefox131

Updated

Sending a customer to the exact line of your returns policy, or pointing a client at one paragraph of a long proposal, beats saying "scroll down a bit". Text fragment links do that with nothing more than a longer URL; the page owner does not have to add anchors. Paste a page address and a passage into the builder to make one.

Text fragment link builder

Your link: https://example.com/returns#:~:text=Refunds%20are%20issued%20within

Examples of each form

Text fragment forms and what they highlight
FragmentHighlights
#:~:text=opening%20hoursThe first match of "opening hours"
#:~:text=Delivery%20takes,business%20daysFrom "Delivery takes" through "business days"
#:~:text=Saturday-,closed"closed" only where it follows "Saturday"
#:~:text=price&text=depositThe first "price" and the first "deposit"

Style the highlight on your own site

Browsers pick a default highlight colour. The ::target-text pseudo-element lets you match it to your brand.

Custom ::target-text colours

Keep strong contrast between the text and the highlight colour.

::target-text {
  background-color: #ffe08a;
  color: #1f1f1f;
}

Feature detection

document.fragmentDirective is an object in supporting browsers and undefined elsewhere.

if ("fragmentDirective" in document) {
  console.log("This browser supports text fragments");
}

The parts of the syntax

The full form is #:~:text=[prefix-,]textStart[,textEnd][,-suffix]. Only textStart is required. With textEnd added, the browser highlights everything from the start words to the end words.

The prefix ends with a dash and the suffix begins with one. They are not highlighted; they only tell the browser which copy of a repeated phrase you mean.

Encoding rules

Every part must be percent-encoded, which turns spaces into %20. MDN adds that the dash itself must be encoded as %2D, because a bare dash would be read as a prefix or suffix marker.

Commas and ampersands separate parts and fragments, so encoding them too, as %2C and %26, keeps them from being misread. The builder on this page does all of this for you.

How it works

  1. Copy the page address you want to link to.
  2. Copy the exact words to highlight from that page, keeping each part within a single paragraph or heading.
  3. For a long passage, give only the first few words as the start and the last few as the end.
  4. Add a prefix or suffix only if the same words appear more than once on the page.

Tips

Frequently asked questions

How do I copy a link to highlighted text in Chrome?

Select the text on the page, right-click it and choose Copy link to highlight. Chrome Help notes that if you cannot select this option, the feature may not work for that content.

Do text fragment links work in Firefox and Safari?

Yes, in current versions. caniuse lists support from Safari 16.1 and Firefox 131, along with Chrome 81 and Edge 83. Older browsers simply open the page at the top.

Why does my text fragment link not highlight anything?

The words may not appear exactly as written, one part may span two paragraphs, or a dash in the text was not percent-encoded. Text inside an iframe is never searched, according to MDN.

Can my own scripts read the text fragment?

No. MDN explains that browsers strip the :~: directive from the URL during loading, so page scripts cannot read it. You can detect support with document.fragmentDirective.

Can I stop other people linking to text on my site this way?

Chromium-based browsers honour a Document-Policy: force-load-at-top response header that opts a page out of text fragment scrolling, according to MDN.

Related: HTML links guide, URL encoder and decoder, HTML mailto links, WhatsApp link generator.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap