Skip to content

Tools

Text Fragment Links Explained

Text fragments are the web standard that lets a link highlight words on a page the link author does not control. This is the reference: how the browser matches, the full syntax, what is and is not sent to the server, and why some links fail.

For twenty years the only way to link into the middle of a page was an anchor the author had placed there, an id attribute you could hang a #section on. Text fragments, specified by the Web Incubator Community Group and shipped in Chrome 80 in early 2020, let the reader choose the target instead. The link carries a few words; the browser searches the page for them, scrolls there and highlights the match. Safari adopted it in 16.1 (2022) and Firefox in 131 (2024), which makes it the first universal, server-free way to share a highlight.

A printed page with a pencil drawing an arrow straight to one highlighted line

In short

Scroll to text fragment is the web standard behind links that end in #:~:text=. The link carries a few words; the browser finds them on the page, scrolls there and highlights them. Chrome, Edge, Safari and Firefox all support it, the fragment is never sent to the website, and any failure falls back to opening the page normally.

The syntax

A text directive lives in the fragment part of a URL (after #), introduced by the delimiter :~:. The general form is:

Grammar

#:~:text=[prefix-,]textStart[,textEnd][,-suffix]

Each part is percent-encoded; commas, hyphens and ampersands inside a part must be encoded so they are not read as separators.
PartRequiredMeaningHighlighted
textStartYesThe phrase to find, or the start of a rangeYes
textEndNoIf present, the match extends from textStart to the first textEnd after itYes (the whole range)
prefix-NoText that must appear immediately before the match (trailing hyphen)No
-suffixNoText that must appear immediately after the match (leading hyphen)No

Multiple directives are joined with &: #:~:text=first%20phrase&text=second%20phrase highlights both. Matching is case-insensitive and ignores differences in whitespace, and it only considers text the user could see and select (not hidden elements, not the contents of form fields). Word boundaries matter: a directive does not match in the middle of a word.

How the browser finds the passage

  1. The browser loads the page and, once the document is ready, looks for the directive in the fragment.
  2. It walks the visible text looking for the first occurrence of textStart that satisfies the prefix and suffix, if given.
  3. If textEnd is present, it extends the match to the first following occurrence of textEnd.
  4. It scrolls the match into view and applies a highlight (yellow or purple depending on the browser and version) using the ::target-text pseudo-element, which page authors can style.
  5. If nothing matches, or if the text arrives too late (some browsers stop searching after a short window), the page opens at the top as if the fragment were not there.

Scroll to text fragment: a worked example

Suppose you want to send a colleague to one sentence on a library's opening-hours page: "The reading room closes at 8 pm on weekdays and 5 pm on Saturdays." The page is invented; the syntax is real. Here is how the directive grows as you make it more precise.

Four versions of one link, from loose to exact.
GoalDirectiveWhat the browser does
Highlight a short phrase#:~:text=closes%20at%208%20pmHighlights the first "closes at 8 pm" on the page; if the cafe's hours use the same words higher up, that is the one it finds
Pick the right match with a prefix#:~:text=reading%20room-,closes%20at%208%20pmOnly a match that directly follows "reading room" counts; the prefix itself is not highlighted
Highlight the whole sentence#:~:text=The%20reading%20room,Saturdays.Highlights from "The reading room" to the first "Saturdays." after it, without spelling out the words between
Pin the match with a suffix#:~:text=closes%20at%208%20pm,-on%20weekdaysOnly a match directly followed by "on weekdays" counts

The encoding rules are small. Spaces become %20; a comma inside a phrase becomes %2C, a hyphen %2D and an ampersand %26, because those three characters are the separators of the directive itself. Generators do this for you. The browser-by-browser steps for copying a link to a highlight cover the built-in Copy link to highlight command in Chrome and Edge; the table above is what that command produces behind the scenes.

Expert tips

  • Quote four to eight words. Shorter phrases match in the wrong place; longer ones break on the first edit to the page.
  • Start and end on a word boundary. Matching respects word boundaries, so a phrase that begins mid-word never matches.
  • Test in a private window. No extension can interfere there, and the page loads as a stranger would see it.
  • Keep the words next to the link. When the link is part of a citation, adding a highlight link to a citation so the reader lands on the line shows the format.
  • Expect late-loading text to fail. Comment threads and some news sites fill in their text after the page appears; for those, the bookmarklet from inside the loaded page is the reliable route.

Privacy properties

The fragment part of a URL is not sent in the HTTP request, so the website cannot know which words you highlighted or that you used a text fragment at all. The browser also refuses to process text directives in situations where they could be used to test whether hidden text exists on a page (cross-origin frames, some scripted navigations), and it only activates them on a full navigation triggered by the user. Page authors can opt a page out entirely with the header Document-Policy: force-load-at-top. In practice, a text fragment link is as private as a plain link.

Styling highlights on your own pages

If you publish pages, you can control how incoming highlights look with a few lines of CSS. Only colour properties are allowed:

CSS

::target-text { background: #f5c400; color: #1c1b17; }

Known limits and how to work around them

Every failure falls back to a normal link to the page.
LimitWhyWork-around
Text that loads later is not foundThe browser searches once the document is ready and stops waiting after a momentUse the bookmarklet from inside the loaded page; or link to a static or print version
Edited text breaks the linkMatching is exact on the wordsKeep highlights short; quote the passage in your message too
Common phrases match the wrong placeThe first match winsAdd a prefix or suffix, or lengthen the phrase
Highlight disappears when the reader clicksSome browsers clear the highlight on interactionExpected behaviour; the reader has already found the passage
Not supported in PDFs, images or inside iframesThe standard covers HTML documents on the top-level pageUse PDF page links (#page=N) or the viewer's own highlighter
Very old browsersNo support before Chrome 80, Safari 16.1, Firefox 131The link still opens the page at the top

Where this came from

Sharing a highlighted passage used to require a service in the middle. The original Awesome Highlighter (2008) saved a copy of the page with your highlights and gave you a short link to it, and dozens of similar services did the same. That worked until the service closed, at which point every link died; our shared highlights archive page is the record of that. Text fragments move the highlight into the link itself, so it depends on nothing but the page it points to. It is the same idea, finally standardised.

Text fragments are the standard behind several tools compared elsewhere in the highlighter tools section: extensions increasingly use them for sharing (see our extension comparison), and the bookmarklet explainer shows how a one-click script builds them. They are also the most precise way to cite evidence, which is why quote tracing ends with one.

Common questions

What does #:~:text= mean in a URL?

It is a text fragment directive. The browser searches the page for the words after text=, scrolls to them and highlights them. The part after # is never sent to the website.

How do I make a text fragment link?

Select the text in Chrome or Edge and choose Copy link to highlight, or use the highlight link generator on this site, which encodes the phrase and optional prefix, suffix and range for you.

Why does my text fragment link not highlight anything?

The words changed, the text loads after the page appears, the phrase occurs earlier on the page, or the reader's browser is too old. Shorten the phrase, add context, or use the bookmarklet inside the loaded page.

Can I highlight a range of text rather than one phrase?

Yes. Use text=start,end. The browser highlights from the start phrase to the first end phrase after it.

Can a website block text fragment highlights?

Yes, with the Document-Policy: force-load-at-top response header. Few sites do.

Are text fragments part of an official standard?

They are specified by the WICG (URL Fragment Text Directives) and implemented by all major browsers. The specification is on a path toward full standardisation through the WHATWG URL and HTML work.