Create beautiful web typography with Typography.js in Gatsby

Artem Sapegin
InstructorArtem Sapegin
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

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.

Instructor: [00:00] 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.

[00:15] 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.

[00:33] 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.

[00:56] 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.

[01:14] 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.

[01:25] 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.

[01:41] 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.

[01:55] 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.

[02:08] Everything you return here will be merged with the default typography js theme.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today