Search code examples
htmlxhtmlsgml

quoting HTML attribute values


I know the spec allows both ' and " as delimiters for attribute values, and I also know it's a good practice to always quote.

However I consider " being the cleaner way, maybe it's just me having grown up with C and C++' syntax.

What is the cleanest way of quoting attribute values and why? Please no subjective answers.


Solution

  • Both are fine, but Double quotes are better (IMHO) as you reduce the risk of dynamic values causing errors. e.g.

    <input value='${lastName}'/>
    
    <input value='O'Graddy'/>
                    ^^^^^^^
    

    vs.

    <input value="${lastName}"/>
    
    <input value="O'Graddy"/>