Search code examples
htmlrel

Can you tag hyperlinks with arbitrary tags using the relative attribute?


The following syntax seems to be valid in HTML:

 <a rel="nofollow" href="http://www.functravel.com/">Cheap Flights</a>

Now, suppose I wanted to have an arbitrary word inserted in the place of "nofollow", would that be valid? For example, suppose there were three kinds of hyperlinks: red, green, and blue. Could I then use these as tags as follows:

<a rel="green" href="http://www.functravel.com/">Cheap Flights</a> 

If the above is allowed, could I go one step further and define a hyperlink with two or more relative attributes, like the following:

 <a rel="nofollow red" href="http://www.functravel.com/">Cheap Flights</a> 

I'm just interested in the theoretical possibilities.


Solution

  • No

    The HTML specification defines the allowed values for the rel attribute.

    Since there is a set of allowed values, deviating from that list is (implicitly) not allowed (and validation will throw an error if you try).

    The class attribute allows you to add arbitrary tags to any element. data-* attributes also allow you to add custom information to an element. Use one of them instead.