Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

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

vs.

<input value="${lastName}"/>

<input value="O'Graddy"/>

Solution 2:

There’s a lot of rules to remember if you want to omit quotes around attribute values. It’s probably easiest to just use quotes consistently; it avoids all kinds of problems.

If you’re interested, I did some research on unquoted attribute values in HTML, CSS and JavaScript a while ago, and wrote about it here: http://mathiasbynens.be/notes/unquoted-attribute-values

I’ve also created a tool that will tell you if a value you enter is a valid unquoted attribute value or not: http://mothereffingunquotedattributes.com/#foo%7Cbar

Solution 3:

Either is good, as long as you use it. " is more popular.

Post a Comment for "Quoting Html Attribute Values"