Text fragment link generator

Create a link that scrolls to and highlights a passage of a web page (#:~:text=), with optional end and context text, several passages at once, or

loading Text fragment link generator
About this tool

What is a text fragment link?

A normal link can jump to a section of a page only if the author put an anchor there. A text fragment link needs no anchor: it points to any words on the page. When you open https://example.com/page#:~:text=an%20example, a supporting browser scrolls to the first place where the words "an example" appear and highlights them. It is the feature behind the yellow highlight you see when you click a quote from a search result, and it is described in the WICG specification "Scroll to Text Fragment".

The format is #:~:text= followed by up to four parts: prefix-,start,end,-suffix. Only start is required. If you give an end, the browser highlights everything from the first start to the next end, which keeps the link short for a long passage. The optional prefix and suffix are context: they must be next to the passage for it to match, which helps when the same words occur several times, and they are not highlighted. You can chain several passages with &text=.

The part that goes wrong by hand is the encoding. Every part is percent-encoded as UTF-8, and three characters have to be encoded because they are the syntax itself: the dash -, the comma , and the ampersand &. Spaces, accents, Arabic or Japanese text and the percent sign must be encoded too. This tool does it exactly, builds links with one or many passages, normalizes line breaks and double spaces of text copied from a page, and keeps any existing query and section anchor of the address.

It also works backwards: paste a link and see which passages it highlights, split into text before, start, end and text after, and which directives are invalid or unknown. Everything runs in your browser; the address and the text are not sent anywhere.

How to create a link

  1. Open the page. It starts with the example of the Wikipedia article on cats, with a prefix, a start, an end and a suffix.
  2. Type or paste the address of the page.
  3. Copy the exact words you want to highlight from the page and paste them in "Text to highlight". Case and spelling must match the page.
  4. For a long passage, put only the first words there, open "Range and context" and put the last words in "Text where the passage ends".
  5. If the words appear more than once, add "Text just before" or "Text just after" to pick the right one.
  6. Copy the link. Use "Add another passage" for more highlights in the same link.

Examples

One phrase

https://example.com#:~:text=an%20example%20text%20fragment

The browser highlights the first "an example text fragment" on the page.

A range, to keep the link short

https://example.com#:~:text=an%20example,text%20fragment

From the first "an example" up to the next "text fragment".

A phrase with context and a comma

https://en.wikipedia.org/wiki/Cat#:~:text=Claws-,Like%20almost,the%20Felidae%2C,-cats

The prefix "Claws" and the suffix "cats" select the right place. The comma inside "the Felidae," is written as %2C, so it is not taken as a separator.

Two passages

https://example.com#:~:text=foo&text=bar

Each passage is independent: if one fails to match, the other still works.

Common mistakes

  • Not encoding the dash and the comma. A hyphenated word such as "well-known" breaks the link unless the dash is %2D. The tool does this for you.
  • Typing the text from memory. It has to match the visible text of the page exactly, including accents. Copy it.
  • Choosing text that appears several times. Without context the first match is highlighted, which may not be the one you meant. Add a prefix or suffix.
  • Putting a section anchor after the directive. The order is #anchor:~:text=. The tool writes it in the right order.
  • Expecting it to work everywhere. Text must be in visible content, not inside a collapsed section, a form field or an image, and the browser must support the feature.
  • Using it on pages that change. If the passage is edited or removed, the link just opens the page without highlighting.

Frequently asked questions

Which browsers support it?

Recent versions of Chrome, Edge, Safari and Firefox. Older browsers ignore the part after :~: and open the page normally, so the link is safe to share.

Does the site see the highlighted text?

The fragment directive is processed by the browser and is not sent to the server, as with any part after #. It is also hidden from the page's own scripts.

Can I add it to a link that has tracking parameters?

Yes, the query string is kept as it is. To remove tracking parameters first, use the URL cleaner. To inspect the final address, use the URL parser.

Why is my link so long?

Each character outside letters and digits becomes three characters, and non-Latin letters become six or more. Use a start and an end instead of the whole passage.

Can I read the highlighted text of an existing link?

Yes, in the "Read link" tab. For the encoding itself, the URL encoder shows how any text is percent-encoded.

Report a problem