Do you quote HTML5 attributes?

ryanve picture ryanve · Jun 27, 2011 · Viewed 21k times · Source

Attribute quotes are optional in HTML5.

What are the pros/cons to quoting them?

id=example                     <!--quotes optional-->
href=http://example.com        <!--quotes optional-->
class="example example-1"      <!--quotes required due to space-->
href="http://example.com/p=47" <!--quotes required due to '=' sign-->

Update: Added advantages based on the answers:

Advantages to quoting all attributes:

  • all editors can deal with it properly
  • more consistent
  • better portability (easier to change doctype)
  • easier to maintain (esp. if attributes might become empty)
  • easier to 'find and replace' changes
  • cleaner doc (if you think quotes improve readability)
  • ?

Advantages to omitting optional quotes:

  • slightly reduced filesize
  • cleaner doc (if you prefer minimal text)
  • ?

Answer

Pekka picture Pekka · Jun 27, 2011

I'm in favour of always using quotes.

  • It looks way cleaner and more consistent

  • All editors can deal with it properly

  • It's easier to maintain - you can edit values without breaking them because quotes are missing.

The few bytes you save in document size by dropping quotes where they are not needed are not worth mentioning (unless maybe you're Google's home page).