views:

51

answers:

5

Is it considered valid to do the following:

<li>stuff</li class="randomlengthclassname">
<li>stuff</li class="shortclassname">
<li>stuff</li class="reallyreallylongarseclassname">

or do the attribute have to be in the opening tag?

+5  A: 

No it isn't. You must use attributes in the opening tag.

Running <a>test</a href="tst.html"> in w3c validator results in this error:

name start character invalid: only S separators and TAGC allowed here

Where S separators and TAGC are:

    S is "whitespace" separator

    [5] s =

        SPACE | (32) space
        RE | (13) CR
        RS | (10) LF
        SEPCHAR (9) HT

            -- http://xml.coverpages.org/sgmlsyn/sgmlsyn.htm#C6.2.1

    TAGC    ">"

            -- http://www.w3.org/TR/sgml.l
Oded
+2  A: 

The attribute has to be in the opening tag. The code which you have presented probably wouldn't work.

rhino
+5  A: 

This is not valid, and all attributes must be defined in the opening tag, indeed.

romaintaz
+1  A: 

Attributes should appear in the element's start tag. Quoting the W3C: On SGML and HTML Attributes:

... Attribute/value pairs appear before the final ">" of an element's start tag. Any number of (legal) attribute value pairs, separated by spaces, may appear in an element's start tag. They may appear in any order.

Daniel Vassallo
A: 

Closing tags may not contain attributes. But in HTML4 you may omit the closing LI:

<!ELEMENT LI - O (%flow;)*             -- list item -->
<!ATTLIST LI
  %attrs;                              -- %coreattrs, %i18n, %events --
  >

Start tag: required, End tag: optional

In XHTML, you may not.

Gordon