Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order of tags in <head></head>

Tags:

html

xhtml

does it matter at all what order the <link> or <script> or <meta> tags are in in the <head></head>?

(daft question but one of those things i've never given any thought to until now.)

like image 264
Chris J Allen Avatar asked Oct 10 '08 11:10

Chris J Allen


People also ask

What is the order of tags in HTML?

Within a web page, some HTML tags are required for the page to be displayed correctly. These tags are <html> , <head> , <title> and <body> . The <html> tags must begin and end the document and the <head> tags must appear before the <body> tags. Also, the <title> tags must be within the <head> tags.

Which sequence of HTML tags is correct a HTML >< head >< title ></ title ></ head >< body ></ body ></ HTML B HTML >< head >< title >< body ></ title ></ head ></?

Hence, Option 1 is correct. The HTML <title> tag is used for indicating the title of the HTML document. The body title is placed between the <head> and the </head> tags. HTML document title is visible via the browser's title bar.

What is the correct tag for head?

HTML <head> Tag. The <head> tag in HTML is used to define the head portion of the document which contains information related to the document.

Where is the head and </ head tags?

The head tag is an element in HTML files that can contain metadata (data about data) and script calls. The head tag is placed between the opening <HTML> and <body> tags at the beginning of the HTML file. The metadata in the head tag is not displayed, but the information is used by browsers and by search engines.


Video Answer


2 Answers

Optimization

According to the folks over at Yahoo! you should put CSS at the top and scripts at the bottom because scripts block parallel downloads. But that is mostly a matter of optimization and is not critical for the page actually working. Joeri Sebrechts pointed out that Cuzillion is a great way to test this and see the speed improvement for yourself.

Multiple Stylesheets

If you are linking multiple stylesheets, the order they are linked may affect how your pages are styled depending on the specificity of your selectors. In other words, if you have two stylesheets that define the same selector in two different ways, the latter will take precedence. For example:

Stylesheet 1:

h1 { color: #f00; } 

Stylesheet 2:

h1 { color: #00f; } 

In this example, h1 elements will have the color #00f because it was defined last with the same specificity:

Multiple Scripts

If you are using multiple scripts, the order they are used may be important if one of the scripts depends on something in another script. In this case, if the scripts are linked in the wrong order, some of your scripts may throw errors or not work as expected. This, however, is highly dependent on what scripts you are using.

like image 171
9 revs Avatar answered Nov 04 '22 07:11

9 revs


The accepted answer is kind of wrong, depending on the encoding of the document. If no encoding is sent by in the HTTP header, the browser has to determine the encoding from the document itself.

If the document uses a <meta http-equiv="Content-Type" … declaration to declare its encoding, then any ASCII-valued character (character code < 128) occurring before this statement must be an ASCII value, as per HTML 4 spec. Therefore, it's important that this meta declaration occurs before any other element that may contain non-ASCII characters.

like image 27
Konrad Rudolph Avatar answered Nov 04 '22 07:11

Konrad Rudolph