A place to cache linked articles (think custom and personal wayback machine)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.md 36KB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. title: A Responsive Guide to Type Sizing
  2. url: http://blog.cloudfour.com/responsive-guide-to-type-sizing/
  3. hash_url: 9ff37a890e93f6f4d5a1bbb30657ff0d
  4. <p>When starting new projects, a CSS builder&#8217;s initial concerns tend to involve typography. Setting a typographic foundation with the right mixture of ingredients can form something solid enough to support many other building blocks of design. It&#8217;s an approach that makes structural sense.</p>
  5. <p><em>Proportions</em> are a key ingredient to the mixture. Calibrating your type proportions for a balance of aesthetics and order can be an obsessive undertaking. It’s a challenge getting proportions right for a given screen size, let alone <em>any possible</em> screen size. This process can be less challenging &#8212; even for responsive designs &#8212; if you use a <em>modular scale</em> and let math do the work for you.</p>
  6. <h3>Using a modular scale for typographic proportions</h3>
  7. <p>In his <a href="http://alistapart.com/article/more-meaningful-typography">detailed article</a> on the subject, Tim Brown demonstrates using a modular scale for composing type. He explains how compositions can benefit from using numbers that relate to each other in a meaningful way:</p>
  8. <blockquote><p>Modular scales[&#8230;] help us achieve a visual harmony not found in compositions that use arbitrary, conventional, or easily divisible numbers.</p></blockquote>
  9. <p>This <em>modulation-based</em> approach is particularly useful for determining type sizes. Selecting sizes using a ratio (instead of guessing) yields a more harmonious range of proportions.</p>
  10. <p>With tools like <a href="http://www.modularscale.com">this indispensable calculator</a>, you can see how different <em>bases</em> and <em>ratios</em> affect your scale. These are the variables in your scale&#8217;s equation. The value produced by multiplying or dividing these variables is a <em>step</em> on your scale. Repeating the operation on each resulting value forms a new step:</p>
  11. <figure style="margin:1em 0; text-align:center">
  12. <table style="display:table; width:100%; table-layout:fixed">
  13. <thead>
  14. <tr>
  15. <th style="text-align:center">Step</th>
  16. <th style="text-align:center">Math</th>
  17. <th style="text-align:center">Result</th>
  18. </tr>
  19. </thead>
  20. <tbody style="font:1em 'source code pro',monospace">
  21. <tr>
  22. <td>+3</td>
  23. <td>&nbsp;40 × 2</td>
  24. <td>80&nbsp;&nbsp;&nbsp;</td>
  25. </tr>
  26. <tr>
  27. <td>+2</td>
  28. <td>&nbsp;20 × 2</td>
  29. <td>40&nbsp;&nbsp;&nbsp;</td>
  30. </tr>
  31. <tr>
  32. <td>+1</td>
  33. <td>&nbsp;10 × 2</td>
  34. <td>20&nbsp;&nbsp;&nbsp;</td>
  35. </tr>
  36. <tr style="opacity:.5">
  37. <td>&nbsp;0</td>
  38. <td>&nbsp;none</td>
  39. <td>10&nbsp;&nbsp;&nbsp;</td>
  40. </tr>
  41. <tr>
  42. <td>−1</td>
  43. <td>&nbsp;10 ÷ 2</td>
  44. <td>&nbsp;5&nbsp;&nbsp;&nbsp;</td>
  45. </tr>
  46. <tr>
  47. <td>−2</td>
  48. <td>&nbsp;&nbsp;5 ÷ 2</td>
  49. <td>&nbsp;2.5&nbsp;</td>
  50. </tr>
  51. <tr>
  52. <td>−3</td>
  53. <td>2.5 ÷ 2</td>
  54. <td>&nbsp;1.25</td>
  55. </tr>
  56. </tbody>
  57. </table>
  58. <figcaption style="font-style:italic">
  59. Example with a base of 10 and a ratio of 2<br />
  60. </figcaption>
  61. </figure>
  62. <p>You can also associate each step in the sequence with the number of times the ratio has been multiplied or divided:</p>
  63. <figure style="margin:1em 0; text-align:center">
  64. <table style="display:table; width:100%; table-layout:fixed">
  65. <thead>
  66. <tr>
  67. <th style="text-align:center">Step</th>
  68. <th style="text-align:center">Math</th>
  69. <th style="text-align:center">Result</th>
  70. </tr>
  71. </thead>
  72. <tbody style="font:1em 'source code pro',monospace">
  73. <tr>
  74. <td>+3</td>
  75. <td>10 × 2 × 2 × 2</td>
  76. <td>80&nbsp;&nbsp;&nbsp;</td>
  77. </tr>
  78. <tr>
  79. <td>+2</td>
  80. <td>10 × 2 × 2&nbsp;&nbsp;&nbsp;&nbsp;</td>
  81. <td>40&nbsp;&nbsp;&nbsp;</td>
  82. </tr>
  83. <tr>
  84. <td>+1</td>
  85. <td>10 × 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
  86. <td>20&nbsp;&nbsp;&nbsp;</td>
  87. </tr>
  88. <tr style="opacity:.5">
  89. <td>&nbsp;0</td>
  90. <td><em>none</em></td>
  91. <td>10&nbsp;&nbsp;&nbsp;</td>
  92. </tr>
  93. <tr>
  94. <td>−1</td>
  95. <td>10 ÷ 2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
  96. <td>&nbsp;5&nbsp;&nbsp;&nbsp;</td>
  97. </tr>
  98. <tr>
  99. <td>−2</td>
  100. <td>10 ÷ 2 ÷ 2&nbsp;&nbsp;&nbsp;&nbsp;</td>
  101. <td>&nbsp;2.5&nbsp;</td>
  102. </tr>
  103. <tr>
  104. <td>−3</td>
  105. <td>10 ÷ 2 ÷ 2 ÷ 2</td>
  106. <td>&nbsp;1.25</td>
  107. </tr>
  108. </tbody>
  109. </table>
  110. </figure>
  111. <p>Experimenting with base and ratio parameters is a quick way to gauge how much proportional contrast is right for your project. Compare the following scales:</p>
  112. <ul>
  113. <li><a href="http://www.modularscale.com/?1&amp;em&amp;1.618&amp;web&amp;text">The golden section</a> (1.618)</li>
  114. <li><a href="http://www.modularscale.com/?1&amp;em&amp;1.2&amp;web&amp;text">The minor third</a> (1.2)</li>
  115. </ul>
  116. <p>Due to their ratios, these scales have wildly differing degrees of change between each step. The &#8220;golden section&#8221; ratio yields much more change than the &#8220;minor third&#8221;. Consider how much change you&#8217;re likely to need, and how it correlates with varying screen sizes and content hierarchy.</p>
  117. <figure style="margin:1em 0">
  118. <a href="http://3w7ov13ob0hk2kk1w147yffjlu5.wpengine.netdna-cdn.com/wp-content/uploads/2015/12/modularscale-ratios_compared.png"><img src="http://3w7ov13ob0hk2kk1w147yffjlu5.wpengine.netdna-cdn.com/wp-content/uploads/2015/12/modularscale-ratios_compared.png" alt="Comparing two scale ratios"></a></p>
  119. <figcaption style="text-align:center; font-style:italic">
  120. Scales with the ratios of 1.618 and 1.2 compared on <a href="http://modularscale.com">modularscale.com</a><br />
  121. </figcaption>
  122. </figure>
  123. <p>The balance of typographic contrast in scale is dependent on screen size. A scale that works well on a large screen may have too much contrast for a small screen (and feel obtrusive). Likewise, a scale that is harmonious on a small screen may be too subtle when viewed on a large screen.</p>
  124. <p>One solution to this conundrum is to create a scale intended for small screens that is also capable of adapting for large ones. The first thing to consider when creating that scale is which ratio to use.</p>
  125. <figure style="margin:1em 0; text-align:center">
  126. <table style="display:table; width:100%; table-layout:fixed">
  127. <thead>
  128. <tr>
  129. <th style="text-align:center">Step</th>
  130. <th style="text-align:center">Font size</th>
  131. <th>Result</th>
  132. </tr>
  133. </thead>
  134. <tbody style="font-family:'source code pro',monospace">
  135. <tr>
  136. <td>&nbsp;0</td>
  137. <td>&nbsp;&nbsp;1.0em</td>
  138. <td>
  139. <div style="font-size:1em; text-align:left">Abcdefg</div>
  140. </td>
  141. </tr>
  142. <tr>
  143. <td>+1</td>
  144. <td>&nbsp;&nbsp;1.2em</td>
  145. <td>
  146. <div style="font-size:1.2em; text-align:left">Abcdefg</div>
  147. </td>
  148. </tr>
  149. <tr>
  150. <td>+2</td>
  151. <td>&nbsp;1.44em</td>
  152. <td>
  153. <div style="font-size:1.44em; text-align:left">Abcdefg</div>
  154. </td>
  155. </tr>
  156. <tr>
  157. <td>+3</td>
  158. <td>1.728em</td>
  159. <td>
  160. <div style="font-size:1.728em; text-align:left">Abcdefg</div>
  161. </td>
  162. </tr>
  163. <tr>
  164. <td>+4</td>
  165. <td>2.074em</td>
  166. <td>
  167. <div style="font-size:2.074em; text-align:left">Abcdefg</div>
  168. </td>
  169. </tr>
  170. <tr>
  171. <td>+5</td>
  172. <td>2.488em</td>
  173. <td>
  174. <div style="font-size:2.488em; text-align:left">Abcdefg</div>
  175. </td>
  176. </tr>
  177. </tbody>
  178. </table>
  179. <figcaption style="font-style:italic">
  180. The minor third ratio (1.2) with a base of 1em<br />
  181. </figcaption>
  182. </figure>
  183. <p><a href="http://www.modularscale.com/?1&amp;em&amp;1.2&amp;web&amp;text">The minor third</a> ratio of 1.2 yields a gradually changing range of sizes. They all feel reasonable for small screens, and are distinct enough for levels of typographic hierarchy. At step #5, the resulting size can still be used while retaining a reasonable number of characters per line. With these attributes, this ratio feels like a good selection for small screen proportions.<sup style="line-height:0"><a href="#responsive-guide-to-type-sizing-fn1">1</a></sup></p>
  184. <h3>Applying your scale from the ground up</h3>
  185. <p>After figuring out a scale that works well for your project, you&#8217;ll probably want to put it into practice. CSS offers a few options:</p>
  186. <ol>
  187. <li>Copying and pasting numbers for a bunch of property values</li>
  188. <li>Using preprocessors like <a href="http://sass-lang.com">Sass</a> with built-in math capabilities</li>
  189. <li>Using the native CSS <code>calc()</code> function</li>
  190. </ol>
  191. <p>The following examples employ option #3, using <a href="https://github.com/postcss">PostCSS</a> in order to provide browser support for <code>calc()</code> and <code>var()</code>. If you prefer a different CSS processor, you can apply the same operations with that tool&#8217;s own arithmetic and variable syntax.<sup style="line-height:0"><a href="#responsive-guide-to-type-sizing-fn2">2</a></sup></p>
  192. <p>For more complex modular scale applications, you should check out these plugins available for <a href="https://github.com/postcss">PostCSS</a> and <a href="http://sass-lang.com">Sass</a>:</p>
  193. <ul>
  194. <li><a href="https://github.com/kristoferjoseph/postcss-modular-scale">postcss-modular-scale</a></li>
  195. <li><a href="https://github.com/modularscalemodularscale-sass">modularscale-sass</a></li>
  196. </ul>
  197. <p>They provide a cleaner syntax than <code>calc()</code> for getting scale values, and also support multiple values for <em>base</em> and <em>ratio</em>.</p>
  198. <h4>Configuring the variables</h4>
  199. <p>The first step is to define values for the <em>ratio</em> and <em>base</em> variables that much of the scale logic depends on:</p>
  200. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #3333ff;">:root </span><span style="color: #00AA00;">&#123;</span>
  201. --ratio<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1.2</span><span style="color: #00AA00;">;</span>
  202. --base<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
  203. --base-em<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> <span style="color: #933;">1em</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  204. --base-px<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  205. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  206. <p>There are three base-related properties defined here. This is to provide flexibility when different CSS units (or no units) are needed.</p>
  207. <p>Next, you need to establish the range of scale steps you&#8217;re likely to use:</p>
  208. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #3333ff;">:root </span><span style="color: #00AA00;">&#123;</span>
  209. --ms0<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">1</span><span style="color: #00AA00;">;</span>
  210. --ms1<span style="color: #00AA00;">:</span> var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 1.2 */</span>
  211. --ms2<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 1.44 */</span>
  212. --ms3<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms2<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 1.728 */</span>
  213. --ms4<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 2.074 */</span>
  214. --ms5<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 2.488 */</span>
  215. --ms6<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 2.986 */</span>
  216. --ms7<span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--ratio<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 3.583 */</span>
  217. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  218. <p>With these step properties defined, you can now compute them with your base to get values from your scale:</p>
  219. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 1.2em */</span>
  220. <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms2<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #808080; font-style: italic;">/* 1.44em */</span></pre></td></tr></table></div>
  221. <h4>Establishing default sizes</h4>
  222. <p>The browser default <code>font-size</code> paired with the scale step of 1.44 for <code>line-height</code> feels like an <a href="http://practicaltypography.com/line-spacing.html">appropriate choice</a> for body copy:</p>
  223. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;">body <span style="color: #00AA00;">&#123;</span>
  224. <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms0<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  225. <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms2<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  226. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  227. <p>Headings probably don&#8217;t need to consist of six different sizes (as there are other ways to differentiate them). However, if you do wish to incorporate a different size for each, you can use a series of steps from your scale:</p>
  228. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;">h6 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> / var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  229. h5 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms0<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  230. h4 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  231. h3 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms2<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  232. h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  233. h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  234. <p>In addition to heading <code>font-size</code>, you should also consider the values for <code>line-height</code>.</p>
  235. <blockquote class="twitter-tweet" lang="en"><p lang="en" dir="ltr">One of the most overlooked things in front-end development is the line-height of wrapped headings. They&#39;re often way too large</p>
  236. <p>&mdash; Matt Stow (@stowball) <a href="https://twitter.com/stowball/status/672710430628810752">December 4, 2015</a></p></blockquote>
  237. <p><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
  238. <p>Using a lower step of the scale in this case can benefit readability when lines are wrapping:</p>
  239. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;">h3<span style="color: #00AA00;">,</span>
  240. h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  241. h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">line-height</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms0<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  242. <p>With these defaults for body copy and headings in place, you have a nice foundational hierarchy that works well on small screens:</p>
  243. <figure style="margin:1em 0">
  244. <a href="http://3w7ov13ob0hk2kk1w147yffjlu5.wpengine.netdna-cdn.com/wp-content/uploads/2015/12/modularscale-ratio_in_use1.png"><img src="http://3w7ov13ob0hk2kk1w147yffjlu5.wpengine.netdna-cdn.com/wp-content/uploads/2015/12/modularscale-ratio_in_use1.png" alt="Ratio of 1.2 on a small screen"></a></p>
  245. <figcaption style="text-align:center; font-style:italic">
  246. A scale with a ratio of 1.2 applied to content on a 320&#215;480 screen<br />
  247. </figcaption>
  248. </figure>
  249. <h3>Expanding your scale when proportional contrast is needed</h3>
  250. <p>Increasing screen sizes and viewing distances will reveal new typographic requirements for your layout. Your body copy and the contrast in scale of all typographic elements will likely need adjustments to suit the new context:</p>
  251. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@media (min-width: 480px) {</span>
  252. html <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-px<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  253. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  254. <p>Bumping the global font size like this is a practical adjustment that requires little effort. While this practice is <a href="https://bugsnag.com/blog/responsive-typography-with-rems">common</a>, it&#8217;s worth noting that even small tweaks like this can leverage steps from your modular scale. Rather than incrementing the size by an arbitrary few pixels or a percentage, you can use your scale to determine the new value.</p>
  255. <p>In line with amplifying your body copy, you might also want to increase the amount of change between each heading size. You can do this by overriding the larger headings with sizes from higher up your scale:</p>
  256. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@media (min-width: 768px) {</span>
  257. h3 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms3<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  258. h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms4<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  259. h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  260. <span style="color: #00AA00;">&#125;</span>
  261. &nbsp;
  262. <span style="color: #a1a100;">@media (min-width: 1024px) {</span>
  263. h2 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms5<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  264. h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms6<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  265. <span style="color: #00AA00;">&#125;</span>
  266. &nbsp;
  267. <span style="color: #a1a100;">@media (min-width: 1360px) {</span>
  268. h1 <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms7<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
  269. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  270. <p>With these size adjustments in place, viewport width will determine how far up the scale your headings are allowed to climb:</p>
  271. <p><iframe height='480' scrolling='no' src='//codepen.io/erikjung/embed/XmOdEo/?height=480&#038;theme-id=0&#038;default-tab=result' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'>See the Pen <a href='http://codepen.io/erikjung/pen/XmOdEo/'>Responsive Type Sizing</a> by Erik Jung (<a href='http://codepen.io/erikjung'>@erikjung</a>) on <a href='http://codepen.io'>CodePen</a>.<br />
  272. </iframe></p>
  273. <p>(View <a href="http://codepen.io/erikjung/pen/XmOdEo">the full CodePen</a> to see how the text size responds.)</p>
  274. <h3>Broadening the usage of your scale</h3>
  275. <p>Limiting your scale&#8217;s influence to just specific elements would be <a href="https://www.youtube.com/watch?v=Ru9e2rTHeuk">highly illogical</a>. You want flexible, abstracted styles to build complex interfaces with. Utility classes can provide that flexibility:</p>
  276. <div class="wp_syntax"><table><tr><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.u-textBigger</span> <span style="color: #00AA00;">&#123;</span>
  277. <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">*</span> var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  278. <span style="color: #00AA00;">&#125;</span>
  279. &nbsp;
  280. <span style="color: #6666ff;">.u-textSmaller</span> <span style="color: #00AA00;">&#123;</span>
  281. <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span> calc<span style="color: #00AA00;">&#40;</span>var<span style="color: #00AA00;">&#40;</span>--base-em<span style="color: #00AA00;">&#41;</span> / var<span style="color: #00AA00;">&#40;</span>--ms1<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
  282. <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>
  283. <p>With one ratio relating all the text sizes, anything affected by these classes will adhere to the steps of your scale. Even when combining or nesting the classes, the resulting text will remain in relative proportion:</p>
  284. <div class="wp_syntax"><table><tr><td class="code"><pre class="html5" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textBigger&quot;</span>&gt;</span>
  285. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>Now I'm as big as an H1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h2</span>&gt;</span>
  286. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>Now I'm as big as an H2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">h3</span>&gt;</span>
  287. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">p</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textSmaller&quot;</span>&gt;</span>I haven't changed at all.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">p</span>&gt;</span>
  288. <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  289. &nbsp;
  290. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textSmaller&quot;</span>&gt;</span>
  291. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textSmaller&quot;</span>&gt;</span>
  292. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textBigger&quot;</span>&gt;</span>
  293. <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">span</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;u-textBigger&quot;</span>&gt;</span>Same as it ever was.<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">span</span>&gt;</span>
  294. <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  295. <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
  296. <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></td></tr></table></div>
  297. <p><iframe height='320' scrolling='no' src='//codepen.io/erikjung/embed/RrrzVr/?height=320&#038;theme-id=0&#038;default-tab=result' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'>See the Pen <a href='http://codepen.io/erikjung/pen/RrrzVr/'>Responsive Type Sizing (utils)</a> by Erik Jung (<a href='http://codepen.io/erikjung'>@erikjung</a>) on <a href='http://codepen.io'>CodePen</a>.<br />
  298. </iframe></p>
  299. <h3>TL;DR</h3>
  300. <ul>
  301. <li>Use a modular scale to define your typographic proportions.</li>
  302. <li>Create a scale that is flexible enough to work on many screen sizes.</li>
  303. <li>Use higher steps from your scale when more proportional contrast is needed.</li>
  304. <li>Don&#8217;t limit the use of your scale to specific elements.</li>
  305. </ul>
  306. <h3>Further reading</h3>
  307. <ul>
  308. <li><a href="http://alistapart.com/article/more-meaningful-typography">More Meaningful Typography</a> by Tim Brown</li>
  309. <li><a href="http://typecast.com/blog/a-more-modern-scale-for-web-typography">A More Modern Scale for Web Typography</a> by Jason Pamental</li>
  310. <li><a href="http://madebymike.com.au/writing/precise-control-responsive-typography">Precise control over responsive typography</a> by Mike Riethmuller</li>
  311. <li><a href="https://bugsnag.com/blog/responsive-typography-with-modular-scale">Responsive typography with Modular Scale</a> by Max Luster</li>
  312. <li><a href="http://www.modularscale.com">Modular Scale Calculator</a></li>
  313. <li><a href="http://www.pearsonified.com/typography">Golden Ratio Typography Calculator</a></li>
  314. <li><a href="http://www.gridlover.net/try">Gridlover</a></li>
  315. <li><a href="http://type-scale.com">Type Scale</a></li>
  316. </ul>
  317. <hr />
  318. <h5>Footnotes</h5>
  319. <ol style="font-size:80%;">
  320. <li id="responsive-guide-to-type-sizing-fn1">
  321. Using one base and one ratio isn&#8217;t the only way to arrive at a scale that works within small screen limitations. You can also create a <em>multi-stranded</em> scale by using multiple base or ratio values instead of just one. Here is an <a href="http://www.modularscale.com/?1,4&#038;em&#038;1.5&#038;web&#038;text">example</a> using a secondary base value to shorten the distance between each step. See <a href="http://modularscale.com">modularscale.com</a> for a better explanation.
  322. </li>
  323. <li id="responsive-guide-to-type-sizing-fn2">
  324. The <a href="http://github.com/cssnext/postcss-cssnext">postcss-cssnext</a> plugin can be used to transform the output of <code>calc()</code> and <code>var()</code>.
  325. </li>
  326. </ol>