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.
When using PHP to generate HTML it can be easier to do something like:
than concatenating a string with a variable with a string, as PHP parses variables in double-quoted strings.
Single quotes generate a cleaner page with less clutter. You shouldn't be escaping them in HTML strings and it's your choice which to use... my preference is single quotes normally and if I need to include a single quote in the string (e.g. as delimiters for a string inside the string), I use double quotes for one & single for the other.
In PHP, echo takes multiples parameters. So, if one would like to omit the concatenation operator, they could done something like and still use double quotes :
I find using single quotes is handy when dynamically generating HTML using a programming language that uses double quote string literals.
e.g.
Another case where you may want to use single quotes: Storing JSON data in data attributes:
JSON object keys must be in double quotes, so the attribute itself cannot.
Why not save pressing the SHIFT Key. One less keystroke for the same milage.