When the attribute value can remain unquoted in HT

2020-07-17 07:39发布

问题:

When the attribute value can remain unquoted in HTML5?

HTML4.01 was a SGML application. So in HTML4 quotes can be omitted if the only characters used in the value are ones currently declared as name characters: alphanumeric character, full stop, -, :, _.

Well, from the W3C working draft (13 January 2011):

The attribute value can remain unquoted if it doesn't contain spaces or any of " ' ` = < or >.

But if I put in the attribute value any other character than alphanumeric character, full stop, -, :, _ and remain it unquoted validator.w3.org doesn't validate my html document as valid HTML5 document.

So the question is still open. Is it a mistake of HTML5 working draft or is it a mistake on validate.w3.org?

回答1:

No, the working draft is fine and the validator is working correctly.

Try this

<!DOCTYPE html>
<title>test</title>
<div class=%test$></div>

at http://validator.w3.org/#validate_by_input

The validator is happy with both the % and $ characters. So what exactly are you testing?



回答2:

This article on unquoted attribute values in HTML and CSS will answer your question. There’s also a tool: http://mothereff.in/unquoted-attributes



回答3:

Unless you are sticking in the xmlns attribute to your html element, rendering your document as XHTML 5 (the XML serialization of HTML 5), using unquoted values with appropriate characters validates as proper HTML 5.