views:

48

answers:

2

Are there any issues (either technically, or otherwise) with putting a space character in an element ID? For example, something like this:

<li id='something with spaces'>Test123</li>

I understand that this is NOT desirable (I have never used spaces before), but I have hit a scneario where I need to do this if possible.

What are the potential issues (if any) I may face with scaling, any particular browsers, scripting, or CSS styling?

Are there any articles that talk about the 'bad characters' that CAN be used but SHOULD NOT be used?

Thanks -

+1  A: 

The issue is that spaces in IDs are not valid according to the HTML spec so behaviour is undefined.

Just use underscores and/or hyphens like everyone else. You might get this to work. You might. I expect there'll be some fairly obscure corner cases. What I'm certain you're doing is creating a maintenance nightmare for whoever follows you.

cletus
+6  A: 

Per the standard,

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

By breaking this rule you'r likely to run into no end of trouble from standard-complying processors of your (invalid) HTML. So, I would recommend you don't do this.

Alex Martelli
that link was exactly what I was looking for - thanks. Will go another route (thanks)!
OneNerd