Hanging Punctuation With CSS

Sponsored Ad

psd 2 xhtml/css advert

Hanging Punctuation refers to the technique of positioning certain typographical elements, such as bullets, quotation marks on pull quotes, etc. into the margin of a document, so that the main text that the glyph highlights remains flush with the rest of the body copy around it. Often seen in print, rarely used on the web, hanging punctuations can help keep the flow of your document and make the text easier to read.

Devising a cross-browser solution can be tricky, particularly with regards to lists. I've come up with a solution below that works in IE6/7, FireFox, Opera 9 and Safari.

First, let's look at hanging punctuation on block quotes, which is by far the easier of the two.

As you can see below, the image on the left shows a block quote without hanging punctuation (the red line signifies the margin in both images). The diagram on the right illustrats the quote with the punctuation hung in the left margin:
CSS Techniques - Hanging Punctuations Fig. 1

Accomplishing this with CSS is simple. All we have to do is apply a negative text indent, so that the quotation mark is moved over into the margin. I can't take credit for this one. I've seen it several places on the web. I'm just re-posting it here, because blockquotes should be hung and it goes along with the CSS to hang lists (which I haven't personally seen elsewhere).

CSS:
  1. blockquote {
  2.     text-indent:-0.5em;
  3. }

Now let's move on to lists, where things get a little trickier.

Again, let's look at an example of a "unhung" list vs. a "hung" list.
CSS Techniques - Hanging Punctuations Fig. 2

For the list to hang properly in Firefox, we need to do away with its default left margin.

Finally, to make this work properly in IE6, we need to manually set the left padding, and then relatively position it to the left of the margin. The left padding that we manually set is also going to get us working in Opera.

CSS:
  1. ol {
  2.     margin-left:0;
  3.     padding-left:1.5em;
  4.     position:relative;
  5.     left:-1.5em;
  6. }

You can view the finished example here.

8 Total TweetBacks: (Tweet this post)
  • : Disfraces en la ofi! http://tr.im/DDK1 10/31/09 05:20am
  • en: I got Type. A Visual History of Typefaces & Graphic Styles, 1628-1900 for my birthday and it is an excellent book. http://tr.im/DdK1 10/27/09 08:03pm
  • sv: Familjens stora begåvning har fått mycket fint pris för "Flickvännen"! http://tr.im/Ddk1 10/27/09 07:00pm
  • en: We are adding some videos!!! http://www.youtube.com/bigbrothersuperpass 07/15/09 01:42am
  • es: Popularidad en lenguajes de programación, estoy mas de acuerdo con http://langpop.com/ que con http://tinyurl.com/3xutoh .. que dicen? 07/15/09 12:20am
  • en: interesting - July 2009 TIOBE Headline: #Objective-C on its way to top 20 thanks to success #iPhone - http://tinyurl.com/3xutoh 07/14/09 08:07am
  • en: @ManningBooks no preference really. mostly curiosity. #php is still a bit more popular accdg to #TIOBE - http://tinyurl.com/3xutoh 07/14/09 08:06am
  • FredRivett: How to ~ Hang the Punctuation :: http://tinyurl.com/d6nf65 03/20/09 11:12pm

4 Responses to “Hanging Punctuation With CSS”

Posted by: Chris Hanson on May 30th, 2007 at 8:20 pm

nice tut it was intresting lol keep them coming they usefull to everyone especially people who have been in the game for years!

Posted by: Daniel Aleksandersen on June 27th, 2007 at 11:30 pm

Thanks! I have been looking for a way to do hanging quotes and bullets for some time. You method is really neat.

Posted by: web designer roxy on August 19th, 2007 at 5:01 pm

Thanks for the awesome tutorial...its really very helpful !!

Posted by: tasuki on February 17th, 2008 at 10:37 am

Great trick to make it work in IE6 and IE7 - thanks!



Make Your Mark

Allowed HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting