Most of the time you can use single quotes for things. But I just noticed that you can use them for id's as well. Does this work everywhere and is it valid?
| SitePoint Sponsor |
Most of the time you can use single quotes for things. But I just noticed that you can use them for id's as well. Does this work everywhere and is it valid?


Yes, it's valid, but personally, I'd stick with double quotes. It's clearer, and I'd say keep single quotes for other languages like JS and PHP. Consistency is the key.

According to a thread we had here 11 years ago (and no, I wasn't around then either!) – XHTML: single quotes or double quotes – it's perfectly valid to use single quotes when quoting attribute values. ID is no different to any other attribute, you can use single quotes there – the only time you are likely to run into trouble is if the attribute value contains a single quote/apostrophe character, and it will then be taken as the end of the attribute value, so you would need to use double quotes in those cases, or escape the single quote/apostrophe using a NCR/entity.
Any posts I write in Arial are on my mobile phone, so please excuse typos etc.
Any posts I write in Verdana are on a PC, so feel free to berate me mercilessly for any mistakes


Like mentioned; if double quotes appear in an attribute value, you should use single quotes to quote the value; if single quotes appear in an attribute value, you should use double quotes to quote the value. For example: <img src="example.png" alt="Robert's picture" /> Basically be constant: http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 Obviously within XHTML all attribute values must be quoted.
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?





In examples like Robert's, I tend to like to use character entities, so's I can keepses mah preferred quoteses.
huh and the forums eatses mah entities. ’ + ;Code:alt="Robert’s picture"


Use NCR and Hex cat... ’ and it won't get eaten by vBulletin. >;-)
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?




Using hex NCR is still better though regardless. NCR is the preferable choice over the entities, entities are limited to a subset of Unicode characters, NCR can specify any character and theoretically Hexadecimal has less ambiguity. >;-)
};-) http://www.xhtmlcoder.com/
Thinking Web: Voices of the Community
> March 2013 - SitePoint forums: Spot the Error 3: Calling all Sleuths! Winner Announced!... She knows how to spot simple <code> errors but do you?





I only use ncr's.
Bookmarks