W3C home > Mailing lists > Public > public-html-comments@w3.org > August 2009

Alternate syntax for defining class attribute

From: T.J. Crowder <tj@crowdersoftware.com>
Date: Sun, 9 Aug 2009 16:53:45 +0100
Message-ID: <c95470a0908090853k46e3bcd9y6ad4b6e131cbc83a@mail.gmail.com>
To: public-html-comments@w3.org
Hello,

First off, thank you for all of your work hammering out HTML5.
Greatly appreciated!

I have a suggestion which may be too late for HTML5 or not in keeping
with the philosophy, but I'll give it a go:

We use the class attribute a *lot*.  To save our poor fingers, not to
mention reduce document sizes, would it be possible to introduce an
alternate syntax for simple situations (one class) mirroring the basic
CSS class selector syntax?  E.g., this:

    <div class='nifty'>nifty stuff here</div>

becomes

    <div.nifty>nifty stuff here</div>

Seems to me this is easily parsed and not a significant burden to
implementors, whereas I think most authors would be thrilled to have
the syntax line up with CSS and to stop typing "class='" all over the
place.

This is an alternate, not a replacement.  If one needs multiple class
names, for example, one would use the original syntax.  Now, it would
be nice to be able do something like this:

    <div."nifty stuff">nifty stuff here</div>

....if people who know more about parsers than I (their numbers are
legion) say that the optional quotes aren't hard to deal with.

Obviously the caveat would be that if you send this alternate form to
a UA that doesn't understand HTML5, it's not going to be a happy
bunny.  Caveat author.

Alternatively (no pun), a less easily-parsed version that doesn't seem
to break the small number of UAs I tried (all browsers: IE7, FF3,
Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
the tag and the dot:

    <div .nifty>nifty stuff here</div>

Older browsers wouldn't see the class name, obviously, but they seem
to mostly ignore the invalid attribute.  I don't like this becaue it
looks like a parsing nightmare to me, although as I said, I'm not a
parser guy.

Apologies if this is a duplicate.  A couple of archive searches didn't
turn it up, but there are probably 18 ways to phrase this.

Thanks for listening,
--
T.J. Crowder
tj / crowder software / com
Received on Monday, 10 August 2009 08:15:28 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 1 June 2011 00:14:00 GMT