36

A question has rised in my project team as we are designing a web page. Can we use white characters (like space) in the name attribute of an HTML element ? eg. <input type="checkbox" name="first check box">

My concern is mainly the behavior of different browsers with such an attribute value.

We are now in the design phase, until we get to write some code and test this, a long time will pass, so I am asking you experts about this.

Thank you !

Tchypp
  • 1,075
  • 2
  • 13
  • 20

2 Answers2

47

Yes.

The name attribute contains CDATA. It can be more or less anything you like. (You shouldn't include leading or tailing white space because user agents can ignore it, but white space in the middle is fine).

Note that name attributes do not have NAME tokens as their data type (although the id attribute does (the id attribute doesn't take an ID token)), so you don't have the restrictions imposed on NAME tokens.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • +1 @David is correct as pointed out by @preinheimer: http://www.w3.org/TR/html401/interact/forms.html `name CDATA #IMPLIED -- name of form for scripting` Learned something, thanks. – Pekka Apr 16 '11 at 17:21
  • Yup. "CDATA is a sequence of characters from the document character set and may include character entities." – Quentin Apr 16 '11 at 17:22
1

Most browsers will handle this fine, as long as they are properly quoted. However, for sake of eliminating corner cases, it's much wiser to user CamelCase and avoid the probability of browsers not handling it correctly.

Mikecito
  • 2,053
  • 11
  • 17
  • 4
    What browser fails to handle it correctly? (I prefer to avoid hacking around unconfirmed bugs in unspecified browsers when the spec says what I want to do is fine) – Quentin Apr 16 '11 at 17:26