2

I was checking the view source of the site http://mothereffinghsl.com/ . It was coded by Paul Irish

In the code the id of the html elements are not enclosed in quotes for few elements. For other elements the id is enclosed in quotes. Is this a good practice. Is it a mistake or purposefully omitted? I dont think a person like Paul has overlooked it.

<div id="main" role="main">
<h1>Mother-effing <span>hsl()</span></h1>
<canvas width=360 height=100><a href="http://noyoueatabagofdicks.com/">your browser doesnt support canvas.</a></canvas>
<span id=loading>one sec, bro.</span>
<label id=sat>Saturation</label>

What are your thoughts?

Edited after accepting the answer

Conclusion:

In html5 quotes are not necessary, but recommend for reasons mentioned in the comments.

Also its NOT a good practice to use quotes for some attributes and not for some other even though it is supported.

kiranvj
  • 32,342
  • 7
  • 71
  • 76

2 Answers2

7

From the article Why attribute values should always be quoted in HTML

There are several reasons to use quotes around attribute values always:

  • It's easier, since you need not memorize and recall the rules for allowable omission.
  • In XML, quotes are always required (since XML has SHORTTAG NO; see Comparison of SGML and XML). You may use XML in the future, and in that case your life will be simpler if you have adopted the habit of quoting attribute values.
  • When someone (you or someone else) later edits your HTML file, he may easily forget to add the quotes if he edits an attribute value in manner which makes the quotes mandatory. For example, an attribute like SRC=foo.gif is legal, but if someone changes the attribute (e.g. due to moving a file to another directory) to SRC=images/foo.gif it becomes illegal.

So, I'd say it's not the best of practices to omit quotes.

KooiInc
  • 119,216
  • 31
  • 141
  • 177
  • Adding a `/` character does not make an attribute value require quotes. Whitespace, quotes, `<`, `>`, and `=` do however. – Pointy Feb 04 '13 at 17:11
1

He's using HTML5. Attribute quotes are optional in HTML5 (and HTML 4, just not in XHTML). See Do you quote HTML5 attributes? and http://mathiasbynens.be/notes/unquoted-attribute-values (that second link references Paul Irish BTW!)

Community
  • 1
  • 1
duncan
  • 31,401
  • 13
  • 78
  • 99
  • 1
    Even then also it should be consistent across the page no? Its not a good practise to use quotes for some elements and not for other elements, right? – kiranvj Jun 27 '12 at 06:52
  • 1
    Consistency is good but TBH I don't think it really matters here, any more than if he'd used double quotes for some attributes and single quotes for others – duncan Jun 27 '12 at 07:49