Zach Shallbetter Zach Shallbetter - 28 days ago 10
CSS Question

Are CSS3 namespaces used for anything except XML?

We have a client that would like us to use CSS3 namespaces. However, everything I'm finding indicates that it is specifically used for styling XML and not HTML. Can anyone validate using it for CSS/HTML or clarify how you would do this? What are the negatives of following this method?

@namespace toto "http://toto.example.org";

toto|Product {
display:block;
}

toto|Code {
color: black
}


http://www.w3.org/TR/css3-namespace/

http://onwebdev.blogspot.com/2010/04/css3-namespace-selectors.html

Answer

Can anyone validate using it for CSS/HTML or clarify how you would do this?

Major browsers use a default namespace of http://www.w3.org/1999/xhtml which is XHTML's namespace, even for HTML, and go about their business. Technically though, since HTML isn't XML, there isn't a point to this unless you consider that XML-based languages like SVG and MathML can be embedded within HTML anyway.

If your client wants to make use of CSS namespaces, they'll probably need to provide you with something that's written in a language that has some sort of namespacing mechanism that is compatible with CSS. It is meaningless to try and apply this knowledge to HTML itself because

  • HTML wasn't exactly designed to be namespaced in the first place
  • browsers already assign a default namespace to (X)HTML documents that you can't access explicitly anyway

More information can be found in this answer.

To answer your question title, the document language does not necessarily have to be XML-based:

Besides terms introduced by this specification, CSS Namespaces uses the terminology defined in Namespaces in XML 1.0. However, the syntax defined here is not restricted to representing XML element and attribute names and may represent other kinds of namespaces as defined by the host language.

The CSS Namespaces spec borrows terminology from XML Namespaces as a convenience simply because CSS is most commonly applied to HTML and XML documents (and even then, more people use XSL(T) with the latter instead).