ID/Class Names beginning with numbers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
13 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ID/Class Names beginning with numbers

Thomas BAYER - Web Alliance

Hi.

 

I know my question may sound stupid or might have been answered tons of times, but here it is : why on earth can't a ID/Class name begin with a number ?

Wouldn't it be a huge enhancement for web developers if it was possible ?

 

Thanks in advance for the explanations.

 

http://www.web-alliance.fr

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Philip Taylor (Webmaster, Ret'd)


Thomas BAYER - Web Alliance wrote:

> Wouldn't it be a huge enhancement for web developers if it was possible ?

I can't see a /prima facie/ case for that. Why do you tacitly
assert that it would be the case, and would your argument
then not be equally true for (say) class or ID names to be
permitted to contain embedded spaces ?

Philip Taylor

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Thomas BAYER - Web Alliance
In reply to this post by Thomas BAYER - Web Alliance

Philip Taylor wrote :

 

> I can't see a /prima facie/ case for that. Why do you tacitly

> assert that it would be the case, and would your argument

> then not be equally true for (say) class or ID names to be

> permitted to contain embedded spaces ?

 

I'm just raising a question, and it seems to me - emphasis on *me* - that it would be useful to be able to have ID/Class names beginning by a number, mut that's just my point of view.

I used to be bothered by this at the beginning, for instance to distinguish odd and even rows/columns in a <table /> element, it just seemed counter-productive to assign class names like "td_0" and "td_0" instead of just "0" or "1".

 

Still, let's set aside my views on the matter, I'm just trying to understand the reason why it can't be done.

 

Finally, concerning the impossibility for ID/Class names to contain embedded spaces, it seems incompatible with CSS and jQuery selectors, to name just a few.

 

http://www.web-alliance.fr

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Alexander Christiaan Jacob
In reply to this post by Thomas BAYER - Web Alliance
Thomas BAYER - Web Alliance schreef op 27-11-2013 16:45:

Hi.

 

I know my question may sound stupid or might have been answered tons of times, but here it is : why on earth can't a ID/Class name begin with a number ?

Wouldn't it be a huge enhancement for web developers if it was possible ?



I'm pretty sure they can in HTML5+.

Greetings,

Alexander
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Philip Taylor (Webmaster, Ret'd)
In reply to this post by Thomas BAYER - Web Alliance


Thomas BAYER - Web Alliance wrote:

> Finally, concerning the impossibility for ID/Class names to contain
> embedded spaces, it seems incompatible with CSS and jQuery selectors, to
> name just a few.

The reasons why they cannot contain embedded (or even trailing) spaces
is clear, and does not need reference to other standards (such as CSS)
even less arbitrary libraries such as Jquery.  But that was not my
question -- I was simply asking if there can exist any justification for
allowing class/ID names to commence with a digit that would not equally
apply to allowing such names to contain spaces; both offer "convenience"
to those that would exploit such features, but little else.

Philip Taylor



Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Jukka K. Korpela
In reply to this post by Thomas BAYER - Web Alliance
2013-11-27 17:45, Thomas BAYER - Web Alliance wrote:

> I know my question may sound stupid or might have been answered tons of
> times, but here it is : why on earth can't a ID/Class name begin with a
> number ?

They can, in HTML5, which is what we mostly discuss on this list. (HTML
4 is still the "official" recommendation, but there has been no work on
it for years.) And here HTML5 reflects browser practices.

In HTML5, an id attribute value may be any nonempty string that does not
contain space characters. So id=42 is fine, and so is id=§42?. And a
class attribute value may be literally any string, for example class="42
¿Qué? #^!@§". Since it is by definition a sequence of class names
separated by space characters, a class name cannot contain a space
character, but other than this, a class name can be any string.

http://www.w3.org/TR/html5/dom.html#the-id-attribute
http://www.w3.org/TR/html5/dom.html#classes

> Wouldn't it be a huge enhancement for web developers if it was possible ?

No, it's not a big deal. Although id=4foo and class=4foo work fine as
far as HTML only is considered, they pose problems in CSS, and
especially class attributes are mainly used for CSS purposes. HTML5 (or
a browser) has no objection to class=4foo, but .4foo is not a valid
selector in CSS; you would need to use escape notations as in .\34foo
which is not that convenient and intuitively clear.

Yucca



Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Albert Lunde
On 11/27/2013 11:28 AM, Jukka K. Korpela wrote:
> 2013-11-27 17:45, Thomas BAYER - Web Alliance wrote:
>
>> I know my question may sound stupid or might have been answered tons of
>> times, but here it is : why on earth can't a ID/Class name begin with a
>> number ?
>
> They can, in HTML5, which is what we mostly discuss on this list. (HTML
> 4 is still the "official" recommendation, but there has been no work on
> it for years.) And here HTML5 reflects browser practices.

This does differ from HTML 4.01.

Agreement with previous HTML versions is probably what accounts for the
definition in the CSS Specifications.

The lack of a versioning mechanism in CSS may be considered a bug or a
feature....

--
     Albert Lunde  [hidden email]
                   [hidden email]  (address for personal mail)

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Jukka K. Korpela
2013-11-27 20:02, Albert Lunde wrote:

> On 11/27/2013 11:28 AM, Jukka K. Korpela wrote:
>> 2013-11-27 17:45, Thomas BAYER - Web Alliance wrote:
>>
>>> I know my question may sound stupid or might have been answered tons of
>>> times, but here it is : why on earth can't a ID/Class name begin with a
>>> number ?
>>
>> They can, in HTML5, which is what we mostly discuss on this list. (HTML
>> 4 is still the "official" recommendation, but there has been no work on
>> it for years.) And here HTML5 reflects browser practices.
>
> This does differ from HTML 4.01.

Yes it does. In this context, the difference means that HTML 4.01 has
formal rules that have no impact on reality. But for reasons external to
HTML, such as CSS syntax and the syntax of URLs (where id values may
appear), we may consider using mostly HTML 4.01 syntax for id and class
names. After all, they are supposed to be internal name tokens, not
visible to users.

> Agreement with previous HTML versions is probably what accounts for the
> definition in the CSS Specifications.

No, it's rather the general CSS syntax. A token that starts with .42
will be parsed as a real number. To keep CSS parsers simple, .42 is not
allowed selector - parsing of basic syntactic constructs does not depend
on context (like selector part of a rules vs. the part where a property
value is to appear).

> The lack of a versioning mechanism in CSS may be considered a bug or a
> feature....

Yes. In any case, it is a key part of the CSS development process. The
same really applies to HTML. People have just been misled into thinking
that old DOCTYPE strings specified the "HTML version being used".

Yucca



Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Philip Taylor (Webmaster, Ret'd)


Jukka K. Korpela wrote:

> People have just been misled into thinking that old DOCTYPE strings
> specified the "HTML version being used".

In what way have they been misled, Jukka ?  When I insert (e.g.,)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

at the top of a web page expressed in HTML, I am making a definite
statement that that is (a) the dialect I have elected to use, and
(b) that is the DTD against which the document should be checked
in the event that someone alleges it contains errors.  I do not
accept that I have been "misled" about its significance; what is
the basis for your assertion ?

Philip Taylor

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Jukka K. Korpela
2013-11-27 20:58, Philip Taylor wrote:

> Jukka K. Korpela wrote:
>
>> People have just been misled into thinking that old DOCTYPE strings
>> specified the "HTML version being used".
>
> In what way have they been misled, Jukka ?

The way that they regard a syntax declaration as specifying a version in
a manner that would matter anything outside formal validation.

>  When I insert (e.g.,)
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
> "http://www.w3.org/TR/html4/strict.dtd">
>
> at the top of a web page expressed in HTML, I am making a definite
> statement that that is (a) the dialect I have elected to use, and
> (b) that is the DTD against which the document should be checked
> in the event that someone alleges it contains errors.

By the SGML standard, which is normatively the only thing that matters
here, you are just specifying a DTD, a formal syntax specification.
Validators will by default use it, but this can be overridden in their
user interface.

Beyond that, it never had any impact, *except* that it triggers
"standards mode" in browsers - something quite different from its SGML
meaning.

Most importantly, browsers do not care the least about "HTML versions"
(apart from text/html vs. XML media types, but this does not depend on
the DOCTYPE string).

If someone alleges that your page contains errors, then a DOCTYPE is
just a formality. For example, the following document passes validation,
but it is neither conformant nor sensible:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<title/I made this up/
<h6><img src=logo.gif alt="TURN IMAGES ON YOU FOOL"></h6>

(The page uses an SGML construct that is valid in HTML 4.01 but not
supported by any browser. It also contains an alt attribute that is not
an adequate replacement for an image, violating HTML specifications, but
SGML validation cannot possibly detect this. And using a 6th level
heading as the only heading is just mad, but conforming.)

Yucca




Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Philip Taylor (Webmaster, Ret'd)


Jukka K. Korpela wrote:

> 2013-11-27 20:58, Philip Taylor wrote:

>> In what way have they been misled, Jukka ?
>
> The way that they regard a syntax declaration as specifying a version in
> a manner that would matter anything outside formal validation.

I'm not convinced that people have been "misled"; some may
have (mistakenly) assumed that the chosen syntax declaration
would matter outside of formal validation, and many more
would assert that the chosen syntax declaration /should/ matter
outside of formal validation -- I am not convinced that
either have been misled.

> By the SGML standard, which is normatively the only thing that matters
> here, you are just specifying a DTD, a formal syntax specification.
> Validators will by default use it, but this can be overridden in their
> user interface.

Indeed it can, but one reason for inserting the chosen DOCTYPE
is to inform anyone considering validating the page that they
should not seek to override it in the user interface other than
for reasons of pure intellectual curiousity.

> Beyond that, it never had any impact, *except* that it triggers
> "standards mode" in browsers - something quite different from its SGML
> meaning.

I would argue that it /does/ have in impact, but in the world of
human beings rather than the world of computers and automata.  It
make a statement that the author of the web page claims to have
some familiarity with the differences between various DOCTYPEs
and has elected to use that specific one for reasons that he or
she does not seek to explain (unless a human-readable comment
follows which explains why that particular DOCTYPE was chosen).
The fact that that statement may be false more often than it
is true does not detract from its putative significance.

> Most importantly, browsers do not care the least about "HTML versions"
> (apart from text/html vs. XML media types, but this does not depend on
> the DOCTYPE string).

That is a very sad but true fact.

> If someone alleges that your page contains errors, then a DOCTYPE is
> just a formality. For example, the following document passes validation,
> but it is neither conformant nor sensible:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
>    "http://www.w3.org/TR/html4/strict.dtd">
> <title/I made this up/
> <h6><img src=logo.gif alt="TURN IMAGES ON YOU FOOL"></h6>
>
> (The page uses an SGML construct that is valid in HTML 4.01 but not
> supported by any browser. It also contains an alt attribute that is not
> an adequate replacement for an image, violating HTML specifications, but
> SGML validation cannot possibly detect this. And using a 6th level
> heading as the only heading is just mad, but conforming.)

As we both know, "[validation] can be used to show the presence of
errors, but never to show their absence!" (with apologies to Prof.
Edsger Dijkstra[1]).

Philip Taylor
--------
[1] "Program testing can be used to show the presence of bugs, but never
to show their absence!" :  Dijkstra, E W (1970), in  "Notes
On Structured Programming", corollary at the end of section 3,
"On The Reliability of Mechanisms".

Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Jukka K. Korpela
2013-11-27 21:40, Philip Taylor wrote:

> Jukka K. Korpela wrote:
>
>> 2013-11-27 20:58, Philip Taylor wrote:
>
>>> In what way have they been misled, Jukka ?
>>
>> The way that they regard a syntax declaration as specifying a version in
>> a manner that would matter anything outside formal validation.
>
> I'm not convinced that people have been "misled";

I am. I have seen far too often statements saying that the DOCTYPE
declares the "HTML version", followed by speculation on its effects on
browsers. People even think they can't use HTML5 features if they
"declare" HTML 4.01 (i.e., use an HTML 4.01 doctype).

> one reason for inserting the chosen DOCTYPE
> is to inform anyone considering validating the page that they
> should not seek to override it in the user interface other than
> for reasons of pure intellectual curiousity.

Why would an author of a page care the least of what other people do if
they decide to use a validator on the page?

The Web would be a better place without this doctype nonsense. An author
who wishes to validate a page can specify the method of validation quite
independently of any magic strings in the page itself. But browsers
decided to apply "doctype sniffing", so we have to use a doctype, and
<!doctype html> is a simple way (quite independently of the "HTML
version" issue).

> It make[s] a statement that the author of the web page claims to have
> some familiarity with the differences between various DOCTYPEs

Well, this probably applies to you, me, and a handful of other people,
but most authors who slap a DOCTYPE string into their document (or have
one inserted by their authoring software) have no idea of this.

I used to be passionate about keeping words like "valid", "validator",
and "validity" in their technical SGML (or XML) sense, when discussing
HTML documents. But this seems to be a lost cause. HTML5 uses the word
"valid" freely and loosely, and I don't really blame them. Yet, now we
have the situation that there is no objective way of deciding whether a
document is valid or not (in the HTML5 sense); "valid" becomes a loose
word like "good" or "OK".

Yucca


Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ID/Class Names beginning with numbers

Philip Taylor (Webmaster, Ret'd)


Jukka K. Korpela wrote:

> 2013-11-27 21:40, Philip Taylor wrote:

>> one reason for inserting the chosen DOCTYPE
>> is to inform anyone considering validating the page that they
>> should not seek to override it in the user interface other than
>> for reasons of pure intellectual curiousity.
>
> Why would an author of a page care the least of what other people do if
> they decide to use a validator on the page?

Because it provide a 100% rebuttal against allegations such
as "Your page does not display correctly in XXXXX, and when
I validated it as HTML5, the validator told me it contains
nnn errors.  Can you please fix them as soon as possible,
as I need to access that page".  (Assuming that the page
was actually valid HTML 4.01 Strict, and displayed correctly
in all mainstream browsers other than XXXXX).

> The Web would be a better place without this doctype nonsense.

Let us agree to differ there.

> I used to be passionate about keeping words like "valid", "validator",
> and "validity" in their technical SGML (or XML) sense, when discussing
> HTML documents. But this seems to be a lost cause. HTML5 uses the word
> "valid" freely and loosely, and I don't really blame them. Yet, now we
> have the situation that there is no objective way of deciding whether a
> document is valid or not (in the HTML5 sense); "valid" becomes a loose
> word like "good" or "OK".

Quite.  But I don't think either of us wants to debate the rights and
wrongs of HTML5's redefinition of the word "valid", so I will stop here.

Philip Taylor

Loading...