The valid values for id attributes are different in HTML4 and HTML5.
HTML5
HTML does not allow space characters. The string should not be empty. It must contain atleast one character.
<p id="test">This is demo text.</p> <p id="#test"> This is demo text.</p>
Refer for more.
HTML4
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 (".").
Refer for more.