Watch a video tutorial on the Storybook channel
The Viewport toolbar item allows you to adjust the dimensions of the iframe your story is rendered in. It makes it easy to develop responsive UIs.
Out of the box, the Viewport addon offers you a standard set of viewports that you can use.
The viewport global can take an object with the following keys:
|defaultViewport||String||Sets the default viewport|
|defaultOrientation||String||Sets the default orientation (e.g. portrait or landscape)|
|disable||Boolean||Disables the viewport||N/A|
|viewports||Object||The configuration object for the viewport|
The viewports object needs the following keys:
|name||String||Name for the viewport|
|styles||Object||Sets Inline styles to be applied to the story|
|type||String||Type of the device (e.g. desktop, mobile, or tablet)|
By default, Storybook uses a minimal set of viewports to get you started. But you're not restricted to these. The addon offers a more granular list of devices that you can use.
.storybook/preview.js to the following:
Start your Storybook, and you'll see the new devices that you can use.
See here the complete list of devices and their configurations.
If you have either a specific viewport or a list of viewports that you need to use, you can modify your
.storybook/preview.js file and include them:
Make the following change to use them in your Storybook:
Once you start Storybook, you'll see your new viewports and devices.
If you need, you can also add these two to another list of viewports.
For instance, if you want to use these two with the minimal set of viewports, you can do it like so:
Both viewports (
Kindle Fire 2 and
Kindle Fire HD) will feature in the list of devices by merging them into the
There are cases where it's not practical for you to use a specific visual viewport on a global scale, and you need it to adjust it to an individual story.
Update your story through parameters to include your viewports at a component level or for a specific story:
- Previous viewport: shift + v
- Next viewport: v
- Reset viewport: alt + v
If you need, you can edit them on the shortcuts page.