Docs » Configure » Integration » Images and assets
Images, fonts, and assets
Components often rely on images, videos, fonts, and other assets to render as the user expects. There are many ways to use these assets in your story files.
You can import any media assets by importing (or requiring) them. It works out of the box with our default config. But, if you are using a custom webpack config, you’ll need to add the file loader to handle the required files.
We recommend serving static files via Storybook to ensure that your components always have the assets they need to load. We recommend this technique for assets that your components often use, like logos, fonts, and icons.
Configure a directory (or a list of directories) where your assets live when starting Storybook. Use the staticDirs configuration element in your main Storybook configuration file (i.e., .storybook/main.js|ts) to specify the directories:
.storybook/main.ts
Here ../public is your static directory. Now use it in a component or story like this.
MyComponent.stories.ts|tsx
You can also pass a list of directories separated by commas without spaces instead of a single directory.
.storybook/main.ts
Or even use a configuration object to define the directories:
Sometimes, you may want to deploy your Storybook into a subpath, like https://example.com/storybook.
In this case, you need to have all your images and media files with relative paths. Otherwise, the browser cannot locate those files.
If you load static content via importing, this is automatic, and you do not have to do anything.
Suppose you are serving assets in a static directory along with your Storybook. In that case, you need to use relative paths to load images or use the base element.
After configuring Storybook to serve assets from your static folder, you can reference those assets in Storybook. For example, you can reference and apply a custom font to your stories. To do this, create a preview-head.html file inside the configuration directory (i.e., .storybook) and add a <link /> tag to reference your font.