Is an ID allowed to be empty in an HTML tag?
I wouldn't set it to blank initially, just have the script (or however means your inserting your ID) append an attribute to the div
. That way your code will validate, if that means anything to you.
Blank attributes are not valid, but having no attribute is valid. There shouldn't be any problems with it, just makes sure you are keeping your IDs unique. I'm sure you knew that, though.
Even if no browser will crash on empty IDs, if you wanna generate valid HTML, you should generate fake IDs and differents, say, prefix + counter.
According to the W3C:
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 (".").
(Source: Basic HTML data types)
This would indicate that a blank value for the attribute is not valid in accordance with the above definition.
Trying to validate against an empty ID attribute returns the following:
syntax of attribute value does not conform to declared value
<div id="">something</div>
The value of an attribute contained something that is not allowed by the specified syntax for that type of attribute. For instance, the “selected” attribute must be either minimized as “selected” or spelled out in full as “selected="selected"”; the variant “selected=""” is not allowed.