4

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?

Joel Mueller
  • 28,324
  • 9
  • 63
  • 88
Andy
  • 603
  • 6
  • 16
  • [This article on unquoted attribute values in HTML and CSS](http://mathiasbynens.be/notes/unquoted-attribute-values) will answer your question. There’s also a tool: http://mothereff.in/unquoted-attributes – Mathias Bynens Jan 23 '12 at 09:00

3 Answers3

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?

Alohci
  • 78,296
  • 16
  • 112
  • 156
  • Ok this is not reproduced anymore. But two weeks ago this was reproduced. I should have tested again before publish this question yesterday. So the question is closed. Thanks – Andy Mar 27 '11 at 09:14
  • Although $ should be escaped in most cases too – Andy Mar 27 '11 at 09:29
  • `%test$` is indeed a valid unquoted attribute value in HTML. However, it isn’t in CSS: http://mothereffingunquotedattributes.com/#%25test%24 – Mathias Bynens Jun 14 '11 at 12:23
1

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

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
0

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.

Kevin Ji
  • 10,479
  • 4
  • 40
  • 63