Link to text fragments on webpages
Posted on 2026.10.01
Some time ago I have discovered that it's possible to create a URL that will point to any text, on any website. And it's super simple! Here is a link with a text fragment anchor:
https://developer.mozilla.org/en-US/docs/Web/URI/Reference/Fragment/Text_fragments#:~:text=sequence,tells
This will link you to a word "Browsers" on the MDN page that describes Text Fragments. The magic of this link lays in this specific suffix:
#:~:text=sequence,tells
Quoting MDN, the syntax is:
https://example.com#:~:text=[prefix-,]textStart[,textEnd][,-suffix]
So my link will point to a text fragment that starts with sequence and ends with tells. You could also link to
#:~:text=sequence%20of%20characters%20tells
as you can just escape spaces but I find the start and end word syntax nicer.
This feature is a part of WICG specs and it is also supported by all browsers according to MDN. Also, you can use CSS to style the highlight via
::target-text {
background-color: rebeccapurple;
color: white;
}
Sweet.
Personally, I never remembered what is exact syntax hence I just installed an extension that allows me for copying a link to the page with attached text fragment anchor. Works well even if it just the "textStart" part of the syntax.