MDX Component
Heading
<h1>**Hello**, This Is a _Title_ Inside `h1`</h1>
{/* using html tag to avoid being rendered in the sidebar */}
Hello, This Is a Title Inside h1
<h2>**Hello**, This Is a _Title_ Inside `h2`</h2>
{/* using html tag to avoid being rendered in the sidebar */}
Hello, This Is a Title Inside h2
### **Hello**, This Is a _Title_ Inside `h3`
Hello, This Is a Title Inside h3
#### **Hello**, This Is a _Title_ Inside `h4`
Hello, This Is a Title Inside h4
##### **Hello**, This Is a _Title_ Inside `h5`
Hello, This Is a Title Inside h5
###### **Hello**, This Is a _Title_ Inside `h6`
Hello, This Is a Title Inside h6
Text
With Nextra, all your `.md` and `.mdx` files under the pages directory will be rendered with [MDX](https://mdxjs.com/about), it's an
advanced Markdown format with React component support.
With Nextra, all your .md
and .mdx
files under the pages directory will be rendered with MDX (opens in a new tab), it's an
advanced Markdown format with React component support.
Text Variant
**bold**
__bold__
bold
**_italicized bold_**
***italicized bold***
___italicized bold___
italicized bold
_italicized_
*italicized*
italicized
~~strikethrough.~~
strikethrough.
Emoji ⛺
Emoji Docs (opens in a new tab) 😂
⚠️ ⛔ ✅ ☑️ ✔️ ❌ 🚀 ⏱️ 💻 📁 🔒 🛠️ 📢 🔔 💡 📓 📆 🌄 🌇 🌍 🌒 ⚡ ❄️ 🔥 ⭐☀️
Line Separator
---
***
Image
External URL :

Static Image URL :
If the demo.png
file is located at /public/demo.png
, you can use the code below to display it:

Static Next/Image :
You can use Next.js Image (opens in a new tab) directly in MDX.
If the demo.png
file is located at /public/demo.png
, you can use the code below to display it:
import Image from "next/image";
<Image src="/demo.png" alt="Hello" className="rounded-lg" width={500} height={300} />;

Link
Autolink literals
www.example.com, https://example.com, and contact@example.com.
www.example.com (opens in a new tab), https://example.com (opens in a new tab), and contact@example.com.
[MDX](https://mdxjs.com/about), it's an external link
MDX (opens in a new tab), it's an external link
[Index](/), it's an internal link
Index, it's an internal link
You can optionally add a title for a link. This will appear as a tooltip when the user hovers over the link. To add a title, enclose it in quotation marks after the URL.
[MDX](https://mdxjs.com/about "MDX Documentation"), Documentation
MDX (opens in a new tab), Documentation
List
1. one
2. two
3. three
- one
- two
- three
1. First item
2. Second item
3. Third item
1. Indented item
2. Indented item
4. Fourth item
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item
- one
- two
- three
- one
- two
- three
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item
1. First item
2. Second item
3. Third item
- Indented item
- Indented item
4. Fourth item
- First item
- Second item
- Third item
- Indented item
- Indented item
- Fourth item
* asterisks for unordered items
1. decimals and a dot for ordered items
- asterisks for unordered items
- decimals and a dot for ordered items
* Next
* docs
- Next
- docs
+ Next
+ docs
- Next
- docs
- Next
- docs
- Next
- docs
Task List
- [x] Write the press release
- [ ] Update the website
- [ ] Contact the media
- Write the press release
- Update the website
- Contact the media
Syntax Highlighting
Automatically syntax highlighting:
```js filename="index.mdx" copy
console.log("hello, world");
```
Renders:
console.log("hello, world");
Inlined Code
You can use \`content\` to wrap inline code content like: `let x = 1`.
You can use `content` to wrap inline code content like: let x = 1
.
Inlined syntax highlighting like let x = 1
is also supported via the {:}
syntax:
Inlined syntax highlighting is also supported `let x = 1{:jsx}` via:
Highlighting Lines
You can also add the {line number, line number-line number}
modifier to highlight specific lines:
```jsx filename="index.mdx" {4, 7-8}
import useSWR from "swr";
function Profile() {
const { data, error } = useSWR("/api/user", fetcher);
if (error) return <div>failed to load</div>;
if (!data) return <div>loading...</div>;
return <div>hello {data.name}!</div>;
}
```
import useSWR from "swr";
function Profile() {
const { data, error } = useSWR("/api/user", fetcher);
if (error) return <div>failed to load</div>;
if (!data) return <div>loading...</div>;
return <div>hello {data.name}!</div>;
}
Highlighting Substrings
You can highlight specific substrings of code by adding a //
attribute to the code block:
```js /useState/
import { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
```
import { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
You can highlight only a part of the occurrences of that substring by adding a number it: /str/1
, or multiple: /str/1-3
, /str/1,3
.
Line Numbers
You can add line numbers to your code blocks by adding a showLineNumbers
attribute:
```js showLineNumbers
import { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
```
Renders:
import { useState } from 'react'
function Counter() {
const [count, setCount] = useState(0)
return <button onClick={() => setCount(count + 1)}>{count}</button>
}
Copy Button
By adding a copy attribute, a copy button will be added to the code block when the user hovers over it:
```js copy
console.log('hello, world')
```
console.log('hello, world')
Diff Code
```diff filename="index.mdx"
- import { useSWRInfinite } from 'swr'
+ import useSWRInfinite from 'swr/infinite'
```
- import { useSWRInfinite } from 'swr'
+ import useSWRInfinite from 'swr/infinite'
Blockquote
> Where some people measure progress in answers-right per test or tests-passed per year, we are more interested in Sistine-Chapel-Ceilings per Lifetime.
>
> — Alan Kay, A Personal Computer for Children of All Ages
Where some people measure progress in answers-right per test or tests-passed per year, we are more interested in Sistine-Chapel-Ceilings per Lifetime.
— Alan Kay, A Personal Computer for Children of All Ages
Nested quotes:
> > Where some people measure progress in answers-right per test or tests-passed per year, we are more interested in Sistine-Chapel-Ceilings per Lifetime.
> >
> > — Alan Kay, A Personal Computer for Children of All Ages
>
> This is **great**.
>
> — Shu Ding.
Where some people measure progress in answers-right per test or tests-passed per year, we are more interested in Sistine-Chapel-Ceilings per Lifetime.
— Alan Kay, A Personal Computer for Children of All Ages
This is great.
— Shu Ding.
Table
| Left | Center | Right |
| :--- | :----: | ----: |
| Left-aligned | Center-aligned | Right-aligned |
Left | Center | Right |
---|---|---|
Left-aligned | Center-aligned | Right-aligned |
| Syntax | Description | Test Text |
| :----------- | :---------: | --------: |
| Header | Title | Here's this |
| Paragraph | Text | And more |
| Strikethrough | | ~~Text~~ |
Syntax | Description | Test Text |
---|---|---|
Header | Title | Here's this |
Paragraph | Text | And more |
Strikethrough |
| Badge | Description | Code | Icon |
| :- | :-: | :-: | -: |
| <Badge>Default</Badge> | Default | <span className="font-semibold text-blue-500">100</span> | ☑️ |
| <Badge variant="success">Success</Badge> | Success | <span className="font-semibold text-green-500">200</span> | ✅ |
| <Badge variant="info">Warning</Badge> | Warning | <span className="font-semibold text-orange-500">400</span> | ⚠️ |
| <Badge variant="danger">Danger</Badge> | Danger | <span className="font-semibold text-red-500">500</span> | ⛔ |
Badge | Description | Code | Icon |
---|---|---|---|
Default | Default | 100 | ☑️ |
Success | Success | 200 | ✅ |
Warning | Warning | 400 | ⚠️ |
Danger | Danger | 500 | ⛔ |
React Components
React components and Markdown can be mixed together, for instance:
Default
Space Invaders is a 1978 shoot 'em up arcade game developed by Tomohiro Nishikado.
import Callout from "nextra-theme-docs/callout";
<Callout emoji="👾">
**Space Invaders** is a 1978 shoot 'em up arcade game developed by Tomohiro
Nishikado.
</Callout>
Warning
This API will be deprecated soon.
import Callout from "nextra-theme-docs/callout";
<Callout type="warning" emoji="⚠️">
This API will be deprecated soon.
</Callout>
Error
This is a dangerous feature that can cause everything to explode.
import Callout from "nextra-theme-docs/callout";
<Callout type="error" emoji="️🚫">
This is a dangerous feature that can cause everything to explode.
</Callout>
>
<Callout>
> Give [**Next Docs**](https://github.com/wahidari/next-docs-v2) a star! >
</Callout>
Renders:
💡Give Next Docs (opens in a new tab) a star!
Embed Iframe
<iframe
width="100%"
height="430"
src="https://www.youtube.com/embed/3hccXiXI0u8"
frameBorder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowFullScreen
/>
<iframe
src="https://codesandbox.io/embed/swr-states-4une7"
width="100%"
height="500px"
title="SWR-States"
></iframe>
Footnote
A note1
Here's a simple footnote,2 and here's a longer one.3