There are many ways to include CSS in a web application, and correspondingly there are many ways to include CSS in Storybook. Usually, it is best to try and replicate what your application does with styling in Storybook’s configuration. To make this easier, we recommend using
Storybook is pre-configured to recognize imports for CSS files. To add global CSS for all your stories, import it in
If your component files import their CSS files, this will work too. The noticeable exception to this is if you're using CSS processor tools like Sass or Postcss.
If you're using Vite as your builder, you're covered! Vite supports Sass and PostCSS out-of-the-box 🎉
However, if you're using Webpack and want to use Sass and PostCss, you'll need some extra configuration. We recommend installing
@storybook/addon-styling to help you configure these tools. Or if you'd prefer, you can customize Storybook's webpack configuration yourself to include the appropriate loader(s).
If you need webfonts to be available, you may need to add some code to the
.storybook/preview-head.html file. We recommend including any assets with your Storybook if possible, in which case you likely want to configure the static file location.
The latest Angular releases introduced significant changes in configuring and styling projects. If you're working with an Angular version greater than 13 and your styles aren't being applied, you may need to check your
angular.json ad adjust the
builder configuration to import your CSS:
Additionally, if you need Storybook-specific styles that are separate from your application, you can configure the styles with Storybook's custom builder, which will override the application's styles:
If you're working with Storybook and Nx libraries,
you can extend your project's configuration (i.e.,
project.json) and provide the application's styles.
For earlier Nx versions (before
14.1.8), your configuration would look like this:
Starting with version
14.1.8, Nx uses the Storybook builder directly, which means any configuration supplied to the builder also applies to the NX setup. If you're working with a library, you'll need to configure the styling options ( e.g., preprocessors) inside the
options configuration object. For example:
When Nx runs, it will load Storybook's configuration and styling based on