What is the context here?
Long blog posts and guides are hard to share. Someone wants to send a colleague to one section, so they send the whole page and say "scroll down to the bit about pricing".
This snippet gives every H2 and H3 inside a rich text element its own ID and adds a small link icon next to it. Click the icon and the URL for that section is copied to the clipboard.
How to set it up
- Paste the full snippet into the Before </body> tag custom code on your CMS template page. Use the site settings instead if you want it on every page.
- You don't need to create any classes in Webflow. The script targets Webflow's default rich text class (
.w-richtext) and adds a.heading-anchorclass to each button it creates, which the CSS styles. If.heading-anchorclashes with a class already on your site, rename it in both the style and script tags. - Change the tick colour by swapping
#1f9d55for your brand colour or a variable. - If you have a fixed navbar, set
scroll-margin-topto your nav height. Otherwise the heading lands underneath the nav. - Publish and test on the live site. Custom code doesn't run in the Designer.
How it works
- Finds every H2 and H3 inside the rich text elements on the page.
- Builds an ID from the heading text, so "How it works" becomes #how-it-works. Duplicate headings get -1, -2 added, and headings that already have an ID keep it.
- Adds a link button to each heading. It shows on hover and on keyboard focus, and it's always visible on touch devices.
- On click, it copies the full URL including the section link, updates the address bar, and shows a tick for 1.5 seconds.


