Re: Is ID a valid attribute of the <style> tag?

Nathan Baker wrote:
> Dear W3C HTML Editor,

This list is for editorial comments on the XHTML specifications; it's
not for authoring questions. Try one of the many discussion groups
devoted to that topic, such as:

> I am a web developer in Central Pennsylvania. I am researching web 
> standards and I've run into a problem I cannot seem to find any 
> documentation on.
> Here is my question: Is ID a valid attribute of the <style> tag?
> Two sources I trust say it is not.
> does not list ID as a required, optional or standard 
> attribute of the <style> tag here - 
> Furthermore, the site 
> specifically states that ID is not a valid attribute in base, head, 
> html, meta, param, script, style and title elements on the page entitled 
> "HTML Standard Attributes" in the "HTmL and XHTML Full Reference" here - 

This is just one example of w3schools's many errors.

> The website states the same thing here - 

Why do you trust them, again? They're wrong too.

No source other than the specifications themselves should be trusted on
the question of what the standard is.

> I ran the page through the W3C validation service and it passed. I guess 
> this means that and are incorrect?


> I kept digging. I found that the W3c themselves do not mention ID as a 
> attribute of the <style> tag in their documentation on HTML 4 elements 
> here - 
> They only mention lang, dir, and title.


> So one last attempt to figure this out lead me to msdn where I found 
> that Microsoft actually does mention ID as an attribute of <style> here 
> - 
> <>. 
> They, however do not mention any others except DISABLED which doesn't 
> even make sense to me.

MSDN is a useful guide to Microsoft's implementations. It's not a
source for what the standard says, and doesn't pretend to be.

> Perhaps it has to with the fact that xml is parsed differently than 
> html? 

XML should be parsed differently from HTML, since they have differing 
declarations in terms of SGML. HTML should be parsed according to its 
SGML declaration (with error handling left up to implementations), but 
in fact popular browsers parse it as "tag soup":

Implementations also had to break compatibility with the HTML 
specification in order to parse XHTML 1.0 as text/html, thanks to W3C 
suggesting that this would work backwards-compatibly in "most HTML 

One of the aims of the new HTML working group is to define a parsing 
model for text/html that is based around the tag soup parsing browsers 
need to do in order to remain compatible with the web:

However, the differences between HTML and XML parsing don't explain the 
difference you've observed.

> I've read that xml can validate while not actually being 
> semantically correct.

In the case of /both/ HTML and XHTML, validation checks only a subset of
syntactical requirements, which in turn are only a subset of possible
conformance requirements. Validity constraints were expressed in terms
of a machine-readable SGML Document Type Definition. (Some validators do
add some warnings on top that are not DTD-based, but these don't affect
the validity of documents.) Unfortunately, DTDs are not flexible enough
to express all syntactical requirements:

More importantly, many non-syntactical conformance requirements would be 
hard for a program to check. It takes human judgement to tell whether 
heading elements are used for headings and whether provided ALT 
attributes for images are appropriate text alternatives.

> For instance, in xhtml served as xml a <span> 
> could wrap a <p> and still validate.

No. That violates one of the syntactical constraints that /can/ be 
expressed with a DTD.

> The xml parser only checks for well-formedness.

Parsing (converting a serialization to a XML document object model) and 
validating are not the same thing. Validation is not required for 
parsing. Some XML processors check for well-formedness only; some 
additionally validate documents against a DTD or other machine-readable 

> At this point I'm thinking that if I want to serve my xhtml documents as 
> xml, I will not use styleblocks in the head. I'll stick to external css 
> files.

Be warned that Internet Explorer, by far the most popular browser on
earth, aims to support HTML 4.01; it does not yet (as of version 8 Beta) 
attempt to support XHTML.

> If you could please offer clarification on this matter I would very much 
> appreciate your help.

HTML 4.01 /does not/ allow an ID attribute for the STYLE element, as can
be seen from its DTDs (search for "ELEMENT STYLE"):

XHTML 1.0 /does/ allow an id attribute for the style element, as can be
seen from the example you cite and from an its DTDs (search for "ELEMENT

Guides to reading DTDs can be found at:

Hope that helps.
Benjamin Hawkes-Lewis

Received on Monday, 9 June 2008 08:03:52 UTC