Automatic visual tests in Storybook, plus 2.2x faster build times for React+TSVisual test with Chromatic


Watch a video tutorial on the Storybook channel

The Source block is used to render a snippet of source code directly.

Screenshot of Source block


Configuring with props and parameters

ℹ️ Like most blocks, the Source block is configured with props in MDX. Many of those props derive their default value from a corresponding parameter in the block's namespace,

The following language configurations are equivalent:

The example above applied the parameter at the story level, but it could also be applied at the component (or meta) level or project level.


Type: string


Provides the source code to be rendered.


Type: boolean


Determines if the snippet is rendered in dark mode.

💡 Light mode is only supported when the Source block is rendered independently. When rendered as part of a Canvas block—like it is in autodocs—it will always use dark mode.


Type: boolean | 'dedent' | BuiltInParserName

Default: or true

Specifies the formatting used on source code. Both true and 'dedent' have the same effect of removing any extraneous indentation. Supports all valid prettier parser names.



Default: or 'jsx'

Specifies the language used for syntax highlighting.


Type: Story export

Specifies which story's source is rendered.


Type: (code: string, storyContext: StoryContext) => string


A function to dynamically transform the source before being rendered, based on the original source and any story context necessary. The returned string is displayed as-is. If both code and transform are specified, transform will be ignored.


Type: 'auto' | 'code' | 'dynamic'

Default: or 'auto'

Specifies how the source code is rendered.

  • auto: Same as dynamic, if the story's render function accepts args inputs and dynamic is supported by the framework in use; otherwise same as code
  • code: Renders the value of code prop, otherwise renders static story source
  • dynamic: Renders the story source with dynamically updated arg values

💡 Note that dynamic snippets will only work if the story uses args and the Story block for that story is rendered along with the Source block.


(⛔️ Deprecated)

Type: string

Specifies the story id for which to render the source code. Referencing a story this way is no longer supported; use the of prop, instead.


(⛔️ Deprecated)

Type: string[]

Specifies the story ids for which to render source code. Multiple stories are no longer supported; to render a single story's source, use the of prop.

Was this page helpful?

Markdown accepted ([link text](url), _italic_, **bold**, etc). Your anonymous feedback will be posted publicly on GitHub.

✍️ Edit on GitHub – PRs welcome!
Join the community
6,326 developers and counting
WhyWhy StorybookComponent-driven UI
Open source software

Maintained by
Special thanks to Netlify and CircleCI