Why shouldn't '
be used to escape single quotes?
When it comes to HTML escaping, stick with '
for single quotes as '
is not universally supported. Observe this quick substitution:
flips to
The outcome is, as you guessed it: It's a great day!
Diving into quote escapement
HTML provides a set of character references to objectify special characters or those that are elusive in HTML representation. Safer choices are numeric entities - '
for single quotes (apostrophe) and "
for double quotes.
Picking the appropriate quote entity
While HTML5 deems '
as valid, retaining legacy support (HTML 4 and XHTML) calls for named entities ‘
and ’
for left and right single curved quotes respectively. Double quotes can enjoy “
and ”
.
Coding semantically with quotes
For semantic correctness, <q>
tags are used to symbolize short quotations which by default, will get rendered with suitable quotation marks by browsers.
Escaping quotes in older browsers
A noteworthy kiey point to remember is to confirm the compatibility of various escape sequences. It's possible some ancient browsers will not recognize '
, hence '
assures maximum compatibility.
Styling quotes with CSS
Leverage the power of CSS to handle quotation marks in your content - the quotes
property can be your go-to tool for multilingual typesetting of quotations with varying quotation marks.
Encoding curly single quotes
There are times when you need to embed curly single quotes into your HTML. Turn to ‘
for left curly single quotes or opening apostrophes and ’
for right curly single quotes or closing apostrophes.
XML vs HTML: their relation
Named character references significantly impact XML applications. Here, '
plays a notable role, but carries a different understanding in HTML 4. Always stay updated with the relevant specification (HTML vs XML) to avoid unusual outcomes.
Compatibility caution with XHTML
If XHTML is a part of your project, take note of Wikipedia's caution to abstain from using '
. As XHTML is an application of XML, but often served with MIME type text/html
, potential confusion or compatibility issues may arise.
Was this article helpful?