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:

http://webdesign-l.com/

> 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.
> 
> W3Schools.com does not list ID as a required, optional or standard 
> attribute of the <style> tag here - 
> http://www.w3schools.com/tags/tag_style.asp. 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 - 
> http://www.w3schools.com/tags/tag_style.asp.

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

> The website xhtml.com states the same thing here - 
> http://xhtml.com/en/xhtml/reference/style/

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 W3Schools.com and xhtml.com are incorrect?

Yep.

> 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 - http://www.w3.org/TR/REC-html40/present/styles.html#edef-STYLE. 
> They only mention lang, dir, and title.

Correct.

> 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 
> - http://msdn.microsoft.com/en-us/library/ms535898(VS.85).aspx 
> <http://msdn.microsoft.com/en-us/library/ms535898%28VS.85%29.aspx>. 
> 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":

http://en.wikipedia.org/wiki/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 
browsers":

http://www.w3.org/TR/2000/REC-xhtml1-20000126/#issues

http://cvs.savannah.gnu.org/viewvc/w3/lisp/w3-parse.el?root=w3&r1=1.19&r2=1.20

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:

http://www.w3.org/2007/03/HTML-WG-charter

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:

http://www.w3.org/TR/REC-html40/sgml/intro.html#h-19.1

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 
schema:

http://www.w3.org/TR/REC-xml/#proc-types

> 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"):

http://www.w3.org/TR/REC-html40/sgml/dtd.html

http://www.w3.org/TR/REC-html40/sgml/loosedtd.html

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
style"):

http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Strict

http://www.w3.org/TR/xhtml1/dtds.html#a_dtd_XHTML-1.0-Transitional

Guides to reading DTDs can be found at:

http://www.w3.org/TR/REC-html40/intro/sgmltut.html#h-3.3

http://www.autisticcuckoo.net/archive.php?id=2005/05/01/art-of-reading-dtd

Hope that helps.
--
Benjamin Hawkes-Lewis

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