Stuff & Nonsense Home

Where you’ll find designer, author and speaker Andy Clarke. The bastard.

Blogging And All That Malarkey

Improve your web typography with baseline shift

The baseline is an invisible line onto which all type characters sit, although of course some characters (including ‘j’, ‘p’, ‘g’ and ‘y’) have descenders that hang below the baseline. Baseline shift involves moving characters up or down in relation to the baseline and using it effectively can make a huge difference to the professional look of your type. Although baseline shift has traditionally been a part of using tools like InDesign or Quark, there are ways to accomplish the same results using today’s CSS

Baseline shift is a great tool for fine-tuning your typography. Try using it to:

  • create fractions manually. Use baseline shift to raise the numerator in diagonal fractions
  • optically position symbols, such as register, copyright and trademark (®, © and ®).
  • adjust the position of bullets, ornaments and other font-based graphics
  • be expressive with type by raising and lowering individual characters to create a jumpy, jittery effect
  • tweak the position of parenthesis, braces and brackets relative to the type they enclose

(Source)

Baseline shift using CSS

If you find yourself with a lost weekend, or your sleeping tablets aren’t working, the W3C has a (seemingly) forgotten Working Draft that deals with baseline shift (and other things) — CSS3 module: line — edited, in part, by Eric Meyer.

The contents of that CSS3 Working Draft might one day make it to a screen near you, but why wait to improve your typography when you can shift your baselines now using CSS2.1? Let’s take a look at one or two practical examples.

Has it ever bothered you that when you set your text large, parenthesis hang below the baseline and sometimes collide with the stroke of an uppercase character? That is because parentheses work best with lowercase characters and not so well will uppercase or numerals in, for example, telephone numbers. Don't worry, CSS2.1 can help you fix that.

Unfortunately there is no shortcut to selecting those parenthesis, so I wrap a span element around each one.

<h2>Blog: 
<span class="parenthesis">(</span>
And All That Malarkey 
<span class="parenthesis">)</span>
</h2>

Relative positioning is the perfect choice for shifting characters from the baseline, first by applying a generic parenthesis class (in which I've also slightly reduced the font-size of the parentheses:

.parenthesis {
position : relative;
font-size : 88%; }

Then specific descendent selectors to vary the baseline shift for each specific instance:

h2 .parenthesis {
top : -.15em; }

Here is the before and after. You can see the effect in action on the For A Beautiful Web home page.

Before baseline shift (top), after top : -.15em (bottom)

You can use the same technique for parentheses around parts of telephone numbers:


<div class="tel">
<span class="parenthesis">(</span>
01745
<span class="parenthesis">)</span>
851848
</div>
.tel .parenthesis {
top : -.15em; }

Before baseline shift (top), after top : -.15em (bottom)

Has it bugged you that when you separate parts of a number with an endash, that the dash sits a little too close to the baseline. Not to worry.

<div class="tel">
<span class="parenthesis">(</span>
01745
<span class="parenthesis">)</span> 
851
<span class="ndash">–</span>
848
</div>

.ndash {
position : relative;
top : -.1em; }

Here is the before and after:

Before baseline shift (top), after top : -.1em (bottom)

On the For A Beautiful Web home page I also decided to use baseline shift to add a little spice to the blog entry’s publication dates. Here is my baseline enhanced markup and CSS:

<abbr class="updated published">27
<span class="shift">th</span>
Apr 2009</abbr>

.shift {
position : relative;
font-size : 68%;  }

.updated .shift {
top : -.5em; }

Before baseline shift (top), after top : -.5em (bottom)

There seems to be no recipe for a correct amount of shift so it’s a matter of judgement and a job for the eye (yes engineers, I know you can’t handle that — tough luck. Get a designer to do it for you). When the position looks right, it is right.

Small details can make a big difference in fine typography. Start shifting your baselines.

Leave your comment

Benjamin D.C.

May 8 2009 @ 12:04am #

Very subtle, I like it :)

Jonathan Snook

May 8 2009 @ 12:04am #

Your solution for superscript TH is a pertinent one as use of SUP or SUB often disrupt the leading—a personal frustration of mine. Nice tip, for sure.

Owen

May 8 2009 @ 12:12am #

I have to disagree with you in the case of parentheses. I think these look a lot better when each parenthesis hangs below the baseline, even with caps. More important is the spacing between the parentheses and what they contain. Quite often the content is too closely bracketed and requires more space. This can be achieved using CSS in the same manner as you describe, but adding a little bit of padding or letter-spacing to the <span> containing each parenthesis. Obviously the opening parenthesis will require spacing on the right, and the closing parenthesis on the left.

You’re spot on with the en dash, though you have to be careful that it doesn’t end up looking too much like a minus symbol. And I guess your example on the dates looks better than, and avoids, the presentational <sup> element.

Experimenting with the baseline is certainly an interesting approach to refining typographic detail online.

Tim Wright

May 8 2009 @ 12:20am #

I’m gonna have to disagree with most of this stuff. It all appears to be presentational markup.

Andy Clarke

May 8 2009 @ 12:25am #

Tim Wright: We’ll have to agree to disagree on that one.

Owen Gregory: I might have to get all Sir Alan Sugar on you… ;)

Amy

May 8 2009 @ 12:35am #

Very nice, yet subtle effects here. The <sup> element would seem more appropriate for an upward “shift” but IE6 and 7 would require some extra styling.

Si Jobling

May 8 2009 @ 12:42am #

Useful tip for altering the baseline of text but I have to agree with Owen on the parenthisis - for me, I prefer the bracket to hang below the baseline to properly wrap the text (although there could be clashes when the parenthesis is directly next to a character with a descender).

I’m sure you were just using the specified class names for examples with regards to the “presentational” markup - surely the <sup> replacement on the date example would be better named “suffix” for the purists out there.

Owen

May 8 2009 @ 12:50am #

@Si Jobling - although there could be clashes when the parenthesis is directly next to a character with a descender - Hence the need for spacing, rather than baseline shift.

Antoine E Butler SR

May 8 2009 @ 01:11am #

nice. Love the “th” example as using <sup> doesn’t make much sense to me. Not sure if semantically inocorrect or not, but rings so for me.

Vladimir Carrer

May 8 2009 @ 02:37am #

Thank you for the tip!

Sam Wieck

May 8 2009 @ 05:28am #

While I think it’s generally positive that people are wary of presentational mark-up. I also think what we do is presentation. I think presentational mark-up is more than acceptable in small amounts: where a heuristic solution provides the refinement that help a site make a subtle shift from really good to really great is a prime example of that.

Joe Clark

May 8 2009 @ 01:27pm #

I really can’t support this. Leave the placement of marks to the type designer. Use real fraction characters, not fake ones. I see nothing in favour of this plan.

Yannick De Smet

May 12 2009 @ 12:26am #

Nice idea. I never thought of it.

E.T.Cook

May 12 2009 @ 06:15am #

Superfluous at best, destructive at worst.  I have to respectfully disagree, especially with regards to parenthesis.

Commenting is not available in this channel entry.
Hardboiled Web Design

Hardboiled Web Design by Andy Clarke

How the latest technologies and techniques will make your websites more creative, flexible and adaptable. Get hardboiled in all formats from Five Simple Steps. Digital formats also available at Amazon.com, Amazon.co.uk and the iBooks store.

We’ve deconstructed this site to focus on content while we restyle. Expect wonkiness during the transition.