Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use meta tag Content-Style-Type for external css?

Tags:

html

Browsing through the source code of Microsoft's sample StockTrader application, I found this snippet in all aspx files:

<meta http-equiv="Content-Style-Type" content="text/css"/>
<title>.NET StockTrader Portfolio</title>
<link rel="stylesheet" href="StockTrader.css" type="text/css" />

Why have the meta tag when the link tag says it all? Am I missing something?

like image 722
ottodidakt Avatar asked Jan 08 '10 05:01

ottodidakt


People also ask

What is the use of meta tag in CSS?

The <meta> tag defines metadata about an HTML document. Metadata is data (information) about data. <meta> tags always go inside the <head> element, and are typically used to specify character set, page description, keywords, author of the document, and viewport settings.

Which attribute is used for external CSS?

css . External stylesheets use the <link> tag inside the head element. The rel attribute explains the relation the link has to our document. The value in this case will always be stylesheet , since that is what we're creating a link to.

Which tag is used for an external style sheet?

css extension and should be linked to the HTML document using link tag. This means that for each element, style can be set only once and that will be applied across web pages. link tag is used to link the external style sheet with the html webpage.

What is the use of external CSS in HTML?

External CSS An external style sheet is used to define the style for many HTML pages.


2 Answers

The reason why you in theory need a Content-Style-Type setting is for inline style attributes:

<div style="color: red;">

What styling language is that in? Unlike with <style> and <link rel="stylesheet"> tags there is no type attribute mechanism to tell the browser what language that is: hence the document-global Content-Style-Type.

The same applies to Content-Script-Type and inline event handler attributes:

<div onclick='alert("hello")'>

What language is that? It's actually equally valid in JavaScript and VBScript; in IE it could be either. In theory, you should give the browser a Content-Script-Type header/meta to tell it. Even with plain old JavaScript, you might want to change the dialect by setting type parameters such as text/javascript;version=1.6 or e4x=1 (if you wanted to use E4X XML literals, which you don't because they're a vile mistake).

In practice, none of this is of any use whatsoever, since the default CSS is the only style language you can actually use, many browsers don't pay any attention to Content-Style-Type anyway, and no browser pays any attention to Content-Script-Type.

(Ah well, who needs inline style and event handler attributes anyway?)

like image 104
bobince Avatar answered Oct 20 '22 16:10

bobince


The "Content-Style-Type" meta tag is used to set the default style type for the document. In practice, this doesn't seem that useful, as most people specifically specify the style types whenever they are used, such as in the <link> tag in your question. This particular declaration seems extra redundant as well. According to the W3:

User agents should determine the default style sheet language for a document according to the following steps (highest to lowest priority):

  1. If any META declarations specify the "Content-Style-Type", the last one in the character stream determines the default style sheet language.
  2. Otherwise, if any HTTP headers specify the "Content-Style-Type", the last one in the character stream determines the default style sheet language.
  3. Otherwise, the default style sheet language is "text/css".

So theoretically, using "Content-Style-Type" to set the default to "text/css" is just overriding what the browser would have assumed anyway, although maybe it's insurance against a rogue web server that might try to set something in the HTTP headers.

It's probably generated in an enthusiastic attempt to be standards compliant.

Quick edit note: That W3 document I linked to actually claims that a document that has elements which use a style attribute without defining a default style sheet language is an incorrect document. I've never seen this come up as an issue in a validator before however.

like image 35
zombat Avatar answered Oct 20 '22 14:10

zombat