Configure Storybook with Global Stylesheets and Fonts

Michael Chan
InstructorMichael Chan
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated 2 months ago

Ensure your Storybook environment mirrors your production setup. Learn to add global stylesheets and fonts, creating a consistent look and feel across your project and component library.

[00:00] Most apps component libraries and design systems will have some type of global CSS even if it's just a reset like this. To add that reset to Storybook, open the Storybook preview module where we can simply import this. Import source assets [00:20] reset dot CSS. The import syntax that you use here is dependent on your module bundler. In this case, I'm using Vite, but webpack is also supported. We can ensure that this worked by adding something, egregious. Background color blue violet? It's ugly [00:40] but at least we know that our reset is getting loaded. Okay. Let's talk about fonts. Oftentimes if we load a font from a CDM like a Google Fonts, we get this HTML. So how can we add that into our storybook? Back to storybook, locate the storybook preview [01:00] module and add a preview dash head dot HTML. In this file, we can insert any HTML tags that we want into our document. Let's save that and restart our Storybook dev server. Now in any of our [01:20] CSS files we can use that font. Font family, enter. Now I know that these components have this defined in the CSS. This will vary depending on your components. However, I'm gonna change this font to enter so we can see the change.

egghead
egghead

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