On this page
A text fragment lets you share a link to a passage on a webpage, rather than asking someone to find it themselves. In a browser that supports the feature, opening the link can scroll to and highlight the matching text. Here’s how to create one, test it, and provide a fallback for readers whose browsers don’t support it.
Key Takeaways
- Add
#:~:text=followed by URL-encoded text to make a basic text-fragment link. - A text fragment matches page text; a traditional anchor points to an element identified by the page author.
- Test the link in the browsers your readers use. If the text changes, the match can fail or point somewhere unexpected.
- Share a normal page link and a short description of the passage as a fallback. Don’t put sensitive text in the URL.
Text fragments versus page anchors
A traditional anchor such as #methods refers to an element with a corresponding ID on the page. It depends on the page author providing that target.
A text fragment instead describes text to find. A basic link looks like this:
https://example.com/#:~:text=Example%20Domain
The part after #:~:text= is the text to match; %20 represents a space. Text fragments can also specify the beginning and end of a longer passage, separated by a comma. The punctuation in the directive matters, so encode text copied from a page rather than inserting it blindly into a URL.
Unlike an element ID, the quoted text can change when the page is edited. Text fragments are therefore convenient for sharing, but they are not permanent identifiers.
Advertisement
How to link to specific text on a webpage
This example uses example.com, a public example domain. The page’s current content and browser behavior could not be checked for this article, so confirm the wording and test the link yourself before sharing it.
- Open
https://example.com/and find the visible heading. If it says “Example Domain,” use that phrase for the example below. Otherwise, choose text that is actually present and encode it for a URL. - Open this link in a browser that supports text fragments: Example Domain text link.
- Check whether the browser moves to or highlights the intended heading. On a short page, there may be little visible scrolling, so look for a highlight as well.
- Copy the link into another browser or a private window and repeat the check. Confirm the exact passage, not just that the page opens.
Some browsers offer a command to copy a link to selected text. If yours does, select the passage, use that command, and test the resulting URL. The command’s availability and wording depend on the browser.
Link to a longer passage
A text directive can use a start phrase and an end phrase, separated by a comma:
https://example.com/article#:~:text=opening%20words,closing%20words
This is a syntax illustration, not a verified link. Replace the address and phrases with text from the page you want to share. Choose phrases that occur in the intended passage and test the result, especially if the page repeats the same wording. More specific context can help distinguish repeated text, but a copied link should still be checked.
Test changed or missing text
To see the failure case, change the example directive to a phrase that is not on the page:
https://example.com/#:~:text=This%20phrase%20is%20not%20on%20the%20page
In a supporting browser, the page can still open, but there should be no matching passage to highlight. A real link can fail similarly if the author edits or removes the text. If an excerpt appears more than once, a match may also land somewhere other than the intended passage. Reopen shared links when accuracy matters, and use the browser’s page search to investigate unexpected results.
Advertisement
Browser support and fallback
Text-fragment behavior varies by browser and environment. The W3C specification and current documentation from major browser vendors were not available to consult for this article, so browser support has not been verified here. Before publishing a link for an audience, check current vendor documentation and test the actual link in the relevant browsers and devices. A browser without support may open the page without navigating to the passage.
Provide a normal link alongside the text-fragment link, plus enough context to locate the passage manually. For example:
- Passage link: Example Domain heading
- Fallback: Example Domain page — look for the main heading.
For longer pages, include the section title or a short, non-sensitive quotation that readers can search for. If the page has a stable author-provided anchor, that can also be a useful fallback.
Privacy and accessibility
The selected words are part of the shareable URL. Anyone who receives, copies, or stores that URL can see them, so do not use text fragments for passwords, personal information, private document excerpts, or other sensitive material. Be mindful that links may be retained in browser history, messages, bookmarks, or other systems used to share them.
A visible highlight is not an accessible instruction for every reader. A browser or assistive technology may not announce the highlighted passage or move focus in the way a reader expects. Include descriptive link text and a plain-language location, and make the normal page link available so readers can navigate or search independently.
Common Mistakes
- Sharing without testing: The page can open even when the passage does not match or the browser does not support the feature.
- Choosing ambiguous text: Repeated phrases can lead to an unintended location. Use more distinctive wording and check the result.
- Treating the link as permanent: An edit, removal, or site redesign can invalidate the match.
- Relying only on a highlight: Give readers a page link and instructions for finding the passage without it.
- Putting sensitive content in the fragment: The words are visible in the URL you share.
Best Practices
Use the shortest distinctive passage that identifies the intended location, then test it from the recipient’s perspective. For important citations, record the page title, section, and a non-sensitive excerpt alongside the link. Recheck links after a page changes and before relying on them in a published document.
Conclusion
Text fragments are a useful way to point readers to a passage without requiring the page author to add an anchor. Test the match and browser support, and always give readers a normal link and enough context to find the text themselves.
What would your domain sell for?
A free TidyURLs account unlocks the Domain Estimator. It prices a name from 191,011 real domain sales.