# Fumadocs (Framework Mode, Next.js): Markdown
URL: /docs/next/markdown
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/(framework)/[framework]/markdown/index.mdx

How to write documents

## Introduction [#introduction]

Fumadocs provides many useful extensions to MDX, a markup language. Here is a brief introduction to the default MDX syntax of Fumadocs.

> MDX is not the only supported format of Fumadocs. In fact, you can use any renderer such as headless CMS.
>
> See [Custom Content Source](/docs/next/integrations/content/custom) for details.

## MDX [#mdx]

We recommend MDX, a superset of Markdown with JSX syntax.
It allows you to import components, and use them in the document, or even writing JavaScript.

See:

- [MDX Syntax](https://mdxjs.com/docs/what-is-mdx/#mdx-syntax).
- GFM (GitHub Flavored Markdown) is also supported, see [GFM Specification](https://github.github.com/gfm).

```mdx noCopy
import { Component } from './component';

<Component name="Hello" />

## Heading

### Heading

#### Heading

Hello World, **Bold**, _Italic_, ~~Hidden~~

1. First
2. Second
3. Third

- Item 1
- Item 2

> Quote here

![alt](/image.png)

| Table | Description |
| ----- | ----------- |
| Hello | World       |
```

### Frontmatter [#frontmatter]

Fumadocs support YAML-based frontmatter by default, `title` represents the page title (`h1`) in Fumadocs UI.

```mdx
---
title: This is a document
---

...
```

For this reason, h1 title (`# Heading`) is usually unused when writing Markdown/MDX unless you have custom logic for page title rendering.

When your content source supports it, you can also export frontmatter in code. It is merged over the YAML frontmatter, and can read [props](#props):

```mdx
---
title: Deploy
---

export const frontmatter = {
  description: `Deploy your ${props.framework} site.`,
};
```

<Callout title="In Fumadocs MDX">
You can use the [`schema`](/docs/mdx/collections#schema-1) option to add frontmatter properties. See [Customize Frontmatter](/docs/mdx#customize-frontmatter) for details.
</Callout>

### Auto Links [#auto-links]

Internal links use the `<Link />` component of your React framework to allow prefetching and avoid hard-reload.

External links will get the default `rel="noreferrer noopener" target="_blank"` attributes for security.

```mdx
[My Link](https://github.github.com/gfm)

This also works: https://github.github.com/gfm.
```

### Cards [#cards]

Useful for adding links.

```mdx
import { HomeIcon } from 'lucide-react';

<Cards>
  <Card href="/docs" title="Documentation">
    Browse the full documentation.
  </Card>
  <Card title="href is optional">Cards can hold plain content too.</Card>
  <Card icon={<HomeIcon />} href="/" title="Home">
    You can include icons too.
  </Card>
</Cards>
```

<Cards>
<Card href="/docs" title="Documentation">
Browse the full documentation.
</Card>

<Card title="href is optional">
Cards can hold plain content too.
</Card>

<Card href="/" title="Home">
You can include icons too.
</Card>
</Cards>

#### "Further Reading" Section [#further-reading-section]

You can do something like:

```tsx title="page.tsx"
import { getPageTreePeers } from 'fumadocs-core/page-tree';
import { source } from '@/lib/source';

<Cards>
  {getPageTreePeers(source.getPageTree(), '/docs/my-page').map((peer) => (
    <Card key={peer.url} title={peer.name} href={peer.url}>
      {peer.description}
    </Card>
  ))}
</Cards>;
```

This will show the other pages in the same folder as cards.

### Callouts [#callouts]

Useful for adding tips/warnings, it is included by default. You can specify the type of callout:

- `info` (default)
- `warn`/`warning`
- `error`
- `success`
- `idea`

```mdx
<Callout>Hello World</Callout>

<Callout title="Title" type="warn">
  Hello World
</Callout>

<Callout title="Title" type="error">
  Hello World
</Callout>

<Callout title="Title" type="idea">
  Hello World
</Callout>
```

<Callout>
Hello World
</Callout>

<Callout title="Title" type="warn">
Hello World
</Callout>

<Callout title="Title" type="error">
Hello World
</Callout>

<Callout title="Title" type="idea">
Hello World
</Callout>

### Headings [#headings]

An anchor is automatically applied to each heading, it sanitizes invalid characters like spaces. (e.g. `Hello World` to `hello-world`)

```md
# Hello `World`
```

#### TOC Settings [#toc-settings]

The table of contents (TOC) will be generated based on headings, you can also customize the effects of headings:

```md
# Heading [!toc]

This heading will be hidden from TOC.

# Another Heading [toc]

This heading will **only** be visible in TOC, you can use it to add additional TOC items.
Like headings rendered in a React component:

<MyComp />
```

#### Custom Anchor [#custom-anchor]

You can add `[#slug]` to customize heading anchors.

```md
# heading [#my-heading-id]
```

You can also chain it with TOC settings like:

```md
# heading [toc] [#my-heading-id]
```

To link people to a specific heading, add the heading id to hash fragment: `/page#my-heading-id`.

### Codeblock [#codeblock]

Syntax Highlighting is supported by default using [Rehype Code](/docs/headless/mdx/rehype-code).

````mdx
```js
console.log('Hello World');
```

```js title="My Title"
console.log('Hello World');
```
````

#### Line Numbers [#line-numbers]

Show line numbers, it also works with Twoslash and other transformers.

````mdx tab="Input"
```ts twoslash lineNumbers
const a = 'Hello World';
//    ^?
console.log(a); // [!code highlight]
```
````

```ts twoslash lineNumbers tab="Output"
const a = 'Hello World';
//    ^?
console.log(a); // [!code highlight]
```

You can set the initial value of line numbers.

````mdx tab="Input"
```js lineNumbers=4
function main() {
  console.log('starts from 4');

  return 0;
}
```
````

```js lineNumbers=4 tab="Output"
function main() {
  console.log('starts from 4');

  return 0;
}
```

#### Shiki Transformers [#shiki-transformers]

We support some of the [Shiki Transformers](https://shiki.style/packages/transformers), allowing you to highlight/style specific lines.

````md tab="Input"
```tsx
// highlight a line
<div>Hello World</div> // [\!code highlight]

// highlight a word
// [\!code word:Fumadocs]
<div>Fumadocs</div>

// diff styles
console.log('hewwo'); // [\!code --]
console.log('hello'); // [\!code ++]

// focus
return new ResizeObserver(() => {}) // [\!code focus]
```
````

```tsx tab="Output"
// highlight a line
<div>Hello World</div> // [!code highlight]

// highlight a word
// [!code word:Fumadocs]
<div>Fumadocs</div>

// diff styles:
console.log('hewwo'); // [!code --]
console.log('hello'); // [!code ++]

// focus
return new ResizeObserver(() => {}) // [!code focus]
```

#### Tab Groups [#tab-groups]

````mdx
```ts tab="Tab 1"
console.log('A');
```

```ts tab="Tab 2"
console.log('B');
```
````

```ts tab="Tab 1"
console.log('A');
```

```ts tab="Tab 2"
console.log('B');
```

To add a persist ID, define `tab-group` at the first codeblock:

````mdx
```ts tab="Tab 1" tab-group="my-custom-group"
console.log('A');
```

```ts tab="Tab 2"
console.log('B');
```
````

```ts tab="Tab 1" tab-group="my-custom-group"
console.log('A');
```

```ts tab="Tab 2"
console.log('B');
```

Another group:

```ts tab="Tab 1" tab-group="my-custom-group"
console.log('A');
```

```ts tab="Tab 2"
console.log('B');
```

#### MDX in Tab Groups [#mdx-in-tab-groups]

Tab groups come from the `remarkCodeTab` remark plugin, which Fumadocs MDX enables by default. To use MDX in tab values, enable its `parseMdx` option:

```ts tab="unified" title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';

export default defineConfig({
  mdxOptions: {
    remarkCodeTabOptions: {
      parseMdx: true, // [!code ++]
    },
  },
});
```

```ts tab="Sätteri" title="source.config.ts"
import { defineConfig, defineDocs } from 'fumadocs-mdx/config';

export const docs = defineDocs({
  docs: {
    compiler: 'satteri',
  },
});

export default defineConfig({
  satteriOptions: {
    remarkCodeTabOptions: {
      parseMdx: true, // [!code ++]
    },
  },
});
```

````mdx
```ts tab="<Building /> Tab 1"
console.log('A');
```

```ts tab="<Rocket /> Tab 2"
console.log('B');
```
````

```ts tab="<Building /> Tab 1"
console.log('A');
```

```ts tab="<Rocket /> Tab 2"
console.log('B');
```

### Include [#include]

Reference another file (can also be a Markdown/MDX document). Fumadocs MDX always enables it with [Remark Include](/docs/headless/mdx/remark-include).
Specify the target file path in `<include>` tag (relative to the MDX file itself).

```mdx title="page.mdx"
<include>./another.mdx</include>
```

See [other usages of include](/docs/mdx/include).

### Props [#props]

The props of a page are available as `props` in MDX. For example, a page in a `[framework]` folder receives `framework` from its [path params](/docs/next/page-conventions#path-params):

```mdx title="[framework]/deploy.mdx"
## Deploy on {props.framework}

Deploy your {props.framework} site.
```

An expression is replaced by its value in the table of contents, the search index and the Markdown for LLMs as well. On the Astro page, the heading above gets the ID `deploy-on-astro`.

You can also pass [custom props](/docs/headless/source-api#custom-props) to a page.

### Show [#show]

Render content on a condition. Fumadocs MDX enables it by default with [Remark Show](/docs/headless/mdx/remark-show).

`when` is a JavaScript expression that can read [props](#props):

```mdx title="[framework]/deploy.mdx"
<show when={props.framework === 'astro'}>

## Adapters

Add an adapter to your Astro config.

</show>
```

The section is only rendered on the page where `framework` is `astro`. On the other pages, it is also left out of the table of contents, the search index and the Markdown for LLMs.

You can use `<show>` around a [step](#steps) too:

```mdx title="[framework]/deploy.mdx"
### Build [step]

<show when={props.framework === 'astro'}>

### Add an Adapter [step]

</show>

### Deploy [step]
```

Steps that aren't rendered are skipped in the numbering: Deploy is step 3 on the Astro page, and step 2 on the other pages.

It works the same way for a code block of a [tab group](#tab-groups). The tab only appears when its code block is rendered.

### NPM Commands [#npm-commands]

Useful for generating commands for installing packages with different package managers.

````md tab="Input"
```npm
npm i next -D
```
````

```npm tab="Output"
npm i next -D
```

See [`remark-npm`](/docs/headless/mdx/remark-npm) for details.

### Steps [#steps]

Useful for denoting steps for guides, see [`remark-steps`](/docs/headless/mdx/remark-steps) for enable & configure.

```md
### Installation [step]

### Write Code [step]

### Deploy [step]
```

#### Installation [step] [#installation]

#### Write Code [step] [#write-code]

#### Deploy [step] [#deploy]

### Other Components [#other-components]

You can configure & use the [built-in components](/docs/ui/components) in your MDX document, such as Tabs, Accordions and Zoomable Image.

## Additional Features [#additional-features]

You may be interested:

- [Math](/docs/next/markdown/math): Writing math equations in Markdown/MDX.
- [Mermaid](/docs/next/markdown/mermaid): Rendering diagrams in your docs
- [Twoslash](/docs/next/markdown/twoslash): Use TypeScript Twoslash in your docs
- [Auto Type Table](/docs/next/markdown/typescript): Generate docs from TypeScript definitions
- [Validate Links](/docs/next/markdown/validate-links): Ensure your links are correct.