MDX Documentation Example
MDX allows you to use JSX components directly in Markdown. Write interactive docs with live examples, custom components, and rich formatting.
What is MDX?
MDX is a format that combines Markdown and JSX. It allows you to import and use React components directly in your markdown content, making it perfect for interactive documentation.
Key Features
- Write in Markdown syntax
- Import and use React components
- Create interactive examples
- Syntax highlighting for code blocks
- Fully typed with TypeScript
Using Components in MDX
You can import and use any React component directly in MDX:
MDX makes it easy to embed interactive components within your documentation.
Code Example
Here's how the card above was created:
<Card>
<CardHeader>
<CardTitle>Example Card Component</CardTitle>
<CardDescription>
This card is rendered using the Card component
</CardDescription>
</CardHeader>
<CardContent>
<p>MDX makes it easy to embed components!</p>
</CardContent>
</Card>Interactive Demos
Create live, interactive examples with full functionality:
Interactive Button Demo
Click the button to see it in action
Alerts and Callouts
Use custom components to create rich callouts:
Tabs for Multi-part Content
Getting Started
MDX combines the simplicity of Markdown with the power of React components. Perfect for documentation, blogs, and content-rich websites.
Inline Components
You can also use inline components like NEW or BREAKING directly within text.
Try combining multiple components:
Code Blocks with Syntax Highlighting
MDX supports code blocks with syntax highlighting:
TypeScript Example
import type { MDXComponents } from 'mdx/types';
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
h1: ({ children }) => (
<h1 className="text-3xl font-bold">{children}</h1>
),
...components,
};
}React Component Example
// React Component Example
export default function MyComponent() {
const [count, setCount] = useState(0);
return (
<button onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
);
}CSS Example
/* CSS Example */
.custom-class {
display: flex;
align-items: center;
gap: 1rem;
padding: 1rem;
border-radius: 0.5rem;
background: hsl(var(--primary));
}Tables
| Feature | Markdown | MDX | HTML |
|---|---|---|---|
| Easy to write | ✅ | ✅ | ❌ |
| Components | ❌ | ✅ | ✅ |
| Interactive | ❌ | ✅ | ✅ |
| Type-safe | ❌ | ✅ | ❌ |
Lists
Unordered List
- First item
- Second item with bold text
- Third item with
code - Nested item 1
- Nested item 2
- Fourth item with a link
Ordered List
- Step one: Install dependencies
- Step two: Configure the project
- Step three: Start building
- Step four: Deploy to production
Blockquotes
This is a blockquote. Use it to emphasize important information or quotes.
You can have multiple paragraphs in a blockquote.
Note: MDX supports all standard Markdown syntax including bold, italic, bold italic,
inline code, and links.
Advantages of MDX
Conclusion
MDX is a powerful tool for creating interactive documentation. It combines the simplicity of Markdown with the flexibility of React components, making it perfect for:
- Documentation sites - Create living docs with working examples
- Blog posts - Add interactive elements to enhance your content
- Tutorial content - Build step-by-step guides with embedded demos
- Component showcases - Display components with live previews
Ready to start? Check out the official MDX documentation for more information!