<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>johndjameson.com</title>
  <subtitle>Web typography and front-end development</subtitle>
  <id>http://johndjameson.com/blog</id>
  <link href="http://johndjameson.com/blog"/>
  <link href="http://johndjameson.com/feed.xml" rel="self"/>
  <updated>2016-06-13T19:00:00-05:00</updated>
  <author>
    <name>John D. Jameson</name>
  </author>
  <entry>
    <title>Styling Fallback Fonts with Sass</title>
    <link rel="alternate" href="http://johndjameson.com/blog/styling-fallback-fonts-with-sass/"/>
    <id>http://johndjameson.com/blog/styling-fallback-fonts-with-sass/</id>
    <published>2016-06-13T19:00:00-05:00</published>
    <updated>2017-09-22T20:20:22-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">One of the pain points of loading fonts asynchronously is writing convoluted CSS for fallback styles. Fortunately, Sass can make it easier to achieve great-looking web typography before a site’s fonts finish loading.</summary>
    <content type="html">&lt;p&gt;If you’ve ever read a blog post about loading web fonts asynchronously for performance, you’ve probably encountered CSS like this before:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Look familiar? In that example, I’m using the &lt;a href="https://github.com/typekit/webfontloader"&gt;Web Font Loader&lt;/a&gt; to load Source Sans Pro via JavaScript. When the fonts finish downloading, the library adds a &lt;code&gt;wf-active&lt;/code&gt; class to the &lt;code&gt;html&lt;/code&gt; element. Then the font family switches from Arial to Source Sans Pro — or from &lt;em&gt;fallback font&lt;/em&gt; to &lt;em&gt;web font&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Unfortunately, most web fonts don’t have ideal system font equivalents. To soften the janky reflow when switching fonts, you’ll need to fine-tune the fallback family’s size and other properties.&lt;/p&gt;

&lt;p&gt;Arial is bigger than Source Sans Pro, so in this example, I reduced its font size to &lt;code&gt;20px&lt;/code&gt; to match Source Sans Pro at &lt;code&gt;21px&lt;/code&gt;. To compensate for the decrease in font size, I also &lt;em&gt;increased&lt;/em&gt; Arial’s line height.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax css"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.45&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;21px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.35&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Here, I wrote two selectors: &lt;code&gt;html&lt;/code&gt; and &lt;code&gt;html.wf-active&lt;/code&gt;. It’s a pretty intuitive for properties inherited from the &lt;code&gt;html&lt;/code&gt; element, but relying on a similar approach elsewhere will introduce a couple maintenance problems throughout the CSS.&lt;/p&gt;

&lt;p&gt;Let’s go over the issues one by one and I’ll show you ways to use Sass to clean things up.&lt;/p&gt;

&lt;h2 id="nest-with-the-ampersand-selector"&gt;Nest with the Ampersand Selector&lt;/h2&gt;

&lt;p&gt;The first thing we can do is use Sass’ ampersand selector to nest the current selector within an ancestor. It’s easier explain with an example:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax sass"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Arial'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;34px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="mi"&gt;.25&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;

  &lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt; &lt;span class="k"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Arial'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;36px&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="mi"&gt;.1&lt;/span&gt;&lt;span class="err"&gt;;&lt;/span&gt;
  &lt;span class="err"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;The compiled CSS looks like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Fallback styles */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt; &lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;/* Web font styles */&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;See how the &lt;code&gt;h1&lt;/code&gt; comes after &lt;code&gt;html.wf-active&lt;/code&gt;? Nesting this way cuts down on a little repetition, but there’s a lot more we can do.&lt;/p&gt;

&lt;h2 id="decrease-specificity"&gt;Decrease Specificity&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;html.wf-active h1&lt;/code&gt; is a &lt;em&gt;compound selector&lt;/em&gt;, which makes it difficult to override any of its styles later on in the style sheet. Its specificity is unreasonably high for what should be a base style.&lt;/p&gt;

&lt;p&gt;We can address that problem by flipping the selector so it affects specificity only when web fonts &lt;em&gt;haven’t&lt;/em&gt; loaded. The &lt;code&gt;not()&lt;/code&gt; pseudo-class lets us do exactly that.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;36px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="py"&gt;html&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="n"&gt;not&lt;/span&gt;&lt;span class="p"&gt;(.&lt;/span&gt;&lt;span class="n"&gt;wf-active&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;&amp;amp;&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;34px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now when web fonts finish loading and the &lt;code&gt;wf-active&lt;/code&gt; class gets applied, &lt;code&gt;html:not(.wf-active) h1&lt;/code&gt; styles are ignored and the &lt;code&gt;h1&lt;/code&gt; specificity stays nice and low.&lt;/p&gt;

&lt;h2 id="put-it-in-a-mixin"&gt;Put It in a Mixin&lt;/h2&gt;

&lt;p&gt;I don’t know about you, but I don’t want to write &lt;code&gt;html:not(.wf-loaded) &amp;amp;&lt;/code&gt; for every fallback font style throughout my code. It’s easy to forget and tedious to write.&lt;/p&gt;

&lt;p&gt;So let’s create a mixin to speed things up. The syntax for this one is simple. Name yours whatever you like, put the ampersand selector in there, and specify where the content goes.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;fontless&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;@content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now use that mixin to apply fallback font styles with ease.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax css"&gt;&lt;code&gt;&lt;span class="nt"&gt;h1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;36px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="err"&gt;@include&lt;/span&gt; &lt;span class="err"&gt;fontless&lt;/span&gt; &lt;span class="err"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;34px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1.25&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="err"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want to use the same mixin on the &lt;code&gt;html&lt;/code&gt; element, you’ll need to add a conditional to make sure it doesn’t nest inside itself.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax scss"&gt;&lt;code&gt;&lt;span class="k"&gt;@mixin&lt;/span&gt; &lt;span class="nf"&gt;fontless&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;@if&lt;/span&gt; &lt;span class="nf"&gt;is-superselector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'html'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;@content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;@else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;html&lt;/span&gt;&lt;span class="nd"&gt;:not&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;.wf-active&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;@content&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And then it works on &lt;code&gt;html&lt;/code&gt;. Kablamo.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;html&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Source Sans Pro'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Arial'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;21px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="mi"&gt;.35&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="k"&gt;@include&lt;/span&gt; &lt;span class="nd"&gt;fontless&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Arial'&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;font-size&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;line-height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="mi"&gt;.45&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Okay, we’re done here. Who needs conclusions on front-end blog posts? You learned a thing — go have fun jank busting fallback fonts. Or &lt;a href="https://twitter.com/johndjameson"&gt;send me a tweet&lt;/a&gt; if you liked the article or have any questions. That’s cool, too.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Sidebearings &amp; Alignment</title>
    <link rel="alternate" href="http://johndjameson.com/blog/sidebearings-and-alignment/"/>
    <id>http://johndjameson.com/blog/sidebearings-and-alignment/</id>
    <published>2015-09-29T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">When using different font sizes throughout a design, you'll need to account for sidebearings to keep the type looking properly aligned.</summary>
    <content type="html">&lt;p&gt;Sidebearings are a necesary part of any font; along with kerning, they ensure that letters look well-spaced next to one another. If you look at one of the glyphs in a font, its &lt;em&gt;sidebearings&lt;/em&gt; are the spaces to the left and right of the letterform. These, along with the character itself, span a glyph’s entire width.&lt;/p&gt;

&lt;p&gt;&lt;img alt="Sidebearings next alongside an H" src="/assets/images/sidebearings-glyph-345ad4fb.svg" /&gt;&lt;/p&gt;

&lt;p&gt;So how can sidebearings cause problems with alignment?&lt;/p&gt;

&lt;p&gt;In left-aligned type, each line’s first glyph begins at the same point, but because of their sidebearings, the actual &lt;em&gt;characters&lt;/em&gt; don’t. This causes large type to look indented — especially when set above or below smaller type.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="630" scrolling="no" src="https://codepen.io/johndjameson/embed/43118a0bceea2de380f87402ff75f3c8/?default-tab=results&amp;amp;height=630&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;In the example above, you can see that the larger the font size is, the more indented the type appears.&lt;/p&gt;

&lt;h2 id="negative-margins"&gt;Negative margins&lt;/h2&gt;

&lt;p&gt;Accounting for sidebearings in left-aligned type is pretty straightforward in CSS: you can use &lt;code&gt;margin-left&lt;/code&gt; with a negative value.&lt;/p&gt;

&lt;p&gt;Depending on the typeface and font size, the value you’ll need can differ wildly, so try out several values to see what works best. I’ve found that they usually fall within the -0.02em to -0.1em range.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="630" scrolling="no" src="https://codepen.io/johndjameson/embed/17300c1454dcfc16c02cc3fba9546333/?default-tab=results&amp;amp;height=630&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;And there you have it: the type now looks properly aligned, thanks to a few negative margins.&lt;/p&gt;

&lt;h2 id="takeaways"&gt;Takeaways&lt;/h2&gt;

&lt;p&gt;Tweaking alignment with CSS can become a hassle if you try to manage all the type across a website. I think it’s best to focus on just the &lt;em&gt;largest&lt;/em&gt; type, and then make adjustments elsewhere as needed. It’s simple to do and can have a huge effect on how cohesive your web typography looks.&lt;/p&gt;

&lt;p&gt;As always, feel free to message me on &lt;a href="https://twitter.com/johndjameson"&gt;Twitter&lt;/a&gt; if you have any questions, feedback, or topic suggestions.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Making Sense of Ch Units</title>
    <link rel="alternate" href="http://johndjameson.com/blog/making-sense-of-ch-units/"/>
    <id>http://johndjameson.com/blog/making-sense-of-ch-units/</id>
    <published>2015-09-15T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">If you try to use ch units with most fonts, things will probably end up broken. Here are some of the issues you'll come across as well as ways you can fix them.</summary>
    <content type="html">&lt;p&gt;Ch units can be an &lt;a href="/blog/typographic-units-in-css.html"&gt;invaluable tool&lt;/a&gt; when you’re working with monospaced fonts. For example, you can declare &lt;code&gt;width: 60ch&lt;/code&gt; on an element and it’ll be the perfect size to fit 60 characters per line of text.&lt;/p&gt;

&lt;p&gt;But when using ch units with non-monospaced (proportional) fonts, you’ll encounter some unexpected results. Declaring the same width of &lt;code&gt;60ch&lt;/code&gt; on a container &lt;em&gt;should&lt;/em&gt; work, but it doesn’t. You’ll end up with somewhere around 70 or 75 characters per line.&lt;/p&gt;

&lt;p&gt;So what causes them to be so inaccurate?&lt;/p&gt;

&lt;p&gt;It comes down to the defintion of a ch unit. According to the &lt;a href="http://www.w3.org/TR/css3-values/#font-relative-lengths"&gt;specification&lt;/a&gt;, a ch unit is equal to the width of the 0 (zero) glyph found in the font used to render it. This definition works for monospaced fonts (where every glyph shares an identical width), but it’s completely unreliable for proportional fonts. On average, a ch unit ends up being 15–30% larger than the width of a font’s other glyphs.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="540" scrolling="no" src="https://codepen.io/johndjameson/embed/24f0cb69d20658c4b14f6fef8e32ce59/?default-tab=results&amp;amp;height=540&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;See the problem? When compared to a line of zeros, ch units perform &lt;em&gt;exactly&lt;/em&gt; as the specification defines them. But when compared to a line of text, ch units are too wide to be useful.&lt;/p&gt;

&lt;h2 id="so-lets-fix-the-problem"&gt;So let’s fix the problem&lt;/h2&gt;

&lt;p&gt;Ch units have a lot of potential, but it’ll take some math to get them working with proportional fonts.&lt;/p&gt;

&lt;p&gt;Let’s say you have a 1000-character-long line of text and a &lt;code&gt;div&lt;/code&gt; with a width of &lt;code&gt;1000ch&lt;/code&gt;. Like in the demo above, the line of text will be shorter than the same number of ch units. Okay, we expect that now. But what’s cool is that you can divide the width of the line of text by the width of the &lt;code&gt;div&lt;/code&gt; to calculate a ratio that accounts for the discrepancy. The number you’ll end up with is usually in the 0.75–0.85 range for non-monospaced fonts.&lt;/p&gt;

&lt;p&gt;Multiply by that number when using ch units, and the resulting value gives you a number much closer to what you’re looking for.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="470" scrolling="no" src="https://codepen.io/johndjameson/embed/c41229e9197ff46d987dceffb4f36b38/?default-tab=results&amp;amp;height=470&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;The more text there is, the more reliable the resulting number becomes.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="340" scrolling="no" src="https://codepen.io/johndjameson/embed/a6c07f62eb3d33741effa552b22abd84/?default-tab=results&amp;amp;height=340&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;h2 id="takeaways"&gt;Takeaways&lt;/h2&gt;

&lt;p&gt;Ch units offer a lot of interesting potential once you get past their quirks. They’re &lt;em&gt;invaluable&lt;/em&gt; tools when working with monospaced fonts, and if you’re willing to take a few measurements and calculate a couple ratios, they’re &lt;em&gt;excellent&lt;/em&gt; for proportional fonts, too.&lt;/p&gt;

&lt;p&gt;Send me a message on &lt;a href="https://twitter.com/johndjameson"&gt;Twitter&lt;/a&gt; if you have any questions or feedback — or if you just want to geek out over web typography.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Kerning &amp; Ligatures in Letterspaced Type</title>
    <link rel="alternate" href="http://johndjameson.com/blog/kerning-and-ligatures-in-letterspaced-type/"/>
    <id>http://johndjameson.com/blog/kerning-and-ligatures-in-letterspaced-type/</id>
    <published>2015-08-31T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">Letterspacing affects type's horizontal rhythm, and so do kerning and ligatures. Combining all three of them can make for beautifully spaced typography.</summary>
    <content type="html">&lt;p&gt;I recently &lt;a href="guidelines-for-letterspacing-type.html"&gt;wrote an article&lt;/a&gt; about the general guidelines for letterspacing type on the web. &lt;em&gt;This article&lt;/em&gt; is a follow-up and much more focused, so bear that in mind as you continue reading. I’d recommend checking out the last one if you want a quick overview of using letterspacing on the web.&lt;/p&gt;

&lt;p&gt;Now with that out of the way, let’s jump right into the rules for letterspacing type with kerning and ligatures.&lt;/p&gt;

&lt;h2 id="kerning"&gt;Kerning&lt;/h2&gt;

&lt;p&gt;It’s a good practice to enable kerning in titles, headings, and other display type. These elements attract the most attention in a design, so it’s important to get their details &lt;em&gt;just right&lt;/em&gt; when typesetting.&lt;/p&gt;

&lt;h3 id="tight-letterspacing"&gt;Tight letterspacing&lt;/h3&gt;

&lt;p&gt;The majority of kerning &lt;em&gt;decreases&lt;/em&gt; the space present between letters. By enabling kerning alone, you can often decrease the horizontal spacing in a line of type — similar to reducing letterspacing. Tight letterspacing exaggerates the need for kerning, so if you make negative adjustments to the &lt;code&gt;letter-spacing&lt;/code&gt; property, you should probably enable kerning, too.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="290" scrolling="no" src="https://codepen.io/johndjameson/embed/5e36a72a168d631d7f3b3ccdcf310497/?default-tab=results&amp;amp;height=290&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;In the example above, there’s a noticeable gap between the unkerned &lt;em&gt;T&lt;/em&gt; and &lt;em&gt;o&lt;/em&gt; pair at the beginning of the word &lt;em&gt;Tomato&lt;/em&gt;. It looks awkward in an otherwise tightly spaced context. Enabling kerning here tightens up the initial spacing and improves the overall look and feel of the word.&lt;/p&gt;

&lt;h3 id="loose-letterspacing"&gt;Loose letterspacing&lt;/h3&gt;

&lt;p&gt;Kerning becomes less important as letterspacing increases, and at a certain point, it’s barely even noticeable.&lt;/p&gt;

&lt;p&gt;If we look at the same word &lt;em&gt;Tomato&lt;/em&gt; — now set with positive letterspacing — the difference is too subtle to make an impact. Kerning becomes a nice-to-have here, instead of a necessity.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="290" scrolling="no" src="https://codepen.io/johndjameson/embed/6d702133d6c081a4af782d648e1c3ff6/?default-tab=results&amp;amp;height=290&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;h2 id="ligatures"&gt;Ligatures&lt;/h2&gt;

&lt;p&gt;Since ligatures are the combined form of two or more letters, and letterspacing adjusts the space &lt;em&gt;in between&lt;/em&gt; those letters, you end up with two typesetting techniques that are at cross-purposes. That’s not to say you shouldn’t letterspace type containing ligatures, but there are a couple considerations to keep in mind.&lt;/p&gt;

&lt;h3 id="loose-letterspacing-1"&gt;Loose letterspacing&lt;/h3&gt;

&lt;p&gt;Ligatures are always a fixed width, but you can still letterspace the type surrounding them. As a result, ligatures end up looking clumped together within a word. It’s best to avoid them altogether in loosely letterspaced type.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="230" scrolling="no" src="https://codepen.io/johndjameson/embed/e4d79dfcf8e98e856f9d5c8ba65f8b4e/?default-tab=results&amp;amp;height=230&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;In this example, we’re much better off using the version of &lt;em&gt;liftoff&lt;/em&gt; that doesn’t contain ligatures.&lt;/p&gt;

&lt;h3 id="tight-letterspacing-1"&gt;Tight letterspacing&lt;/h3&gt;

&lt;p&gt;Ligatures are often narrower than their two related characters, so they look right at home in lightly tightened type. In a very tight setting, however, ligatures can stand out as noticeably wider than other letters.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="230" scrolling="no" src="https://codepen.io/johndjameson/embed/cb5625881dcf0db7e11d26d69c2ff40c/?default-tab=results&amp;amp;height=230&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;If you look closely at the &lt;em&gt;ff&lt;/em&gt; and &lt;em&gt;ft&lt;/em&gt; pairs in the second word &lt;em&gt;liftoff&lt;/em&gt;, you’ll see an awkward gap between their crossbars. Enabling ligatures fixes this problem by combining the separate letters into a single glyph and merging the two crossbars into one.&lt;/p&gt;

&lt;h2 id="browser-support"&gt;Browser support&lt;/h2&gt;

&lt;p&gt;The default behavior of most browsers is to disable kerning and ligatures wherever the &lt;code&gt;letter-spacing&lt;/code&gt; property is applied. Due to current browser support, it takes some very precise CSS to get all three components working together.&lt;/p&gt;

&lt;p&gt;The biggest issue is that Safari doesn’t &lt;em&gt;actually&lt;/em&gt; support &lt;code&gt;font-feature-settings&lt;/code&gt;. Declare the property in any way, and Safari enables both kerning and ligatures. Want to turn on small caps? You get kerning and ligatures. Want to &lt;em&gt;disable&lt;/em&gt; kerning and ligatures? You get kerning and ligatures. This is particularly problematic when the property is inherited, since there’s no way to unset it by using the property itself.&lt;/p&gt;

&lt;p&gt;I made a &lt;a href="http://codepen.io/johndjameson/pen/e96a930f0a73dd36f9ff173422b48523?editors=110"&gt;CodePen demo&lt;/a&gt; with more information on browser support. It’s a little too in-depth to embed here, but definitely take a look if you plan on using kerning and ligatures together with with the &lt;code&gt;letter-spacing&lt;/code&gt; property.&lt;/p&gt;

&lt;h2 id="and-thats-it"&gt;And that’s it!&lt;/h2&gt;

&lt;p&gt;Before we wrap up, I have to give a shout-out to &lt;a href="https://twitter.com/bram_stein"&gt;Bram Stein&lt;/a&gt; for his work on &lt;a href="http://stateofwebtype.com/"&gt;The State of Web Type&lt;/a&gt;. That site has been a &lt;em&gt;huge&lt;/em&gt; help for me in figuring out an approach that works across browsers.&lt;/p&gt;

&lt;p&gt;If you have any questions about letterspacing on the web — or if you just want to chat about web typography — send me a message over on &lt;a href="https://twitter.com/johndjameson"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Guidelines for Letterspacing Type</title>
    <link rel="alternate" href="http://johndjameson.com/blog/guidelines-for-letterspacing-type/"/>
    <id>http://johndjameson.com/blog/guidelines-for-letterspacing-type/</id>
    <published>2015-08-17T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">Blog posts on line height and vertical rhythm are all so boring. Let's get horizontal, instead.</summary>
    <content type="html">&lt;p&gt;I know very few web designers who ever adjust letterspacing when setting type on the web. Small changes can have an enormous effect on the readability of text. That means it’s hard to make those decisions unless you’re &lt;em&gt;very confident&lt;/em&gt; with your knowledge in web typography.&lt;/p&gt;

&lt;p&gt;Effectively letterspacing text can make the difference between good typography and &lt;em&gt;great&lt;/em&gt; typography. With that in mind, I decided to put together some guidelines for letterspacing type on the web.&lt;/p&gt;

&lt;h2 id="capital-letters"&gt;Capital letters&lt;/h2&gt;

&lt;p&gt;It’s almost always a good idea to increase letterspacing with uppercase type. Default spacing between uppercase letters is designed to be the &lt;em&gt;minimum&lt;/em&gt; necessary, so you’ll usually want to add a little more breathing room between the characters.&lt;/p&gt;

&lt;p&gt;This usually involves setting a &lt;code&gt;letter-spacing&lt;/code&gt; value around 0.2–0.25 ems for headings and a value around 0.05–0.1 ems for acronyms.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="200" scrolling="no" src="https://codepen.io/johndjameson/embed/QbRayd/?default-tab=results&amp;amp;height=200&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;In this example, “HTML” and “CSS” are set in &lt;em&gt;small caps&lt;/em&gt;, but the same advice applies here, too.&lt;/p&gt;

&lt;h2 id="font-size"&gt;Font size&lt;/h2&gt;

&lt;p&gt;The relationship between font size and letterspacing is pretty straightforward: as size increases, letterspacing decreases, and as size decreases, letterspacing increases.&lt;/p&gt;

&lt;p&gt;In more practical terms, here’s what that relationship looks like:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Large text (e.g., titles and headings) should have decreased letterspacing.&lt;/li&gt;
  &lt;li&gt;Body text should have default tracking, or stick very close to default letterspacing.&lt;/li&gt;
  &lt;li&gt;Very small text should have increased letterspacing.&lt;/li&gt;
&lt;/ul&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="438" scrolling="no" src="https://codepen.io/johndjameson/embed/aa39c703c30de9f1b65a3c738ad344c2/?default-tab=results&amp;amp;height=438&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;h2 id="font-weight"&gt;Font weight&lt;/h2&gt;

&lt;p&gt;Like with font size, the relationship between font weight and letterspacing follows a simple pattern: as weight increases, letterspacing decreases, and as weight decreases, letterspacing increases.&lt;/p&gt;

&lt;p&gt;This is because of the way typefaces at look and feel at certain weights. Light typefaces have an airy aesthetic that’s complemented by open letterspacing, while bold typefaces have a dark and heavy aesthetic that’s complemented by pulling the letters &lt;em&gt;closer together&lt;/em&gt;.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="350" scrolling="no" src="https://codepen.io/johndjameson/embed/ba2516c0e03124d5afe2d7f0eefec5fd/?default-tab=results&amp;amp;height=350&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;For a more in-depth explanation on how weight affects letterspacing decisions, check out Carolina de Bartolo’s &lt;em&gt;Typography Matters&lt;/em&gt; talk over on &lt;a href="https://www.youtube.com/watch?v=VpBslige5Yk&amp;amp;feature=youtu.be&amp;amp;t=1130"&gt;YouTube&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id="light-on-dark-text"&gt;Light-on-dark text&lt;/h2&gt;

&lt;p&gt;Light type set on a dark background usually benefits from a small increase in letterspacing.&lt;/p&gt;

&lt;p&gt;If you look at the following example, you’ll notice that the white-on-black text appears &lt;em&gt;bolder&lt;/em&gt; than the black-on-white text. They’re the exact same size and weight, but the white-on-black text still looks a little bit thicker. To compensate for that difference, you’ll need to make a subtle increase in letterspacing.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="236" scrolling="no" src="https://codepen.io/johndjameson/embed/qdGyJY/?default-tab=results&amp;amp;height=236&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;p&gt;CSS supports &lt;code&gt;letter-spacing&lt;/code&gt; values in quarter-pixel increments, so I’m able to specify &lt;code&gt;0.5px&lt;/code&gt; in this example. When setting type at a small size, you’ll often find comfortable letterspacing somewhere &lt;em&gt;in between&lt;/em&gt; whole pixel values.&lt;/p&gt;

&lt;h2 id="theres-always-more-to-learn"&gt;There’s always more to learn&lt;/h2&gt;

&lt;p&gt;This article just &lt;em&gt;scratches the surface&lt;/em&gt; of letterspacing type on the web. Once you start combining different elements of typography, you’ll run into situations where its best to work &lt;em&gt;outside&lt;/em&gt; these guidelines. For example, how does type set in italics respond to letterspacing? And in what situations does wordspacing come into play?&lt;/p&gt;

&lt;p&gt;I’m still figuring out the answers to those questions myself, but if you’d like to start a conversation about web typography, hit me up on &lt;a href="https://twitter.com/johndjameson"&gt;Twitter&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Typographic Units in CSS</title>
    <link rel="alternate" href="http://johndjameson.com/blog/typographic-units-in-css/"/>
    <id>http://johndjameson.com/blog/typographic-units-in-css/</id>
    <published>2015-08-04T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">CSS offers many more units than pixels, ems, and percentages. But out of all the units available to us, I find two the most intriguing: ex and ch.</summary>
    <content type="html">&lt;p&gt;&lt;code&gt;Ex&lt;/code&gt; and &lt;code&gt;ch&lt;/code&gt; are &lt;em&gt;typographic units&lt;/em&gt;, meaning their values depend on an element’s font family. When you use &lt;code&gt;em&lt;/code&gt; or &lt;code&gt;rem&lt;/code&gt; units, the browser computes their values based on the element’s font size. It doesn’t matter what font gets displayed onscreen, the browser will compute the same values for every typeface. This is where &lt;code&gt;ex&lt;/code&gt; and &lt;code&gt;ch&lt;/code&gt; units offer a little more flexibility. They require the browser to reference an element’s font family &lt;em&gt;before&lt;/em&gt; computing values and applying styles.&lt;/p&gt;

&lt;p&gt;Let’s take a look at these two typographic units in more detail.&lt;/p&gt;

&lt;h2 id="ex-units"&gt;Ex units&lt;/h2&gt;

&lt;p&gt;In typographic terms, x-height is determined by the height of a typeface’s lowercase letters. This is often measured by the letter x, which doesn’t have any ascenders or descenders. The relationship between a typeface’s font size and x-height can tell you a lot about the typeface’s proportions with only a couple of measurements.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ex&lt;/code&gt; units get their value from the x-height of the &lt;em&gt;font context&lt;/em&gt; they’re computed in, which is determined by two things: font family and font size. In other words, they’re equal to the x-height of a specific font family at a specific font size.&lt;/p&gt;

&lt;p&gt;To illustrate this, if Helvetica Neue is set at a font size of &lt;code&gt;100px&lt;/code&gt;, then you can expect &lt;code&gt;1ex&lt;/code&gt; to equal about &lt;code&gt;52px&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img alt="Ex units equal the x-height of a typeface" src="/assets/images/typographic-units-ex-units-6ccfc9aa.svg" /&gt;&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;ex&lt;/code&gt; units in CSS is just like using any other units. You’re able to write them with any CSS property you’d use with pixels or &lt;code&gt;em&lt;/code&gt; units.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="270" scrolling="no" src="https://codepen.io/johndjameson/embed/d81ece0b6a9436654dd4777a73634005/?default-tab=results&amp;amp;height=270&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;h2 id="ch-units"&gt;Ch units&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;Ch&lt;/code&gt; units are based on the &lt;em&gt;characters&lt;/em&gt; of a typeface, drawing their value from the width of a font’s &lt;code&gt;0&lt;/code&gt; glyph. I’ll warn you that this is &lt;a href="http://meyerweb.com/eric/thoughts/2012/05/15/defining-ch/"&gt;somewhat arbitrary&lt;/a&gt;, and the width of a &lt;code&gt;0&lt;/code&gt; is often a poor estimate of a typeface’s average character width. However, when using a monospace typeface — where all glyphs share identical widths — &lt;code&gt;ch&lt;/code&gt; units are always dependable.&lt;/p&gt;

&lt;p&gt;&lt;img alt="Ch units equal a 0 character's width" src="/assets/images/typographic-units-ch-units-bc5ee525.svg" /&gt;&lt;/p&gt;

&lt;p&gt;With this constraint in mind, here are some of the use cases where I’ve found &lt;code&gt;ch&lt;/code&gt; units to be particularly useful:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Setting a container’s width&lt;/li&gt;
  &lt;li&gt;Letter-spacing text (instead of using height-based units like &lt;code&gt;em&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Creating gutters that are based on a typeface’s proportions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In the following example, I’m able to declare &lt;code&gt;max-width: 75ch&lt;/code&gt; on the paragraph element, ensuring &lt;a href="https://css-tricks.com/bookmarklet-colorize-text-45-75-characters-line-length-testing/"&gt;ideal line length&lt;/a&gt; as the user’s viewport widens.&lt;/p&gt;

&lt;iframe allowfullscreen="true" allowtransparency="true" frameborder="no" height="261" scrolling="no" src="https://codepen.io/johndjameson/embed/fbfae4fd58d5356f6b95683fb219aa38/?default-tab=results&amp;amp;height=261&amp;amp;theme-id=23596&amp;amp;embed-version=2" style="width: 100%"&gt;&lt;/iframe&gt;

&lt;h2 id="takeaways"&gt;Takeaways&lt;/h2&gt;

&lt;p&gt;I’ll admit that &lt;code&gt;ex&lt;/code&gt; and &lt;code&gt;ch&lt;/code&gt; units are more than a little weird. They’re unlike any other units CSS has to offer. Weirdness aside, these typographic units offer front-end developers a lot of opportunities to explore web typography. With any luck, I hope that &lt;code&gt;ex&lt;/code&gt; and &lt;code&gt;ch&lt;/code&gt; pave the road for additional typographic units to follow.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Data Attributes for Keyboard Shortcuts</title>
    <link rel="alternate" href="http://johndjameson.com/blog/data-attributes-for-keyboard-shortcuts/"/>
    <id>http://johndjameson.com/blog/data-attributes-for-keyboard-shortcuts/</id>
    <published>2015-03-15T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">With a little help from JavaScript, you can add a data attribute to any HTML element to instantly assign a shortcut key.</summary>
    <content type="html">&lt;p&gt;Assigning keyboard shortcuts on the web could be as simple as adding an HTML attribute onto an element and setting its value. Even though browsers are unlikely to support this approach natively, you’re still able to define shortcut keys in your markup by using &lt;code&gt;data&lt;/code&gt; attributes and a touch of JavaScript.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;data-shortcut=&lt;/span&gt;&lt;span class="s"&gt;'s'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Do Something&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;I think that’s pretty intuitive. Think about all the common use cases:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Clicking a button&lt;/li&gt;
  &lt;li&gt;Following a link&lt;/li&gt;
  &lt;li&gt;Focusing a form input&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other than scrolling past copy on code-related blog posts, these three things make up &lt;strong&gt;most of the interactions on the web.&lt;/strong&gt; Using &lt;code&gt;data&lt;/code&gt; attributes can give you an expressive, reusable syntax for assigning keyboard shortcuts to each of these use cases.&lt;/p&gt;

&lt;p&gt;Let’s go over how it works.&lt;/p&gt;

&lt;h2 id="set-up-dependencies"&gt;Set up dependencies&lt;/h2&gt;

&lt;p&gt;Before getting started, you’ll need to grab jQuery and &lt;a href="https://github.com/jeresig/jquery.hotkeys"&gt;jQuery Hotkeys&lt;/a&gt;, and link them up in your project. You can get by on your own without either library, but including them both helps simplify the code we’ll cover down below.&lt;/p&gt;

&lt;p&gt;Using &lt;a href="http://bower.io/"&gt;Bower&lt;/a&gt;, you can download a copy of each library by entering the following shell command:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax shell"&gt;&lt;code&gt;bower install jquery jquery.hotkeys &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="write-some-javascript"&gt;Write some JavaScript&lt;/h2&gt;

&lt;p&gt;Remember our three use cases? Well, in JavaScript, they translate into the following behaviors:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Triggering a &lt;code&gt;click&lt;/code&gt; event&lt;/li&gt;
  &lt;li&gt;Changing &lt;code&gt;window.location&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Giving &lt;code&gt;focus&lt;/code&gt; to an element&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With jQuery Hotkeys set up in your project, write a &lt;code&gt;$(document).ready()&lt;/code&gt; call that contains the following JavaScript:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'[data-shortcut]'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;$element&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
      &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;$element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'shortcut'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;$&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'keyup'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;$element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'focus'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;trigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'click'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;$element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;prop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'tagName'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toLowerCase&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'href'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;This code will loop through every HTML element that has a &lt;code&gt;[data-shortcut]&lt;/code&gt; attribute and attach the keyboard shortcut’s event handler. Now when you press an assigned key, the &lt;code&gt;keyup&lt;/code&gt; event will trigger both &lt;code&gt;click&lt;/code&gt; and &lt;code&gt;focus&lt;/code&gt; events on its related DOM element. Additionally, if the element is an &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tag, your browser will follow the link provided by the element’s &lt;code&gt;href&lt;/code&gt; attribute.&lt;/p&gt;

&lt;h2 id="assign-your-shortcuts"&gt;Assign your shortcuts&lt;/h2&gt;

&lt;p&gt;Your JavaScript is up and running, so you can finally start assigning keyboard shortcuts in your markup! Find an &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;button&amp;gt;&lt;/code&gt;, or &lt;code&gt;&amp;lt;input&amp;gt;&lt;/code&gt; tag that could use a shortcut, and add a &lt;code&gt;data-shortcut&lt;/code&gt; attribute with the intended key as its value.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'http://example.com/edit'&lt;/span&gt; &lt;span class="na"&gt;data-shortcut=&lt;/span&gt;&lt;span class="s"&gt;'e'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Edit&lt;span class="nt"&gt;&amp;lt;/a&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;If you want to assign a keyboard shortcut that requires pressing two or more keys at once, you’ll need to use the &lt;a href="https://github.com/jeresig/jquery.hotkeys#notes"&gt;syntax&lt;/a&gt; that jQuery Hotkeys provides. The jQuery Hotkeys &lt;a href="https://rawgit.com/jeresig/jquery.hotkeys/master/test-static-01.html"&gt;example page&lt;/a&gt; has even more key combinations.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;a&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;'/index.html'&lt;/span&gt; &lt;span class="na"&gt;data-shortcut=&lt;/span&gt;&lt;span class="s"&gt;'shift+1'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;data-shortcut=&lt;/span&gt;&lt;span class="s"&gt;'alt+m'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Menu&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;'submit'&lt;/span&gt; &lt;span class="na"&gt;data-shortcut=&lt;/span&gt;&lt;span class="s"&gt;'ctrl+alt+enter'&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;And that’s it — you’ve set up everything you need to start assigning keyboard shortcuts in your markup. &lt;em&gt;Now go forth and empower efficiency.&lt;/em&gt;&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Filtering Google Results with Alfred</title>
    <link rel="alternate" href="http://johndjameson.com/blog/filtering-google-results-with-alfred/"/>
    <id>http://johndjameson.com/blog/filtering-google-results-with-alfred/</id>
    <published>2014-08-19T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">Google offers powerful filters for search results that can help you find exactly what you're looking for&amp;mdash;it just isn't quick or easy to do. By using Alfred, you can configure these searches once and reuse them whenever you want.</summary>
    <content type="html">&lt;p&gt;Filtering search results on Google is always a bit of a hassle. The search tools are difficult to find, and once you’ve found them, you have to click each filter individually before &lt;em&gt;refreshing the page&lt;/em&gt; to enable another one. For commonly used filters or groups of filters, this can add up to be a real productivity killer. Thanks to &lt;a href="http://www.alfredapp.com/"&gt;Alfred&lt;/a&gt;, however, you can configure these filters a &lt;strong&gt;single time,&lt;/strong&gt; and then save them as a custom Web Search to use again in the future.&lt;/p&gt;

&lt;p&gt;For an introduction to Alfred check out Drew Barontini’s &lt;em&gt;excellent&lt;/em&gt; &lt;a href="http://drewbarontini.com/setup/alfred/"&gt;article&lt;/a&gt; on how to set up Aflred like a pro.&lt;/p&gt;

&lt;h2 id="adding-a-custom-search"&gt;Adding a custom search&lt;/h2&gt;

&lt;p&gt;To get started, open the &lt;code&gt;Preferences&lt;/code&gt; window in Alfred, click the &lt;code&gt;Features&lt;/code&gt; tab, and then select the &lt;code&gt;Web Search&lt;/code&gt; sidebar item. You should encounter a table of Alfred’s built-in Web Searches that you can augment by clicking &lt;code&gt;Add Custom Search&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The modal that appears will let you define a custom search URL, as well as a title and keyword to use via Alfred’s main window. Once you configure a Google search &lt;em&gt;just the way you like it&lt;/em&gt;, find the part of the URL that matches your search text and replace the words with &lt;code&gt;{query}&lt;/code&gt;. Then paste your modified URL into the &lt;code&gt;Search URL&lt;/code&gt; input field and label it to your liking.&lt;/p&gt;

&lt;p&gt;&lt;img alt="Alfred Preferences" width="854" height="491" src="/assets/images/alfred-google-past-year-049591b3.jpg" /&gt;&lt;/p&gt;

&lt;p&gt;In the example above, I’ve defined a custom Google search that filters out any web pages published more than a year ago. This idea was inspired by Olivier Lacan’s blog post &lt;a href="http://olivierlacan.com/posts/put-a-date-on-it/"&gt;Put a Date on It&lt;/a&gt; and helps me every day when searching for up-to-date information on web-related nerdery.&lt;/p&gt;

&lt;p&gt;Feel free to copy the URL below:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax plaintext"&gt;&lt;code&gt;https://www.google.com/search?q={query}&amp;amp;tbs=qdr:y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="useful-google-searches"&gt;Useful Google searches&lt;/h2&gt;

&lt;p&gt;Configuring Google searches via the website can generate some scary-looking URLs littered with unnecessary parameters. You can shorten these dramatically before adding them to Alfred, but the process involved is rarely better than Delete Things until It Breaks.™&lt;/p&gt;

&lt;p&gt;If you want to avoid that hassle altogether, here are a few more Google search URLS you can paste into Alfred and start using today.&lt;/p&gt;

&lt;h3 id="web-results"&gt;Web results&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax plaintext"&gt;&lt;code&gt;Last month:
https://www.google.com/search?q={query}&amp;amp;tbs=qdr:m

Last week:
https://www.google.com/search?q={query}&amp;amp;tbs=qdr:w

Last 24 hours (great for news and Smash Bros. rumors):
https://www.google.com/search?q={query}&amp;amp;tbs=qdr:d

Verbatim:
https://www.google.com/search?q={query}&amp;amp;tbs=li:1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h3 id="image-results"&gt;Image results&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax plaintext"&gt;&lt;code&gt;Animated GIFs:
https://www.google.com/search?q={query}&amp;amp;tbm=isch&amp;amp;tbs=ift:gif,itp:animated

Show sizes:
https://www.google.com/search?q={query}&amp;amp;tbm=isch&amp;amp;tbs=imgo:1

Labeled for reuse with modification:
https://www.google.com/search?q={query}&amp;amp;tbm=isch&amp;amp;tbs=sur:fmc
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;h2 id="keep-em-coming"&gt;Keep ‘em coming&lt;/h2&gt;

&lt;p&gt;That’s it for now, but as a &lt;a href="https://twitter.com/olivierlacan/status/501359705550495744"&gt;crazy efficiency nerd&lt;/a&gt;, I’ll make sure to add to this post whenever I think of another useful Google search. Until then, have fun experimenting with custom search URLs on different websites. For example, you could search for only Prime-eligible items on Amazon—or even tweets you’ve posted in the last month.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Updating Your Shell with Homebrew</title>
    <link rel="alternate" href="http://johndjameson.com/blog/updating-your-shell-with-homebrew/"/>
    <id>http://johndjameson.com/blog/updating-your-shell-with-homebrew/</id>
    <published>2014-07-20T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">If you haven't manually updated your version of Bash or Zsh on OS X, chances are it’s out-of-date. Here’s how to install the latest version and keep your shell updated using Homebrew.</summary>
    <content type="html">&lt;p&gt;OS X ships with an outdated version of Bash as its default shell. The preinstalled version dates back to 2007, and since then, Bash has been updated to add features and fix troublesome bugs. If you want to use an &lt;em&gt;updated&lt;/em&gt; version of Bash—or even Zsh—as your shell, you can install it by using &lt;a href="http://brew.sh/"&gt;Homebrew&lt;/a&gt;, a package manager for OS X.&lt;/p&gt;

&lt;h2 id="installing-via-homebrew"&gt;Installing via Homebrew&lt;/h2&gt;

&lt;p&gt;To get things started, you need to tell Homebrew to install the latest version of your shell. Whether you prefer using Bash or Zsh, the following instructions will work for both. Just change the word &lt;code&gt;bash&lt;/code&gt; to &lt;code&gt;zsh&lt;/code&gt;, and you’ll be good to go.&lt;/p&gt;

&lt;p&gt;Open your terminal and enter this command:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax shell"&gt;&lt;code&gt;brew install bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Homebrew installs packages to &lt;code&gt;/usr/local/bin/&lt;/code&gt;, so you’ll need to specify that path when looking for any Homebrew packages. In the following three commands, we’ll initiate a shell as the &lt;code&gt;root&lt;/code&gt; user, append our desired shell’s path to a file of whitelisted system shells, and then change the system shell globally.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo&lt;/span&gt; &lt;span class="nt"&gt;-s&lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; /usr/local/bin/bash &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /etc/shells
chsh &lt;span class="nt"&gt;-s&lt;/span&gt; /usr/local/bin/bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;Now you can close and reopen your terminal. With just those few commands, you should be using with the latest version of your shell. You can double-check the version you’re using with the command &lt;code&gt;echo $BASH_VERSION&lt;/code&gt;. Or, if you’ve installed Zsh, you can use the command &lt;code&gt;echo $ZSH_VERSION&lt;/code&gt; to do the same.&lt;/p&gt;

&lt;p&gt;That’s it for installing your brand-new shell. Let’s take a look at how to keep it &lt;em&gt;up-to-date&lt;/em&gt; with the help of Homebrew.&lt;/p&gt;

&lt;h2 id="staying-current"&gt;Staying current&lt;/h2&gt;

&lt;p&gt;The Homebrew command &lt;code&gt;update&lt;/code&gt; actually refers to updating Homebrew itself. If you want to install the latest version of a Homebrew &lt;em&gt;package&lt;/em&gt;, you’ll have to use the word &lt;code&gt;upgrade&lt;/code&gt; instead:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="syntax js-syntax shell"&gt;&lt;code&gt;brew upgrade bash
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In this example, Homebrew will look for the package named &lt;code&gt;bash&lt;/code&gt; on your computer and install the latest version. If you already have the newest version installed, Homebrew will print an error message telling you exactly that. You’ll have to run this command manually from time to time, but it’s a much more reliable approach than downloading directly from source or maintaining a cloned version control repository.&lt;/p&gt;

&lt;p&gt;Now go out and write shell scripts for &lt;a href="https://twitter.com/dandenney/status/490210755246301185"&gt;all the things&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title>Using Emmet with Sublime Text</title>
    <link rel="alternate" href="http://johndjameson.com/blog/using-emmet-with-sublime-text/"/>
    <id>http://johndjameson.com/blog/using-emmet-with-sublime-text/</id>
    <published>2014-04-27T19:00:00-05:00</published>
    <updated>2017-09-22T20:13:06-05:00</updated>
    <author>
      <name>John D. Jameson</name>
    </author>
    <summary type="html">Emmet is an invaluable time-saving tool for anyone who writes HTML and CSS. Thanks to Sublime Text, it only takes a little bit of effort to install and start using right now.</summary>
    <content type="html">&lt;p&gt;One of the biggest problems with hand-authoring HTML is the monotony of writing the common markup that surrounds content itself. While several templating languages exist to alleviate this issue, they introduce dependencies and abstractions that have a somewhat steep learning curve to master. Fortunately, a tool called Emmet walks the line between both manual and automated approaches—and has become one of the most useful additions to my workflow.&lt;/p&gt;

&lt;h2 id="what-is-emmet"&gt;What is Emmet?&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;Emmet (previously known as Zen Coding) is a web-developer’s toolkit that can
greatly improve your HTML &amp;amp; CSS workflow you can type CSS-like expressions
that can be dynamically parsed, and produce output depending on what you type
in the abbreviation. — &lt;a href="http://docs.emmet.io/"&gt;Emmet Documentation&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This means that by using Emmet we can:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Type HTML and CSS using simple shortcuts&lt;/li&gt;
  &lt;li&gt;Save time writing code&lt;/li&gt;
  &lt;li&gt;Make life easier&lt;/li&gt;
&lt;/ul&gt;

&lt;figure class="figure"&gt;
  &lt;img class="figure-image" src="/assets/images/emmet-example-1.gif" /&gt;
  &lt;figcaption class="figure-caption"&gt;Scaffolding an HTML document and common navigation using&amp;nbsp;Emmet&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;p&gt;Pretty useful, right? Let’s find out how to install it using Sublime Text.&lt;/p&gt;

&lt;h2 id="installing-plugins"&gt;Installing plugins&lt;/h2&gt;

&lt;p&gt;Sublime Text has an amazing add-on called &lt;strong&gt;Package Control&lt;/strong&gt; that lets you find and install virtually &lt;em&gt;any&lt;/em&gt; plug-in from within the application itself. The line of code to install Package Control changes with every release, so you’ll have to copy it directly from the &lt;a href="https://sublime.wbond.net/installation"&gt;offcial website&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you have the snippet for your version of Sublime, launch the program and show the Console (&lt;kbd&gt;&amp;#x2318;+`&lt;/kbd&gt; on OS X). Paste the intended code, hit &lt;kbd&gt;Enter&lt;/kbd&gt;, then watch Package Control install itself like magic.&lt;/p&gt;

&lt;p&gt;With Package Control installed, you can download additional plug-ins by opening the Command Palette (&lt;kbd&gt;Shift+&amp;#x2318;+P&lt;/kbd&gt; on OS X) and typing “Install Package” and then submitting the top result. A similar menu opens next, revealing the list of packages available for installation. Type “Emmet” here and choose the top result.&lt;/p&gt;

&lt;figure class="figure"&gt;
  &lt;img class="figure-image" src="/assets/images/emmet-example-2.gif" /&gt;
  &lt;figcaption class="figure-caption"&gt;Installing Emmet using Package Control&lt;/figcaption&gt;
&lt;/figure&gt;

&lt;h2 id="using-emmet"&gt;Using Emmet&lt;/h2&gt;

&lt;p&gt;Now that we have Emmet installed, we can finally start having fun with some of its incredible shortcuts. The formula for using Emmet is very straightforward:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Type a supported shortcut&lt;/li&gt;
  &lt;li&gt;Press &lt;kbd&gt;Tab&lt;/kbd&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And that’s it! Check out some of the most useful &lt;a href="http://docs.emmet.io/cheat-sheet/"&gt;shortcuts&lt;/a&gt; you can start using right now.&lt;/p&gt;

&lt;h2 id="getting-better"&gt;Getting better&lt;/h2&gt;

&lt;p&gt;If you’re like me, getting up to speed with new tools is an endless struggle. Fortunately, Emmet is &lt;em&gt;completely optional&lt;/em&gt; once installed and you can ignore all of its features until &lt;strong&gt;you&lt;/strong&gt; want to use them. This makes mastering Emmet as flexible as gradually adding shortcuts to your workflow when you need them. Start with the shorthand for a class or ID, for example, and then build up from there, learning more ambitious shortcuts along the way.&lt;/p&gt;

&lt;p&gt;You can visit the &lt;a href="http://docs.emmet.io/"&gt;official documentation&lt;/a&gt; to discover &lt;em&gt;all&lt;/em&gt; of Emmet’s features, or if that isn’t your cup of tea, CSS-Tricks’ Chris Coyier has a sweet &lt;a href="http://css-tricks.com/video-screencasts/129-emmet-awesome/"&gt;screencast&lt;/a&gt; covering the basics along with everything else you’ll need to know.&lt;/p&gt;

</content>
  </entry>
</feed>
