Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialErik Nuber
20,629 Pointswhen to use <link> versus <link />
I have been looking at a lot of code trying to further my understanding, specifically the difference between canonical and alternate as a relationship value and have noticed that the <link> tag is written two different ways based on the websites you visit but, I can't find an explanation as to why.
First is how it is shown in this video
<link rel="stylesheet" href="style.css">
Than I have seen it written out as
<link rel=”canonical” href=”http://www.example.com/url-a.html” />
This second one has a floating / at the end and, I have seen several pages where even the first example has / after it. Is this for an older version of HTML? For some other purpose? I have also wondered if this is simply a way of closing the link since it is self closing and, maybe other tags like <img> that are self-contained should also have this.
2 Answers
Luke Pettway
16,593 Points"Under XHTML 1.0, empty elements such as <link> require a trailing slash: <link />".
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link
So for example if you were using XHMTL 1.0 you would have to do the same with the img tag
<img src="cat.jpg" />
XHTML is more strict but you don't see it too often anymore. If you'd like to know more about it: http://www.webstandards.org/learn/articles/askw3c/oct2003/
Erik Nuber
20,629 PointsGreat thank you, I appreciate the quick answer.