# Fumadocs MDX (the built-in content source): Include
URL: /docs/mdx/include
Source: https://raw.githubusercontent.com/fuma-nama/fumadocs/refs/heads/main/apps/docs/content/docs/mdx/include.mdx

Reuse content from other files.

## Usage [#usage]

Fumadocs MDX always enables [Remark Include](/docs/headless/mdx/remark-include), on both unified and Sätteri.

### Content [#content]

To display content from another Markdown/MDX file, specify its path relative to the file itself in the `<include>` tag.

```mdx tab="MDX"
<include>./another.mdx</include>
```

```md tab="Markdown"
::include[./another.mdx]
```

<Callout type="warn">
Do not pass untrusted paths to `<include>`, it can embed any file on your machine, like `.env`.
</Callout>

<Callout title="For Markdown">
Markdown (`.md`) files do not support JSX syntax. Use the directive syntax instead.
Sätteri parses directives by default. On unified, add the `remark-directive` remark plugin:

```ts title="source.config.ts"
import { defineConfig } from 'fumadocs-mdx/config';
import remarkDirective from 'remark-directive';

export default defineConfig({
  mdxOptions: {
    // [!code ++]
    remarkPlugins: [remarkDirective],
  },
});
```

You may also need `rehype-raw` for HTML comments and content.
</Callout>

### CodeBlock [#codeblock]

For other types of files, it will become a codeblock:

```mdx tab="MDX"
<include>./script.ts</include>

<include lang="md" meta='title="lib.md"'>
  page.md
</include>
```

```md tab="Markdown"
::include[./script.ts]

::include[page.md]{lang=md meta='title="lib.md"'}
```

You can include only a region of content:

```ts title="code.ts"
export function fn() {
  //#region a
  console.log('one');
  //#endregion
}
```

```mdx tab="MDX"
<include>./code.ts#a</include>
```

```md tab="Markdown"
::include[./code.ts#a]
```

### `cwd` [#cwd]

Resolve relative paths from cwd instead of the current file:

```mdx tab="MDX"
<include cwd lang="tsx" meta='title="lib.ts"'>
  ./script.ts
</include>
```

```md tab="Markdown"
::include[./script.ts]{cwd lang=tsx meta='title="lib.ts"'}
```

## Extraction [#extraction]

When referencing content files, you can only include a certain part of the document.

### Section [#section]

Encapsulate by a `<section />` tag:

```mdx tab="a.mdx"
## Hello World

<section id="test">This is included</section>

This is not included.
```

```mdx tab="b.mdx"
Include the content from `a.mdx`:

<include>a.mdx#test</include>
```

In Markdown:

```md tab="a.md"
## Hello World

:::section{#test}
This is included
:::

This is not included.
```

```md tab="b.md"
Include the content from `a.mdx`:

::include[a.md#test]
```

### Heading [#heading]

Include contents under a certain heading.

```mdx tab="a.mdx"
## Included Section

I'm here!

## Not Included

Some random text.
```

```mdx tab="b.mdx"
Content under the heading:

<include>a.mdx#included-section</include>
```

In Markdown:

```md tab="a.md"
## Included Section

I'm here!

## Not Included

Some random text.
```

```md tab="b.md"
Content under the heading:

::include[a.mdx#included-section]
```