Typography

for Developers

Ben Scott / @BPScott

Who?

  • Web Developer @ bbc.co.uk/programmes
  • Not a natural visual designer
  • Trying not to use that as an excuse
95% of the information on the web is written language. It is only logical to say that a web designer should get good training in the main discipline of shaping written information, in other words: Typography.
Oliver Reichenstein

Two Disciplines

Creative Typography

Technical Typography

CSS


    body {
      font-size: 16px;
      line-height: 1.5;
    }

    p {
      margin-bottom: 24px;
    }
  

Technical Typography

Rhythm

Ratios

Rhythm

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Dummy Text

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Line-Height

  • Usually between 1.2 and 1.8
  • Larger text needs a smaller line-height
  • Larger x-height needs a larger line-height

Ratios

Ratios

Ratios

Modular Scale

Base font-size: 16px. Ratio: 1:1.5

SizeCalculated By
7.111px10.667px / 1.5
10.667px16px / 1.5
16px-
24px16px * 1.5
36px24px * 1.5
54px36px * 1.5

Modular Scale

Base font-size: 16px. Ratio: 1:1.5

SizeCalculated By
7.111px16px * (1.5 ^ -2)
10.667px16px * (1.5 ^ -1)
16px16px * (1.5 ^ 0)
24px16px * (1.5 ^ 1)
36px16px * (1.5 ^ 2)
54px16px * (1.5 ^ 3)

Modular Scale

7.111px - 16px * (1.5 ^ -2)

10.667px - 16px * (1.5 ^ -1)

16px - 16px * (1.5 ^ 0)

24px - 16px * (1.5 ^ 1)

36px - 16px * (1.5 ^ 2)

54px - 16px * (1.5 ^ 3)

81px - 16px * (1.5 ^ 4)

Bringing it all together

GridLover.net

Sass

Sassy Default Variables


    $base-font-size: 16px !default;
    $base-line-height: 1.5 !default;
    $ratio: 1.5 !default; // Perfect Fifth
    $round-pixels: true !default;
  

Sassy Vertical Rhythm


@function rhythm($multiplier: 1,
                 $base-font-size: $base-font-size,
                 $base-line-height: $base-line-height) {
  @return $multiplier * $base-font-size * $base-line-height;
}
  

Sassy Modular Scale


  @function modular-scale($offset,
                          $base-font-size: $base-font-size,
                          $ratio: $ratio,
                          $round-pixels: $round-pixels) {
  @if $round-pixels == true {
    @return round($base-font-size * pow($ratio, $offset));
  }

  @return $base-font-size * pow($ratio, $offset);
}
  

Sassy Basic Usage


html {
  font-family: 'Open Sans', sans-serif;
  font-size: $base-font-size;
  line-height: $base-line-height;
  text-rendering: optimizeLegibility;
}

p, ul, ol {
  margin: 0 0 rhythm(1) 0;
}

ul, ol {
  padding-left: $base-font-size * 2.5;
}
  

Sassy Headings


h1 {
  font-size: modular-scale(3); // 16px * 1.5^3 = 54px
  line-height: (rhythm(3) / modular-scale(3)); // 72px / 54px = 1.33
}

h2 {
  font-size: modular-scale(2); // 16px * 1.5^2 = 36px
  line-height: (rhythm(2) / modular-scale(2)); // 48px / 36px = 1.33
}

h3 {
  font-size: modular-scale(1); // 16px * 1.5^1 = 24px
  line-height: (rhythm(2) / modular-scale(1)); // 48px / 24px = 2
}
  

Sassy Headings


h1 {
  font-size: 54px;
  line-height: 1.33333;
}


h2 {
  font-size: 36px;
  line-height: 1.33333;
}

h3 {
  font-size: 24px;
  line-height: 2;
}
  

Rems

  • Relative measurements
  • A better fit for responsive thinking
  • Progressive enhancement

html {
  font-size: 16px;
  font-size: 1rem;
}
  

Sassy REMs


@mixin rem($property, $px-values, $baseline-px: $base-font-size) {
  $baseline-rem: $baseline-px / 1rem;
  $rem-values: ();

  @each $value in $px-values {
    $rem-values: append($rem-values,
      if($value == 0, $value, $value / $baseline-rem));
  }

  #{$property}: $px-values;
  #{$property}: $rem-values;
}
  

Sassy Headings (Redux)


h1 {
  @include rem('font-size', modular-scale(3));
  line-height: (rhythm(3) / modular-scale(3));
}

h2 {
  @include rem('font-size', modular-scale(2));
  line-height: (rhythm(2) / modular-scale(2));
}

h3 {
  @include rem('font-size', modular-scale(1));
  line-height: (rhythm(2) / modular-scale(1));
}
  

Sassy Headings (Redux)


h1 {
  font-size: 54px;
  font-size: 3.375rem;
  line-height: 1.33333;
}

h2 {
  font-size: 36px;
  font-size: 2.25rem;
  line-height: 1.33333;
}

h3 {
  font-size: 24px;
  font-size: 1.5rem;
  line-height: 2;
}
  

TL;DR

  • Universal guidelines exist
  • They're pretty easy to use
  • Computers are good at math
  • A designer's eye always wins

Link Dump

Thank You

Any Questions?

Ben Scott / @BPScott

reload.me.uk/talk-typography-for-developers