DBMS Topics
Complete MDX Cheatsheet
title: "Complete MDX Cheatsheet",
Bookmark this. Come back when you forget a syntax. That's what it's here for.
Markdown Syntax Reference
Text Formatting
| Syntax | Output | HTML |
|---|---|---|
bold | bold | <strong> |
*italic* | *italic* | <em> |
~~strikethrough~~ | ~~strikethrough~~ | <del> |
` inline code ` | inline code | <code> |
link | link | <a href> |
!alt | Image | <img> |
Headings
# Heading 1 → <h1>
## Heading 2 → <h2>
### Heading 3 → <h3>
#### Heading 4 → <h4>
##### Heading 5 → <h5>
###### Heading 6 → <h6>Heading 1 (largest, page title) Heading 2 (section title) Heading 3 (subsection) Heading 4 (small section) Heading 5 (fine detail) Heading 6 (smallest)
Lists
Blockquotes
> Single line quote
> Multi-line quote
> continues on the next line.
>
> New paragraph in the same quote.Code Blocks
const x = 42;
function App() { return <h1>Hello</h1>; }
npm install @mdx-js/react
Tables
| Left-aligned | Center-aligned | Right-aligned |
|:-------------|:--------------:|--------------:|
| Cell 1 | Cell 2 | Cell 3 |
| Cell 4 | Cell 5 | Cell 6 |Horizontal Rule
Accessing Frontmatter
---
title: "My Page"
author: "Jane Doe"
---
export const meta = frontmatter;
# {frontmatter.title}
Written by {frontmatter.author}Import / Export Syntax
Import Patterns
Export Patterns
{/* Export metadata */}
export const meta = {
title: "My Page",
publishedAt: "2024-01-15"
};
{/* Export functions */}
export function getStaticProps() {
return { props: { data: fetchData() } };
}
{/* Export constants for use in the document */}
export const version = "3.0.0";
# Release Notes v{version}
{/* Export layout (framework-specific) */}
export { default as Layout } from '../layouts/Docs';Expression Syntax
Using Expressions in MDX
Curly braces {} let you drop JavaScript expressions anywhere in your content:
Expression Limitations
The big gotcha: you can only use *expressions*, not *statements*.
Common Component Patterns
Callout / Admonition
<Callout type="info" title="Note">
This is informational content.
</Callout>
<Callout type="warning">
Be careful with this approach.
</Callout>
<Callout type="error" title="Breaking Change">
This API was removed in v3.0.
</Callout>Tabs
npm install @mdx-js/react ``` </Tab> <Tab>
pnpm add @mdx-js/react
</Tab>
</Tabs>Collapsible / Accordion
<details>
<summary>Click to expand</summary>
Hidden content with **Markdown** support.
- List items work
- Inside details elements
</details>Steps / Stepper
<Steps>
<Step title="Install dependencies">npm install @mdx-js/react @mdx-js/mdx
</Step>
<Step title="Configure bundler">
Add the MDX plugin to your build config.
</Step>
<Step title="Create your first .mdx file">
Start writing MDX content!
</Step>
</Steps>Code with Preview
<CodePreview><button className="btn btn-primary"> Click me </button>
</CodePreview>MDX Configuration Quick Reference
Next.js
Vite
Astro
Key Rules to Remember
These will save you from the most common mistakes:
| Rule | Details |
|---|---|
| One H1 per file | Title comes from the single # heading |
| Close all tags | <br /> not <br> |
| JSX comments only | {/* comment */} not <!-- comment --> |
| Imports at top | After frontmatter, before content |
| Blank lines matter | Separate components from Markdown with blank lines |
| Expressions only | No statements (if, for) inside {} |
className not class | React attribute names in JSX |
| Escape curly braces | Use {'{'} or backticks for literal { |
No < in text | Use backticks or < for angle brackets |
| Case-sensitive components | <alert> ≠ <Alert> (lowercase = HTML) |
File Structure Template
When in doubt, structure your MDX file like this:
---
title: "Page Title"
description: "Brief description"
---
import { Component } from '../components/Component';
export const metadata = { custom: 'data' };
# Page Title
Introduction paragraph.
## First Section
Content with <Component prop="value">children</Component>.
## Second Section
More content with expressions: {1 + 1}
## Summary
Closing thoughts.That's the whole MDX syntax in one page. Keep it handy.
Exam Focus
Revise definitions, diagrams, examples, and short-answer points for Complete MDX Cheatsheet.
Interview Use
Prepare one clear explanation, one practical example, and one common mistake for this MDX topic.
Search Terms
mdx, mdx tutorial, learn mdx, markdown, jsx, tutorial, resources, cheatsheet
Related MDX Topics