Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate CSS letter-spacing v.s. "tracking" in typography?

Tags:

html

css

I have instructions from a graphic designer for a layout that specifies "track 100" for some elements. In CSS letter-spacing is the equivalent property for "tracking".

Given a value for tracking, how do you express this as a value for CSS in pixels?

like image 712
Diodeus - James MacFarlane Avatar asked May 03 '10 19:05

Diodeus - James MacFarlane


People also ask

Is tracking same as letter-spacing?

What is letter-spacing / Tracking? Tracking is the typographer's term for letter-spacing. Sometimes confused with kerning (which is used to adjust spacing between individual letters), tracking adjusts the letter-spacing uniformly over a range of characters.

What is the difference between tracking and kerning in typography?

Tracking is sometimes confused for kerning, but it's actually quite different. Where kerning involves the spacing between two letters, tracking involves the spacing throughout the entire word.

What is letter-spacing in typography?

Letterspacing (also known as character spacing or tracking ) is the adjustment of the horizontal white space between the letters in a block of text. Unlike kerning, which affects only designated pairs of letters, letterspacing affects every pair.


2 Answers

Do you have to use pixels? The conversions I found is a tracking value of 1000 is equal to 1 em in CSS, so in your case tracking 100 should be 0.1 em.

EDIT

To go from EM to pixels use this site PXtoEM.com. For your specific case 0.1 em converts to 2px. However this is based on a 16pt font, so you will have to adjust for the specific font size you're using.

like image 159
Alex Larzelere Avatar answered Sep 22 '22 10:09

Alex Larzelere


TL;DR: divide the tracking by 1000 and use em's


A bit of background about letter-spacing is always applied to text so we should use a relative unit of length. As font-size can change by the user or even by cascade.

The best unit of length for text is the em unit.

This unit represents the calculated font-size of the element. If used on the font-size property itself, it represents the inherited font-size of the element. CSS Lengths - Mozilla Developer Network

Why is tracking different?

Layout apps such as Adobe's Photoshop, Illustrator and InDesign use em's in their tracking but manipulate the unit so it's an easier number for designers to play with. To make it easier they times it by 1000.

Indesign Tooltip: Tracking (in thousandths of an em

Converting tracking back to whole em's

To do this we just need to divide the tracking number by 1000 to get the unit back to a whole em that CSS can use.

So 50/1000 = 0.05em.

Calculating this in CSS/SCSS

If you are using SCSS and want a reusable solution - here is a mixin.

// Convert illustrator, indesign and photoshop tracking into letter spacing.  @function tracking( $target ){   @return ($target / 1000) * 1em; }  @mixin tracking( $target ){   letter-spacing: tracking( $target ); } 

To use the above functions you can just do this.

.example {   @include tracking(50); } 

Alternatively you can just to the maths inline without a mixin so it's less abstracted:

.example{   letter-spacing: #{(50/1000)}em; } 

The output for the above examples will be:

.example {   letter-spacing: 0.05em; } 

Note: You should not use a pixel based value as pixels are fixed and break when:

  1. The designer changes the font-size. You would need to recalculate the value.

  2. If the user changes their text size your sites design won't appear as desired or even illegible to read.

Additionally browsers render text different to how the graphic design programs do so don't be surprised if the designer tweaks the tracking/letter-spacing on review of the implementation.

like image 32
jnowland Avatar answered Sep 22 '22 10:09

jnowland