36

Possible Duplicate:
What are valid values for the id attribute in HTML?
valid value for name attribute in html

It is valid to name a HTML5 input with a string containing a period?

<input type="text" name="article.title" value="The title"/>
Community
  • 1
  • 1
David Tuite
  • 22,258
  • 25
  • 106
  • 176
  • [Here you go](http://stackoverflow.com/q/3447329/645270) (How to work with it) – keyser Sep 29 '12 at 08:22
  • dup http://stackoverflow.com/questions/10369295/valid-value-for-name-attribute-in-html – Prinzhorn Sep 29 '12 at 08:23
  • @Prinzhorn That question is more to do with whether or not PHP considers it valid. I'm asking about whether or not the HTML spec considers it valid. – David Tuite Sep 29 '12 at 08:28
  • @DavidTuite right, the question is different. but the answer says "By HTML rules, the name attribute may have any value" – Prinzhorn Sep 29 '12 at 09:39

3 Answers3

26

Yes, it's valid.

But you will make things difficult for yourself if you need to access them via JS or CSS in particular. Again, it can be done, but it will make things difficult.

My advice is to use a hyphen instead.

Spudley
  • 166,037
  • 39
  • 233
  • 307
  • 3
    "But you will make things difficult for yourself if you need to access them via JS or CSS in particular. " - or easier, depending on if you're building around that expectation or not. – Nathan Hornby Dec 01 '15 at 13:22
3

It is valid according to this part of the HTML5 spec.

The name content attribute gives the name of the form control, as used in form submission and in the form element's elements object. If the attribute is specified, its value must not be the empty string.

Any non-empty value for name is allowed, but the names "charset" and "isindex" are special:

emphasis mine

Community
  • 1
  • 1
David Tuite
  • 22,258
  • 25
  • 106
  • 176
0

"Attribute values can contain text and character references, with additional restrictions depending on whether they are unquoted attribute values, single-quoted attribute values, or double-quoted attribute values. Also, the HTML elements section of this reference describes further restrictions on the allowed values of particular attributes, and attributes must have values that conform to those restrictions."

from w3.org (W3C Working Draft):

HTML Syntax - HTML5