Projects Blog

Useful VSCode snippets: anchor with target="__blank" in Markdown and MDX

A good practice to speed up development in VSCode is creating snippets of code that we frequently use.

If you are someone who uses Markdown or MDX, like me for this blog or documentation sites, you’ll definitely benefit from having a snippet for inserting external URLs that automatically open in a new tab.

When we add an external URL with this behavior in a Markdown or MDX file, we need to write the HTML Anchor element with 3 attributes: href, target and rel.

Adding the snippet will prevent you from writing the full markup element every time you need one (which could be quite frequent).

Adding the snippet

{
// Rest of the JSON
"Anchor with target blank": {
"prefix": "anchorBlank",
"body": ["<a href=\"${1:url}\" target=\"_blank\" rel=\"noreferrer\">${2:text}</a>"],
"description": "Add anchor with target blank"
}
}

And now, you can use this snippet writing the starting letters of the prefix, pressing Ctrl + Space for IntelliSense suggestions and selecting the anchorBlank option.

VSCode IntelliSense suggesting our snippet

I hope you found this article useful.

Happy coding! 🚀

Related posts