Setting rel attributes in Markdown

Markdown can't do everything, including rel attributes. Use HTML for these links instead.

Markdown is great for a lot of things. Where is starts to fall over is when you need specific HTML attributes for elements covered by Markdown. rel is an example of this.

If you are trying to add the rel attribute to a Markdown link, you will need to jump into HTML and write it inline. The vast majority of Markdown parsers will accept this. If you were searching for an answer, there it is! No need to keep reading. But here is some more information if you’re curious.

You should pay attention to where you are linking and why, when you do, you will often want to add rel to a link, for example linking to a page that you don’t want a bot or spider to follow you could do <a href="/blah" rel="nofollow">, or if you are marking up a sponsored post you would use rel="sponsored".

I won’t talk about the specific properties of rel attributes in this article (but watch this space, because as I type this I’m getting excited about jotting some stuff down!) but having rel attributes is really important. Stuff you post on the internet is accessed lots of times by lots of different people and machines. Appropriate use of rel can save machines lots of effort, which is good for the environment, and, as I can argue in another article, good for your website.

update to get it out of my system;

Anyway, back to my point. Markdown doesn’t really care about the outside world, and as such didn’t have a thing built in to add these types of attributes.

In Markdown we would write [my link](/my-link), which would get translated into <a href="/my-link">my link</a>. You can’t shoehorn in other attributes, even more common ones like class aren’t supported.

There are some proposals for a syntax to support it;

[Google](https://google.com){:rel=“nofollow”}

From a DatoCMS discussion around rel=”nofollow”

[1]:!http://my-site.com/article1

From a Github discussion around rel=”nofollow”

Even if either approach was adopted, unless there was near universal adoption in Markdown parsers, I think it would be safer to drop down to HTML.


Recent posts View all

Ruby

Forcing a Rails database column to be not null

How you can force a table column to always have something in it with Rails

Writing Marketing

We've deleted an article's worth of unhelpful words

We've improved several pages across our site by removing words that add no value, and often detract from the article.