Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can self closing <link> tags be problematic?

Tags:

I read that self closing tags were problematic for some browsers such as IE7 and Firefox 3 here: Why don't self-closing script tags work?

I am curious if this issue can also hold true for linking stylesheets.

For example using

<link href="/css/style.css" rel="stylesheet" type="text/css" /> 

Instead of

<link href="/css/style.css" rel="stylesheet" type="text/css"></link> 
like image 343
Jeremy A. West Avatar asked Mar 30 '12 13:03

Jeremy A. West


People also ask

Should link tags be self closing?

None of the markup needs to conform to XML in this case, so no self-closing tag syntax is needed, either.

Can a tag be self closing?

A self-closing tag is an element of HTML code that has evolved in the language. Typically, the self-closing tag makes use of a “/” character in order to effectively close out a beginning tag enclosed in sideways carets.

Should meta tags be self closing?

<meta> HTML Tag This element must not contain any content, and does not need a closing tag.

Why is it important to use closing tags?

Should Optional HTML Tags be Closed? Code with closing tags is much more readable and easy to follow. It is much easier to visually inspect a page with well laid out markup. Working with this markup is easier for developers.


2 Answers

<link href="/css/style.css" rel="stylesheet" type="text/css"></link> is not a good idea.

If you use html4 use this:
<link href="/css/style.css" rel="stylesheet" type="text/css">

If you use xhtml use this:
<link href="/css/style.css" rel="stylesheet" type="text/css" />

In html5 both versions are fine.

like image 131
Hubert Schölnast Avatar answered Sep 19 '22 06:09

Hubert Schölnast


HTML 4

http://www.w3.org/TR/html401/struct/links.html#edef-LINK
Start tag: required, End tag: forbidden

HTML 5

http://www.w3.org/TR/html5/document-metadata.html#the-link-element
Tag omission in text/html: No end tag.

http://www.w3.org/TR/html5/syntax.html#elements-0
"Void elements: ... link ..."
"Void elements only have a start tag; end tags must not be specified for void elements."

like image 33
Sebbe Avatar answered Sep 22 '22 06:09

Sebbe