Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use white spaces in the name attribute of an HTML element? [duplicate]

Tags:

html

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 !

like image 636
Tchypp Avatar asked Apr 16 '11 17:04

Tchypp


People also ask

Can HTML tags have spaces?

Rule 6: Tag Names Cannot Contain Spaces.

Does HTML ignore whitespace?

The HTML interpreter ignore white spaces by default. HTML ignore any space added after the first space between words. Any space at the start or end of a HTML tags is completely ignored. HTML interpreters also ignore line breaks by default.

How do I make white space in HTML?

To insert blank spaces in text in HTML, type &nbsp; for each space to add. For example, to create five blank spaces between two words, type the &nbsp; entity five times between the words. You do not need to type any spaces between the entities.

What is white space in HTML?

Whitespace refers to characters which are used to provide horizontal or vertical space between other characters. Whitespace is often used to separate tokens in HTML, CSS, JavaScript, and other computer languages.


2 Answers

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.

like image 99
Quentin Avatar answered Oct 15 '22 13:10

Quentin


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.

like image 36
Mikecito Avatar answered Oct 15 '22 12:10

Mikecito