The Ultimate Guide to CSS Typography

39

by Shane Jeffers

Typography is often overlooked in todays design specifically by web developers. It really is a shame because CSS gives us so much control over our type. That being said, we our limited to certain “web safe” typefaces but that shouldn’t decrease our creativity. Here are a few CSS tips for typography on the web.

The Font Attribute

CSS provides us with the Font attribute, which is what allows us to tweak the text on our page. This is an overview of the syntax and how to effect text using CSS.

Font-size

Change the size of your font using font-size

     font-size: 1.2em;
     font-size: 12px;
     font-size: 10pt;
Live Preview
  1. Font size is set to 1.2em.
  2. Font size is set to 12px.
  3. Font size is set to 10pt.

Font-weight

This is used to change the weight of your font (i.e bold, bolder)

     font-weight: normal;
     font-weight: bold;
     font-weight: bolder;
     font-weight: lighter;
Live Preview
  1. Font weight is set to normal
  2. Font weight is set to bold
  3. Font weight is set to bolder
  4. Font weight is set to lighter

Text-transform

The text-transform property allows you to apply uppercase, lowercase, and capitalize effects to your text.

     text-transform: capitalize;
     text-transform: uppercase;
     text-transform: lowercase;
     text-transform: inherit;
Live Preview
  1. Capitalizes the first letter in every word
  2. Allows your html to be lower case the converts it all to uppercase characters
  3. ALLOWS YOUR HTML TO BE UPPERCASE THEN CONVERTS IT TO LOWERCASE, THIS WAS TYPED IN ALLCAPS
  4. inherits the text-transform property from its parent element

Text-decoration

The text-decoration property allows you to underline, overline and put a line through your text

     text-decoration: normal;
     text-decoration: underline;
     text-decoration: overline;
     text-decoration: line-through;
     text-decoration: blink; (DO NOT USE)
Live Preview
  1. Text decoration set to normal
  2. Text decoration set to underline
  3. Text decoration set to overline
  4. Text decoration set to line-through
  5. Text decoration set to blink ( Only works in Firefox and Opera )

Font-Variant

The Font variant property allows you to create the small-caps effect which capitalizes the letters then decreases the font size.

     font-variant: normal;
     font-variant: small-caps;
     font-variant: inherit;
Live Preview
  1. Font Variant set to normal
  2. Font Variant set to small-caps
  3. Font variant set to inherit

Creating Drop Caps

Creating drop caps is easy with CSS. There are multiple ways to create the drop cap effect but I am going to show the most efficient way. To create them use the :first-letter pseudo-element which only effects the first character of a given element.

<p class="dropcaps">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.</p>
p.dropcaps:first-letter {
      	font-size: 340%;
	margin: 8px 5px 0px 0px;
	float: left;
	font-weight: bold;
	width: 1em;
}

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Creating Attractive Paragraphs

For more attractive paragraphs use Robert Bringhurst’s method which states: Take your font size and multiply it by 30 to get the width of your paragraphs.

For example if your font size is 12px, multiply it by 30 and you get 360px which should get you approximately 65 characters per line.

Incorrect Measure

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Correct Measure

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Line-height Examples

Line height dictates the amount of space in between each line of text. A good rule of thumb is to make the line height 6-7px bigger than your font-size.

For example if your font size is 12px, add 6px to the font size and you get your line height, which would be 18px.

Incorrect Line-Height

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Correct Line-Height

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Cleanly Emphasize Text

Underlines should only be used on text that is linking to something or somewhere. Italicizing text is a cleaner alternative.

Incorrect example

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Correct example

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

Looking forward – CSS3

There are already some exciting features that you can incorporate into your designs dealing with type in CSS3. Of course some of these new features do not work in IE, but your probably used to nothing working in IE anyway so give these a shot.

@Font-face

@font-face allows you to upload a raw font file to your web server and link to it in your external CSS file, then apply it to any type on your site.

This feature is the biggest one dealing with type, but along with it’s upside comes its downside. There are only a few fonts that you are “allowed” to use because of licensing issues. The fonts that are CSS3 safe can be found here.

Usage of @font-face

In this example I put a folder in the root of my server called font. First you need to declare the @font-face attribute which imports your font file and then you can use the font name to effect any other elements.

/* Declaring the font */

@font-face {
      src: (font/diavlo.otf)
}

/* Applying the font to an element */

h1 {
      font-family:  diavlo, Arial;
}

Text-Shadow

The text shadow attribute takes away the need to create drop shadows for certain elements in photoshop and gives you dynamic drop shadow control. Of course this attribute is only supported in Safari, Chrome, Firefox and Opera.

Example Heading


p {
      font-size: 2em;
      font-weight: bold;
      color: #777;
      text-shadow: 1px 1px 1px #222;
}

Example Heading 2


p {
      text-shadow: 2px 2px 2px #222;
}

Example Heading 3


p {
      text-shadow: 1px 1px 5px #FFF;
}

The Challenge

The techniques in this article are just guidelines. Take them and implement the features you like into your web designs. Typography is extremely important and can absolutely ruin a beautiful design. Don’t let that happen to you bookmark this guide!

Written by Shane Jeffers

Shane Jeffers is the Creator and Author of Three Styles. He has a unique passion for design trends and tutorials. Reach him through the Contact page or follow him on twitter @ThreeStyles

Enjoy this post? Subscribe by RSS or Email


CSS, Tutorials

39 Responses to “The Ultimate Guide to CSS Typography”

  1. GravatarLiam McCabe Says:

    Some great tips Shane, thanks for the post :)
    Liam McCabe´s last blog ..Contact form or mailto link? My ComLuv Profile

  2. GravatarChris Thurman Says:

    A good overview. A few thoughts/questions:

    What do you use for font-size? I started out using pixels and then moved to ems because it was better for screen zooming but with full page zooming in most browsers, I’ve leaned back towards pixels.

    Text-decoration:blink should be banned from all browsers.

    I love the possibilities with CSS3 especially in the type arena. I’m using a little text shadow on my upcoming redesign. What is your favorite CSS3 text effect?
    Chris Thurman´s last blog ..Wet Logos: Showcase of Logo Designs Featuring Water My ComLuv Profile

  3. GravatarMurlu Says:

    This post is absolutely fantastic and a great reference – bookmarked.

    I really like the live examples and some of the common guidelines you cover.
    Murlu´s last blog ..The Beginner DJ Equipment Guide: Building Your First DJ Setup My ComLuv Profile

  4. GravatarLéo Says:

    Nice review, however I believe that there are three missing CSS elements (2 attribute, 1 selector) to make it “Ultimate” :

    - font-variant
    - letter-spacing
    - :first-letter (to create drop caps)
    Léo´s last blog ..8 conseils pour gagner jusqu’à 5 points de PageRank en quelques mois My ComLuv Profile

  5. GravatarTony Says:

    Sweeet. Great tutorial. I think I will even print this out for future reference.
    Tony´s last blog ..How to Track the Number of Clicks on Your Bit.ly Links on Twitter My ComLuv Profile

  6. GravatarJP Says:

    Nice guide man.
    I can’t wait for CSS3 to be more widely accepted! Imagine the day you wouldn’t have to worry anymore about Internet Explorer… ahh one can dream :D
    JP´s last blog ..10 Ways to Instantly Speed Up Your Website My ComLuv Profile

  7. Gravatarsquareart Says:

    Nice one, bookmarked for future reference.
    Thanks.

  8. GravatarThe Ultimate Guide to CSS Typography | Design Newz Says:

    [...] The Ultimate Guide to CSS Typography [...]

  9. GravatarInternet Brain » The Ultimate Guide to CSS Typography | Three Styles Says:

    [...] The Ultimate Guide to CSS Typography | Three Styles. [...]

  10. GravatarMissControlZ Says:

    I’m just entering the world of web development and I think this is a fantastic reference for manipulating font layout. I am really interested in @font-face and the ways it can be used. I blogged about it earlier this summer, so here’s another example as well as some visuals. http://www.monetspells.com/?p=218.

    Thanks for the reference sheet. I am definitely going to bookmark it!

  11. Gravatarcchana Says:

    Typography seems to be gaining a lot of momentum on the web, which is good and once css3 has been widely adopted, it will be a great tool to play with!

  12. GravatarMandi Says:

    Great!! Thanks so much for this :)

  13. Gravatarvocal Says:

    wonderful post, thanks for share.

    in fact, CSS3 can do more thing for typography. i agree with Leo says, and recommend the css3 multiple column.

  14. GravatarEditha Fuentes Says:

    Thanks Shane, what a great article!

  15. GravatarJay Kaushal Says:

    Great Tips Shane.

    These must be handy and kept as printed page for easy reference anytime. Great for a novice or a pro equally. I agree that CSS3 has many more attributes which are not in older version especially regarding images and typography.

    Keep up the good work :)

  16. Gravatarchris Says:

    Nice roundup but you made a little mistake:
    The copy text of the “Text decoration” paragraph is the same as in the “Text transform” paragraph.

  17. GravatarThe Ultimate Guide to CSS Typography | Three Styles | Artful Pussycat Says:

    [...] Read more @ The Ultimate Guide to CSS Typography | Three Styles. [...]

  18. Gravatarlinks for 2010-01-17 Says:

    [...] The Ultimate Guide to CSS Typography Typography is often overlooked in todays design specifically by web developers. It really is a shame because CSS gives us so much control over our type. That being said, we our limited to certain “web safe” typefaces but that shouldn’t decrease our creativity. Here are a few CSS tips for typography on the web. (tags: typography css webdesign tips) [...]

  19. GravatarTop Tutorials Are Worth Seeing of the Week – #1 | AEXT.NET Says:

    [...] The Ultimate Guide to CSS Typography [...]

  20. Gravatardot Blog. The week in links 18/01/10 Says:

    [...] The ultimate guide to CSS typography (threestyles​.com) [...]

  21. GravatarSaptarshi Says:

    Great basic tutorial. Will keep coming back :)
    Saptarshi´s last blog ..Geek Google and Helvetica My ComLuv Profile

  22. Gravatarsiena Says:

    Very good article men.

  23. GravatarAnna Says:

    Hi,
    Nice article, but would not call it ultimate. You left quite a bit out of it.

  24. GravatarnFormas design Says:

    Nice guide!

  25. GravatarShane Jeffers Says:

    @Chris

    Currently my favorite is the text-shadow property, but @font-face is pretty exciting.

    @Leo

    I updated the article to include these properties! Thanks for the suggestions.

  26. GravatarJason Says:

    Great roundup of the font attributes and what they do.

    There area couple things missing. First off, learning the correct order in the shorthand method for ‘font’ is necessary.

    font: bold 11px/16px verdana, sans-serif;
    Font Weight
    Font Size
    Line Height
    Font Family

    And if you’re wanting the ‘ultimate’ guide, you have to talk about using ems instead of pixels or points for uniform display and scaling across browsers.

    This article is pretty much the gold standard:
    http://www.alistapart.com/articles/howtosizetextincss/
    Jason´s last blog ..Digging into Wordpress: Book Released My ComLuv Profile

  27. Gravatardcp3450 Says:

    Great article. Doing a full redesign of my company’s site and using the Correct Measure and Lineheight concepts for sure.

  28. GravatarTips and Advice for better Design « AIGA Aii-KC Student Group Says:

    [...] Ultimate Guide to CSS Typography: http://www.threestyles.com/tutorials/css-tips-for-better-typography/ Possibly related posts: (automatically generated)Sunline’s new exhaust is readySunline’s [...]

  29. GravatarVeezual Says:

    Nice and well-explained article. Made me look at the @font-face thing.

  30. GravatarWeekly Round - Up | Barry McGee Says:

    [...] Sam Horner sent me this very informative article on dealing typography using CSS. [...]

  31. GravatarSweet Tweets: Design Resources of the Week #32 Says:

    [...] The ultimate guide to CSS typography “Typography is often overlooked in todays design specifically by web developers. It really is a shame because CSS gives us so much control over our type. That being said, we our limited to certain “web safe” typefaces but that shouldn’t decrease our creativity. Here are a few CSS tips for typography on the web.” [...]

  32. Gravatarminyang Says:

    Thank you for this guide. This is really helpful to me.
    I’m Korean web designer. So I’m always concerned about Hangul typography.
    Hangul is little diffrent with English. But typography to deal with letters have a lot in common.
    Your articl is very good guide for web typography.

  33. GravatarLinks for January 17th, 2010 | BlogHalt.com (Pre-Launch) Says:

    [...] The Ultimate Guide to CSS Typography Typography is often overlooked in todays design specifically by web developers. It really is a shame because CSS gives us so much control over our type. That being said, we our limited to certain “web safe” typefaces but that shouldn’t decrease our creativity. Here are a few CSS tips for typography on the web. (tags: typography css webdesign tips) [...]

  34. GravatarCodesquid Says:

    This is a very nice little tutorial! Many of these techniques are sadly unknown or overlooked by so many designers. Bad typography can indeed ruin a site. I hate trying to read full-screen width text with not enough line-height. It ruins the usability and accessibility of a site.
    Codesquid´s last blog ..Usable and accessible web design for the iPad My ComLuv Profile

  35. GravatarAvangelist Says:

    @Chris Thurman,

    For many years now I have been using the percentage em reset concept for font sizing.

    This is done by setting the body{} font-size to 62.5%, the theory being that 1em = 10px. It was years ago I read about this so I have long forgotten where this is written but I am sure it is documented in many places.

    1em = 10px;
    1.2em = 12px;
    1.4em = 14px;

    and so on.

    This means you can use em to create scalable text but with more control over your understanding of what the size should be.

    This if course doesn’t factor the differing size in text at any given size. Most fonts appear bigger/smaller even when they’re set to the same size.

    verdana at 12px looks bigger than arial at 12px for example.

  36. GravatarGabe Casalett Says:

    Great Post! Thanks for sharing!

  37. Gravatararavind ajith Says:

    Wow! Great post. :)
    aravind ajith´s last blog ..Zexee: A Free Sexy WordPress Theme! My ComLuv Profile

  38. GravatarMes favoris du 20-02-10 au 21-02-10 » Gilles Toubiana Says:

    [...] The Ultimate Guide to CSS Typography | Three Styles [...]

  39. GravatarValerie Morgan Says:

    Great tips. I’m bookmarking this one right away!
    Thanks!

Leave a Reply

CommentLuv Enabled