Last Updated
Viewed 424,220 Times
  

When creating the id attributes for HTML elements, what rules are there for the value?

When creating the class attributes for HTML elements, what rules are there for the value?

Is it valid HTML to use IRIs containing non-ASCII characters as attribute values (e.g. for href attributes) instead of URIs? Are there any differences among the HTML flavors (HTML and XHTML, 4 and 5)? At least RFC 3986 seems to imply that it isn't.

I realize that it would probably be safer (regarding older and IRI-unaware software) to use percent encoding, but I'm looking for a definitive answer with regards to the standard.

So far, I've done some tests with the W3C validator, and unescaped unicode characters in URIs don't trigger any warnings or errors with HTML 4/5 and XHTML 4/5 doctypes (but of course the absence of error messages doesn't imply the absence of errors).

At least chrome also supports raw UTF-8 IRIs, but percent-escapes them before firing an HTTP request. Also, my web server (lighttpd) seems to support UTF-8 characters in their percent-encoded as well as in unencoded form in an HTTP request.

Usually HTML element attribute values are marked with a quotation mark, like


<input type="hidden" value="test" />

Sometimes, however, you see code like


<input type='hidden' value='test' />

Is it valid HTML and can it cause any problems? What about mixing the two, like


<input type='hidden' value="test">

?

Similar Question 7 (1 solutions) : &amp; is valid in an HTML attribute?

Similar Question 9 (1 solutions) : PHP check if it is a valid HTML attribute

cc