When working with Storybook, I wanted my component previews to take up the entire viewport height. But by default, the preview area doesn’t always stretch to fit the full screen. After trying a few different approaches, I found the simplest and most reliable way to achieve this.
Thank me by sharing on Twitter 🙏
Here’s how to make sure your Storybook preview always fills the full height of the browser window.
Use a Decorator to Force Full Height
The best way to handle this is by wrapping every story in a container that explicitly sets its height to 100vh
. Storybook provides a decorator feature, which makes it easy to apply this to all stories globally.
In your .storybook/preview.js
or .storybook/preview.ts
, add the following:
import { Decorator } from '@storybook/react';
export const decorators: Decorator[] = [
(Story) => (
<div style={{ height: '100vh', display: 'flex', flexDirection: 'column' }}>
<Story />
</div>
),
];
This ensures that every story renders inside a full-height container, no matter how your components are structured.
USB C to Lightning Cable 3FT 2Pack [Apple MFi Certified], Power Delivery iPhone Cables Type C iPhone Charger Cord Fast Charging Compatible iPhone 14 13 12 11 Pro Max X XS XR 8 7 6s Plus SE
$5.59 (as of March 13, 2025 13:36 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display, 1 x Powered USB-C 5Gbps & 2×Powered USB-A 3.0 5Gbps Data Ports for MacBook Pro, MacBook Air, Dell and More
$24.99 (as of March 13, 2025 13:36 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Highwings 8K 10K 4K HDMI Cable 48Gbps 6.6FT/2M, Certified Ultra High Speed HDMI Cable Braided Cord-4K@120Hz 8K@60Hz, DTS:X, HDCP 2.2 & 2.3, HDR 10 Compatible with Roku TV/PS5/HDTV/Blu-ray
$9.99 (as of March 13, 2025 13:36 GMT +00:00 - More infoProduct prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on [relevant Amazon Site(s), as applicable] at the time of purchase will apply to the purchase of this product.)Why This Works Best
I initially tried adjusting global styles using CSS, but Storybook’s internal styles sometimes override them. Similarly, modifying Storybook’s layout settings wasn’t necessary with recent versions. The decorator method avoids those issues and works consistently across different setups.
Ensuring Components Expand Correctly
For this to work as expected, the components themselves need to support full-height layouts. If a component is nested inside a parent without a defined height, it might not stretch properly. Adding height: 100%
to your component’s container can help:
.your-component {
height: 100%;
}
Wrapping Up
Using a decorator is the cleanest and most effective way to make Storybook previews fill the entire viewport. It doesn’t rely on modifying Storybook’s internals, and it ensures every story has the right layout without extra configuration.
This approach has worked well for me, and I hope it makes your Storybook experience smoother too.