Is There a Style Type Besides Text/Css

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" />

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/

Are there any other style types besides CSS for HTML?

Netscape 4 (only) supported Javascript Style Sheets.

Is type= text/css mandatory on the link element?

I found the answer on the official W3C HTML5 draft:

The type attribute gives the MIME type of the linked resource. It is
purely advisory
. The value must be a valid MIME type.

For external resource links, the type attribute is used as a hint to
user agents so that they can avoid fetching resources they do not
support. If the attribute is present, then the user agent must assume
that the resource is of the given type (even if that is not a valid
MIME type, e.g. the empty string). If the attribute is omitted, but
the external resource link type has a default type defined, then the
user agent must assume that the resource is of that type. (...)

User agents must not consider the type attribute authoritative — upon
fetching the resource, user agents must not use the type attribute to
determine its actual type. Only the actual type (...).

The stylesheet link type defines rules for processing the resource's
Content-Type metadata. (...)

If a document contains style sheet links labeled as follows:

 <link rel="stylesheet" href="A" type="text/plain">
<link rel="stylesheet" href="B" type="text/css">
<link rel="stylesheet" href="C">

...then a compliant UA that supported only CSS style sheets would
fetch the B and C files, and skip the A file (since text/plain is not
the MIME type for CSS style sheets).

For files B and C, it would then check the actual types returned by
the server. For those that are sent as text/css, it would apply the
styles, but for those labeled as text/plain, or any other type, it
would not.

If one of the two files was returned without a Content-Type metadata,
or with a syntactically incorrect type like Content-Type: "null", then
the default type for stylesheet links would kick in. Since that
default type is text/css, the style sheet would nonetheless be
applied.

For the <style> attribute, the same document states:

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]

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, '');

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.



Related Topics



Leave a reply



Submit