@theme-ui/mdx package provides utilities for integrating Theme UI with MDX. It includes the Themed component dictionary and hooks for applying theme styles to MDX content.
Installation
When to Use
Use@theme-ui/mdx when you:
- Are using MDX in your project
- Want to style MDX content with theme styles
- Need to use theme styles outside of MDX
- Want to provide consistent typography throughout your app
theme-ui package re-exports everything from this package.
Exports
Components
Themed
A dictionary of HTML components that automatically pick up styles from theme.styles.
Hooks
useThemedStylesWithMdx
A hook that wraps MDX components with styles from theme.styles.
- Applies styles from
theme.stylesto MDX components - Merges with custom components you provide
- Preserves component functionality
- Works with
@mdx-js/reactv2+
Utilities
themed
A utility function to create themed components.
defaultMdxComponents
The default set of MDX components used by Theme UI.
Usage with MDX
Basic Setup
With Custom Components
Styling MDX Content
Define styles in your theme:Use Cases
Outside MDX
UseThemed components anywhere, not just in MDX:
Consistent Typography
Ensure consistent typography across MDX and regular JSX:Custom Wrapper
TypeScript Types
Type Usage
Notes
- Works with MDX v2 and later
- Requires
@emotion/reactas a peer dependency - Requires
@types/mdxfor TypeScript support - The
Themedcomponents support thesxprop - All components forward refs properly
- No side effects - safe for tree-shaking
Examples
Blog Post
Documentation Page
Related
- MDX Documentation
- @theme-ui/core - Core Theme UI functionality
- Theme Specification - Defining theme.styles
- MDX Guide - Full MDX integration guide
