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.
| Browser | Supported from |
|---|---|
| Chrome | 81 |
| Edge | 83 |
| Safari | 16.1 |
| Firefox | 131 |
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
| Fragment | Highlights |
|---|---|
| #:~:text=opening%20hours | The first match of "opening hours" |
| #:~:text=Delivery%20takes,business%20days | From "Delivery takes" through "business days" |
| #:~:text=Saturday-,closed | "closed" only where it follows "Saturday" |
| #:~:text=price&text=deposit | The 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
- Copy the page address you want to link to.
- Copy the exact words to highlight from that page, keeping each part within a single paragraph or heading.
- For a long passage, give only the first few words as the start and the last few as the end.
- Add a prefix or suffix only if the same words appear more than once on the page.
Tips
- Matching ignores capital letters, so the case of your words does not matter.
- If nothing matches, MDN says the fragment is ignored and the page opens at the top, so a broken link fails gently.
- Edit the page later and the link may stop highlighting. Pick wording that is unlikely to change.
- To highlight two separate passages, join them with an ampersand: #:~:text=first&text=second.
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, WhatsApp link generator.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- Local Citations: Get Your Name, Address and Phone Right Everywhere
- Local Citations for Australian Businesses: Where to Be Listed | How-to Guide
- Local Citations for Canadian Businesses: A Practical List | How-to Guide
- Local Citations for UK Businesses: The Listings That Matter | How-to Guide
- Local Citations for US Businesses: Where to List and Why | How-to Guide
- Competitor Gap Analysis for a Local Business | How-to Guide
- localhost:11434: Talking to the Ollama Server
- mongodb://localhost:27017: Connecting to Local MongoDB
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App