Styling quotations

Posted on 23 August 2006 (02:51 PM)

I've always liked the way most standards-compliant browsers display inline quotations (marked up with <q>). In case you don't have such a browser at your disposal; it's an easy concept to grasp, these browsers put quotation-marks around the text like this:

A picture of how inline quotations look in standards-compliant browsers
Warning: the technique described in this article should not be used. Make sure to read my edit.

Internet Explorer however, does not use this default styling. But since you probably want quotation marks around your quotations, you've got two options:

  1. Insert the quotes yourself like this:
    <q>
    " To be or not to be. "
    </q>
  2. Don't bother about semantics and use different markup.

Since I'm advocating accessible coding in my articles, option 2 is out of the question. Semantic markup really helps assistive devices, so it shouldn't be abandoned.

Option 1 however, looks allright in Internet Explorer, but in most other browsers you end up with a double set of quotation marks, like this:

A picture showing the awkward double set of quotation marks in standards-compliant browsers

That just looks plain silly. Luckily, this is easy to overcome using the following CSS:

  1. q:before,
  2. q:after {
  3. content: "";
  4. }
  5. Download this code: /code/styling_quotations1.txt

And that's that. IE won't understand the :before and :after pseudo-selectors, more advanced browsers will cut the default quotation marks off. It's a small problem, with an easy solution, but tiny details like this can really be a finishing touch.

Edit: turns out I was wrong

As pointed out to me in the comments, the W3C certainly has a different opinion on the matter. Explorer is wrong and this time it isn't the author's job to rectify their mistake. Related reading, as provided by Sébastien Guillon:

Back to top

Filed under HTML and CSS

Comments:

  1. 27 August 2006 (03:02 AM) by Sébastien Guillon

    Option 1 is not acceptable according to the HTML spec (see:

    http://www.w3.o...xt.HTML#h-9.2.2 ) :

    "Visual user agents must ensure that the content of the Q element is rendered with delimiting quotation marks." So Internet Explorer IS failing.

    "Authors should not put quotation marks at the beginning and end of the content of a Q element." But it seems your option is also incorrect. So if you add quotation marks manually you shouldn't enclose the text in Q tags."

    Related:

    http://acjs.net...marks/index.PHP

    http://sebastie...francais-en-CSS (in French)

    this comment has been quoted by Harmen Janssen

  2. 28 December 2006 (12:09 AM) by Harmen Janssen

    Sébastien Guillon wrote:

    Option 1 is not acceptable according to the HTML spec (see:

    http://www.w3.org/TR/html4/struct/text.html#h-9.2.2 ) :

    "Visual user agents must ensure that the content of the Q element is rendered with delimiting quotation marks." So Internet Explorer IS failing.

    "Authors should not put quotation marks at the beginning and end of the content of a Q element." But it seems your option is also incorrect. So if you add quotation marks manually you shouldn't enclose the text in Q tags."

    Related:

    http://acjs.net/weblog/2005/06/10/language_specific_styling_quotation_marks/index.php

    http://sebastienguillon.com/journal/2005/07/guillemets-francais-en-css (in French)

    Thanks a lot, Sebastien, I wasn''t exactly sure what my solution would do to accessibility.

    Too bad though, if this means developers should just stay away from the q-tag.

Leave a comment

RE: Styling quotations

Note to spammers: rel="nofollow" will be added to links. If I consider your comment spam, your IP-address might get blocked.

HTML not allowed. URLS will be auto-linked. Maximum length is 1250 characters.

I understand this is inconvenient, but the spam I'm receiving on this website is driving me nuts. Please forgive me and cope with it until I find a better solution.

Mandatory fields are marked by an asterisk (*).

Increase textarea-size Decrease textarea-size

Back to top

Preferences

These settings will be saved for your convenience.