This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 14145 - Spaces in id attributes [was Could we define the id attribute so as to allow multiple unique ids to point to the same DOM element, by separating the names given in the value by spaces?]
Summary: Spaces in id attributes [was Could we define the id attribute so as to allow ...
Status: RESOLVED WONTFIX
Alias: None
Product: HTML WG
Classification: Unclassified
Component: HTML5 spec (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: ---
Assignee: Ian 'Hixie' Hickson
QA Contact: HTML WG Bugzilla archive list
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-14 10:44 UTC by contributor
Modified: 2011-10-19 23:10 UTC (History)
6 users (show)

See Also:


Attachments

Description contributor 2011-09-14 10:44:47 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html
Multipage: http://www.whatwg.org/C#the-id-attribute
Complete: http://www.whatwg.org/c#the-id-attribute

Comment:
Could we define the id attribute so as to allow multiple unique ids to point
to the same DOM element, by separating the names given in the value by spaces?

Posted from: 134.214.169.135
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.9 Safari/535.2
Comment 1 Thaddee TYL 2011-09-14 10:52:50 UTC
The specification currently says:

"This specification doesn't preclude an element having multiple IDs, if other mechanisms (e.g. DOM Core methods) can set an element's ID in a way that doesn't conflict with the id attribute."

It also says:

"The value [of an ID attribute] must not contain any space characters."

 and later:

"[] user agents must associate the element with the given value (exactly, including any space characters)"

The current state in Google Chrome, Firefox and Opera (at least) is that space characters are not allowed in IDs: if they have a space in their value, you cannot refer to them at all, even if it is a trailing space.
Comment 2 Thaddee TYL 2011-09-14 12:00:21 UTC
It seems that, due to an error in the tests I did, my previous comment is wrong.

Chrome, Firefox and Opera all allow spaces in id attributes without any need to escape using %20.

I therefore suggest to remove the sentence that says:

"The value must not contain any space characters."

and to remove the paragraph that says:

"This specification doesn't preclude an element having multiple IDs, if other mechanisms (e.g. DOM Core methods) can set an element's ID in a way that doesn't conflict with the id attribute."

as Anne Van Kesteren suggested to me on #whatwg.
Comment 3 Simon Pieters 2011-09-14 12:57:10 UTC
(In reply to comment #2)
> I therefore suggest to remove the sentence that says:
> 
> "The value must not contain any space characters."

Allowing spaces in IDs would break things that have a list of space-separated IDs, e.g. <td headers>.
Comment 4 Thaddee TYL 2011-09-14 20:29:29 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > I therefore suggest to remove the sentence that says:
> > 
> > "The value must not contain any space characters."
> 
> Allowing spaces in IDs would break things that have a list of space-separated
> IDs, e.g. <td headers>.

While I understand this position, I would like to mention the fact that, while browsers currently accept id values with spaces in them, they disregard <td headers> completely (see http://jsbin.com/aguhuf/3) because they do not implement DOM4's DOMSettableTokenList.

Since I hope to have DOM4 implemented in browsers, I wish to +1 Simon Pieters on this one.

My updated request is therefore to:

- remove the parenthesized expression here:

"[] user agents must associate the element with the given value (exactly,
including any space characters)"

- remove the paragraph that says:

"This specification doesn't preclude an element having multiple IDs, if other
mechanisms (e.g. DOM Core methods) can set an element's ID in a way that
doesn't conflict with the id attribute."

---

On the other hand, I would rather we specified the behavior that browsers should follow when encountering an id value that contains a space.

Along the suggestions that spring to mind:

- Remove the id attribute (which will break the page if a script relies on it)
- Remove the spaces in the id value (which will break the page just as much)
- Let it pass, but show a warning in the dev tools, and let the page fail if a <td headers> refers to it (which may have unexpected results since the @id value will be cut in half in the @headers value)

We should make it clear that this isn't optimum behavior, though. Having this parenthesized "exactly, including any space characters" puzzles me.
Comment 5 Ian 'Hixie' Hickson 2011-10-19 23:10:41 UTC
EDITOR'S RESPONSE: This is an Editor's Response to your comment. If you are satisfied with this response, please change the state of this bug to CLOSED. If you have additional information and would like the editor to reconsider, please reopen this bug. If you would like to escalate the issue to the full HTML Working Group, please add the TrackerRequest keyword to this bug, and suggest title and text for the tracker issue; or you may create a tracker issue yourself, if you are able to do so. For more details, see this document:
   http://dev.w3.org/html5/decision-policy/decision-policy.html

Status: Rejected
Change Description: no spec change
Rationale: We now defer to the DOM Core specification for the ID attribute stuff, so this is no longer in scope for the HTML spec.