Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<link> vs <a>: when to use one over the other?

I have some confusion between <link> and <a>.

I know that in order to add CSS to an HTML document we use the <link> tag, for example:

<link type="text/css" rel="stylesheet" href="/spinner/styles.css?ln=css" /> 

But, I can't understand why we do not use an anchor <a> tag (as it contains the same necessary attributes), something like:

 <a type="text/css" rel="stylesheet" href="/spinner/styles.css?ln=css" /> 

Are these two tags interchangeable? Also, if this is possible, then how do we choose one over the other and why?

Update:

I got that confusion, because I saw in The Complete Reference HTML & CSS book regarding the rel attribute of the <a> Tag, that:

rel: For anchors containing the href attribute, this attribute specifies the relationship of the target object to the link object.

So I thought that it could do the same function as the <link> tag.

like image 355
Tarik Avatar asked Feb 21 '15 19:02

Tarik


People also ask

What is the difference between link tag link and anchor tag A?

These are two different things. The anchor element is used to link to another page or to a certain part of the page if you use its ID. And The link tag defines a link between a document and an external resource. The link tag is used to link to external style sheets.

What is the difference between A and a link in CSS?

a covers all the bases. a:link is used only if the link in un- visited , un- hover ed, and in- active . So, use a for things like font-family (if you want links to come up in a different font), then use link for the standard formatting, and visited , hover and active for 'special effects'.

What is the difference between using link to page and a href page?

<a> is the html element used to display an hypertext reference link (clickable anchor) in <body> part (content) of the page, while <link> is used in <head> part (document meta informations) to link an external ressource file to the document... Wow, awesome community. Thanks everyone.


1 Answers

Attributes are not the same as the tag they are in.

<link /> is an empty element, i.e. it can not have anything inside of it. All it does is specify a relationship with another document. Additionally, the <link> tag is only used in the <head> section.

<a></a> on the other hand, is not an empty element and specifies an object to be created on the page - like a clickable link or image - which takes the user to some other location. This tag is only used in the <body> section.

So, even though the tags can have the same attributes, that does not mean they do the same thing.

like image 127
Jon Egeland Avatar answered Sep 25 '22 02:09

Jon Egeland