Add icons to external links
Using a rehype plugin, you can identify and modify links in your Markdown files that point to external sites. This example adds icons to the end of each external link, so that visitors will know they are leaving your site.
PrerequisitesSection titled Prerequisites
- An Astro project using Markdown for content pages.
RecipeSection titled Recipe
Import the plugin into your
rehypePluginsarray, along with an options object that includes a content property. Set this property’s
textif you want to add plain text to the end of the link. To add HTML to the end of the link instead, set the property
The value of the
content property is not represented in the accessibility tree. As such, it’s best to make clear that the link is external in the surrounding content, rather than relying on the icon alone.