Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Create beautiful web typography with Typography.js in Gatsby

    Artem SapeginArtem Sapegin

    Learn how to define typography styles for Gatsby sites with Typography.js. You’ll learn how to setup Typography.js with Gatsby using gatsby-plugin-typography, how to use Typography.js themes to improve styles of your site, and how to create your own themes.

    This lesson is compatible with Gatsby v1 and v2.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: First, install gatsby-plugin-typography and its peer dependencies react-typography and typography js. Then, add the plugin to your Gatsby config file. If you're using the Gatsby default starter, you need to remove its default styles from layout js file.

    Run Gatsby, and you can see that your site is now using the default typography js theme. Now, go to typography js site and choose one of the many themes. I like the Lincoln theme.

    Go back to your terminal and start it from npm. Create a new file, typography js, import typography and our theme. Create a typography instance with our theme. Now, go back to your Gatsby config and point the typography plugin to our new file.

    Restart Gatsby. Now, our site is using the Lincoln theme, but look at the header. Something is wrong here. Let's have a look at the browser developer tools. Aha, they used text shadow to remove link underlines around letter descenders. Let's get rid of it.

    Typography js theme is an object with various typography js options like base font size or baseline height. We can overwrite any of them in our typography js file.

    For example, header color. You need to restart Gatsby to see your changes. Our text shadow thing is more tricky. Here it is in the Lincoln theme. It's inside overrideStyles function.

    If we override it, we'll replace everything this function returns here, which is not what we want. Luckily, typography js has another function called overrideThemeStyles, which does exactly what we want.

    Everything this function returns will be merged with style overrides from the original theme. Here it is. The header looks nice. Of course, you can create your own theme for typography js.

    Everything you return here will be merged with the default typography js theme.