Recently I've been seeing a lot of this:
<a href='http://widget-site-example.com/example.html'> <img src='http://widget-site-example.com/ross.jpg' alt='Ross's Widget' /> </a>
Is it valid to use single quotes in HTML? As I've highlighted above it's also problematic because you have to escape apostrophes.
The HTML specification says: Attributes are placed inside the start tag, and consist of a name and a value, separated by an = character. The attribute value can remain unquoted if it doesn't contain spaces or any of " ' ` = < or > . Otherwise, it has to be quoted using either single or double quotes.
The attribute value may only contain letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45), and periods (ASCII decimal 46). We recommend using quotation marks even when it is possible to eliminate them.
The attribute value can remain unquoted if it doesn't contain ASCII whitespace or any of " ' ` = < or >. Otherwise, it has to be quoted using either single or double quotes. The value, along with the "=" character, can be omitted altogether if the value is the empty string.
It's certainly valid to use single quotes (HTML 4.01, section 3.2.2). I haven't noticed such a trend, but perhaps there's some framework that powers web sites you've visited that happens to quote using single quotes.
I find using single quotes is handy when dynamically generating HTML using a programming language that uses double quote string literals.
e.g.
String.Format("<a href='{0}'>{1}</a>", Url, Desc)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With