Skip to main content
The @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
The main 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.
Available Components:
With Custom Props:

Hooks

useThemedStylesWithMdx

A hook that wraps MDX components with styles from theme.styles.
Signature:
Features:
  • Applies styles from theme.styles to MDX components
  • Merges with custom components you provide
  • Preserves component functionality
  • Works with @mdx-js/react v2+

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

Use Themed 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/react as a peer dependency
  • Requires @types/mdx for TypeScript support
  • The Themed components support the sx prop
  • All components forward refs properly
  • No side effects - safe for tree-shaking

Examples

Blog Post

Documentation Page