Style Type="Text/Css" ... What Else Is There

style type= text/css ... what else is there?

There also are XSL (Extensible Stylesheet Language) stylesheets for styling XML documents. They cannot be used with HTML though.

CSS works for XML docs, but using XSL is recommended. Opposed to CSS, XSL is a Transformation Language (transforms input text written in a formal language into a modified output text).

Further references:

http://www.w3.org/Style/

http://www.w3.org/Style/XSL/

Is there a style type besides text/css?

HTML 4 and 5 leave open the possibility of other types, but do not specify any besides "text/css". In practice, I have never encountered a case where anything but "text/css" is used. For this reason, the HTML5 specification made the type attribute optional. If it is omitted, the default type "text/css" is used. See the style tag specification for details:

The type attribute gives the styling language. If the attribute is
present, its value must be a valid MIME type that designates a styling
language. The charset parameter must not be specified. The default
value for the type attribute, which is used if the attribute is
absent, is "text/css". RFC2318

In HTML 4 documents, the type attribute must be specified. The specification does not limit the values that can be used:

This attribute specifies the style sheet language of the element's
contents and overrides the default style sheet language. The style
sheet language is specified as a content type (e.g., "text/css").
Authors must supply a value for this attribute; there is no default
value for this attribute.

In old versions of HTML (<= 4) the type attribute appears to be an attempt to maintain compatibility with the <link> method of importing stylesheets, where the type is required:

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

Do we need type= text/css for link in HTML5

The HTML5 spec says that the type attribute is purely advisory and explains in detail how browsers should act if it's omitted (too much to quote here). It doesn't explicitly say that an omitted type attribute is either valid or invalid, but you can safely omit it knowing that browsers will still react as you expect.

Is type= text/css necessary in a link tag?

It's not required with the HTML5 spec, but for older versions of HTML is it required.

Html 4 W3.org spec

http://www.w3.org/TR/html40/struct/links.html#edef-LINK
http://www.w3.org/TR/html40/present/styles.html

Type stands for The MIME type of the style sheet. The only supported value I have ever seen is Text/CSS, which is probably why HTML5 has dropped it. I imagine they had it for earlier versions to allow future expansion possibilities which never happened.

Using HTML5 and not specifying the type, I have run so far into no problems with compatibility even when testing older versions of IE.

Is there a useful purpose for style type= text/javascript ?

It's for "JSSS", or Javascript style sheets; see here for more info. It's nonstandard and never really caught on outside of Netscape's original proposal, which you can read here. I don't think most browsers today support this; I've certainly never seen a website that used it.

How can I remove a style type= text/css ... /style inside my variable with Javascript and regex

Ingmars has the right idea, except it's missing an important question mark, some additional HTML/XML possibilities (such as whitespace allowed after the tag name in both cases, and attributes in the first case), and also replacing it with a message (I'm assuming that you just wanted to delete it completely).

This will work except if attributes contain ">" which is a calculated risk. The code is written given that htmlString is the actual variable that you have containing the HTML document.

htmlString = htmlString.replace(/<style\b[^<>]*>[\s\S]*?<\/style\s*>/gi, '');


Related Topics



Leave a reply



Submit