
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.
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]
| Part | Required | Meaning | Highlighted |
|---|---|---|---|
textStart | Yes | The phrase to find, or the start of a range | Yes |
textEnd | No | If present, the match extends from textStart to the first textEnd after it | Yes (the whole range) |
prefix- | No | Text that must appear immediately before the match (trailing hyphen) | No |
-suffix | No | Text 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
- The browser loads the page and, once the document is ready, looks for the directive in the fragment.
- It walks the visible text looking for the first occurrence of
textStartthat satisfies the prefix and suffix, if given. - If
textEndis present, it extends the match to the first following occurrence oftextEnd. - It scrolls the match into view and applies a highlight (yellow or purple depending on the browser and version) using the
::target-textpseudo-element, which page authors can style. - 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.
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
| Limit | Why | Work-around |
|---|---|---|
| Text that loads later is not found | The browser searches once the document is ready and stops waiting after a moment | Use the bookmarklet from inside the loaded page; or link to a static or print version |
| Edited text breaks the link | Matching is exact on the words | Keep highlights short; quote the passage in your message too |
| Common phrases match the wrong place | The first match wins | Add a prefix or suffix, or lengthen the phrase |
| Highlight disappears when the reader clicks | Some browsers clear the highlight on interaction | Expected behaviour; the reader has already found the passage |
| Not supported in PDFs, images or inside iframes | The standard covers HTML documents on the top-level page | Use PDF page links (#page=N) or the viewer's own highlighter |
| Very old browsers | No support before Chrome 80, Safari 16.1, Firefox 131 | The 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.
Sources
- WICG: URL Fragment Text Directives, editor's draft
- MDN Web Docs: Text fragments and ::target-text
- Chrome 80 release notes (February 2020); WebKit Safari 16.1 release notes; Firefox 131 release notes