{"id":45677,"date":"2024-11-05T14:17:06","date_gmt":"2024-11-05T19:17:06","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=45677"},"modified":"2026-04-17T08:31:12","modified_gmt":"2026-04-17T12:31:12","slug":"how-to-highlight-text-fragments-when-linking","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/11\/05\/how-to-highlight-text-fragments-when-linking\/","title":{"rendered":"How to Highlight Text Fragments When Linking"},"content":{"rendered":"<p><a href=\"https:\/\/weblog.rogueamoeba.com\/2024\/08\/08\/how-to-highlight-text-fragments-when-linking\/\">Paul Kafasis<\/a>:<\/p>\n<blockquote cite=\"https:\/\/weblog.rogueamoeba.com\/2024\/08\/08\/how-to-highlight-text-fragments-when-linking\/\">\n<p>In recent months, I&rsquo;ve begun to notice that results from web searches often highlight specific text on the page to which they&rsquo;re linking. The web page is also scrolled to the relevant content. It&rsquo;s quite helpful!<\/p>\n<p>A quick investigation showed this is accomplished by appending a bit of code, <code>#:~:text=<\/code> to the URL for a link. These are called <a href=\"https:\/\/web.dev\/articles\/text-fragments\">Text Fragments<\/a>, and they&rsquo;ve been supported by Chrome since back in 2020. It took a couple more years for support to come to Safari, but at this point, the element is <a href=\"https:\/\/caniuse.com\/?search=text%20fragments\">well-supported enough<\/a> to be worth using.<\/p>\n<p>[&#8230;]<\/p>\n<p>By using this code in a bookmarklet, you can easily create links with helpful highlighting.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/alfy.blog\/2024\/10\/19\/linking-directly-to-web-page-content.html\">Ahmad Alfy<\/a>:<\/p>\n<blockquote cite=\"https:\/\/alfy.blog\/2024\/10\/19\/linking-directly-to-web-page-content.html\"><p>This feature is complemented by the <code>::target-text<\/code> CSS pseudo-element, which provides a way to style the highlighted text.<\/p><p>[&#8230;]<\/p><p>Here&rsquo;s the basic syntax for a text fragment URL:<\/p><pre>\nhttps:\/\/example.com\/page.html#:~:text=[prefix-,]textStart[,textEnd][,-suffix]\n<\/pre><\/blockquote>\n\n<p>Via <a href=\"https:\/\/pxlnv.com\/linklog\/text-fragments\/\">Nick Heer<\/a>:<\/p>\n<blockquote cite=\"https:\/\/pxlnv.com\/linklog\/text-fragments\/\">\n<p>As someone who writes essays containing citations, this is one of the nicest additions to the web that I wish was easier to use in Safari. What I, like Alfy, want to be able to do is highlight a specific phrase and copy a direct link.<\/p>\n\n<p>Also, something I often forget is that you can link directly to specific pages of a PDF file by appending <code>#page=<\/code> and then the page number.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/www.tomshardware.com\/software\/how-to-deep-link-to-a-specific-pdf-page\">Avram Piltch<\/a>:<\/p>\n<blockquote cite=\"https:\/\/www.tomshardware.com\/software\/how-to-deep-link-to-a-specific-pdf-page\">\n<p>Note that you should use the page number within the PDF (as seen in the page list), not whatever number it says on the top of the page itself.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/underpassapp.com\/news\/2024\/10\/5.html\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/underpassapp.com\/news\/2024\/10\/5.html\">\n<p>StopTheMadness Pro 11.0 adds the ability to copy a <a href=\"https:\/\/developer.mozilla.org\/docs\/Web\/URI\/Fragment\/Text_fragments\">text fragment<\/a> link from selected text in Safari, using a <a href=\"https:\/\/underpassapp.com\/StopTheMadness\/Pro\/Docs\/WebsiteOptions.html#:~:text=Contextual%20Menu%20Items%20(macOS%20Safari)\">contextual menu item<\/a> on macOS or <a href=\"https:\/\/underpassapp.com\/StopTheMadness\/Pro\/Docs\/Buttons.html#:~:text=Show%20Menu%20on%20Tap\">Show Menu on Tap<\/a> on iOS.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@xeenon\/113409717246944569\">Timothy Hatcher<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@xeenon\/113409717246944569\">\n<p>This is actually in Safari 18.2 beta now as well.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/underpassapp.com\/news\/2024\/11\/1.html\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/underpassapp.com\/news\/2024\/11\/1.html\"><p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Sherlock_(software)#Sherlocked_as_a_term\">Sherlocked<\/a>: The phenomenon of Apple releasing a feature that supplants or obviates third-party software<\/p><p>[&#8230;]<\/p><p>The good news is that this feature is available now in StopTheMadness Pro, whereas Safari 18.2 is not scheduled for release by Apple until December. Also, it&rsquo;s available in StopTheMadness Pro to users of older versions of Safari. And from what I&rsquo;ve seen, Apple&rsquo;s feature is available only in macOS Safari, not in iOS Safari. So my efforts weren&rsquo;t totally wasted.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2016\/07\/18\/medium-url-fragment-tracking\/\">Medium URL Fragment Tracking<\/a><\/li>\n<\/ul>\n\n<p id=\"how-to-highlight-text-fragments-when-linking-update-2024-11-06\">Update (2024-11-06): <a href=\"https:\/\/hachyderm.io\/@vitor\/113433008486898268\">V&iacute;tor<\/a>:<\/p>\n<blockquote cite=\"https:\/\/hachyderm.io\/@vitor\/113433008486898268\">\n<p>There&rsquo;s also an <a href=\"https:\/\/alfred.app\/workflows\/alfredapp\/web-highlight\/\">Alfred workflow<\/a> for this.<\/p>\n<\/blockquote>\n\n<p id=\"how-to-highlight-text-fragments-when-linking-update-2024-11-07\">Update (2024-11-07): See also: <a href=\"https:\/\/forum.keyboardmaestro.com\/t\/highlighting-text-fragments-when-linking\/38246\">Keyboard Maestro<\/a>.<\/p>\n\n<p id=\"how-to-highlight-text-fragments-when-linking-update-2024-12-17\">Update (2024-12-17): <a href=\"https:\/\/underpassapp.com\/news\/2024\/12\/3.html\">Jeff Johnson<\/a>:<\/p>\n<blockquote cite=\"https:\/\/underpassapp.com\/news\/2024\/12\/3.html\"><p>It turns out, however, that the <a href=\"https:\/\/underpassapp.com\/StopTheMadness\/\">StopTheMadness Pro<\/a> contextual menu item to copy text fragment links is not as Sherlocked as I thought. That&rsquo;s because my feature works right, and Safari&rsquo;s doesn&rsquo;t. [&#8230;] Apparently Safari doesn&rsquo;t correctly handle paragraph breaks.<\/p><\/blockquote>\n\n<p id=\"how-to-highlight-text-fragments-when-linking-update-2025-04-29\">Update (<a href=\"#how-to-highlight-text-fragments-when-linking-update-2025-04-29\">2025-04-29<\/a>): <a href=\"https:\/\/tidbits.com\/2025\/04\/23\/text-fragments-enable-deep-linking-on-web-pages\/\">Adam Engst<\/a>:<\/p>\n<blockquote cite=\"https:\/\/tidbits.com\/2025\/04\/23\/text-fragments-enable-deep-linking-on-web-pages\/\">\n<p>You can highlight multiple portions of a document by editing the text fragment URL and appending additional <code>text=<\/code> elements, separated by an <code>&amp;<\/code>. It requires precise work to copy the <code>text=<\/code> element from one URL and paste it into another, but the result may be worthwhile.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Paul Kafasis: In recent months, I&rsquo;ve begun to notice that results from web searches often highlight specific text on the page to which they&rsquo;re linking. The web page is also scrolled to the relevant content. It&rsquo;s quite helpful! A quick investigation showed this is accomplished by appending a bit of code, #:~:text= to the URL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-11-05T19:17:11Z","apple_news_api_id":"eb09eebb-6e59-4b3b-a24d-cd409a5ac279","apple_news_api_modified_at":"2026-04-17T12:31:17Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAABw==","apple_news_api_share_url":"https:\/\/apple.news\/A6wnuu25ZSzuiTc1AmlrCeQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[2],"tags":[627,338,31,2586,346,30,2598,345,103,1775,489,96],"class_list":["post-45677","post","type-post","status-publish","format-standard","hentry","category-technology","tag-bookmarks","tag-css","tag-ios","tag-ios-18","tag-javascript","tag-mac","tag-macos-15-sequoia","tag-pdf","tag-safari","tag-stop-the-madness","tag-url","tag-web"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=45677"}],"version-history":[{"count":9,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45677\/revisions"}],"predecessor-version":[{"id":51618,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/45677\/revisions\/51618"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=45677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=45677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=45677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}