<!--
Sitemap:
- [What is Vocs](/guide/what-is-vocs): Learn what Vocs provides for documentation sites
- [Getting Started](/guide/getting-started): Install Vocs and create your first documentation site
- [Writing Docs with AI](/guide/writing-docs-with-ai): Use an AI agent to create and maintain Vocs documentation
- [Project Structure](/guide/structure): Overview of the structure of a Vocs project
- [Markdown Extensions](/guide/markdown-extensions): Features and syntax of Markdown in Vocs
- [Code & Syntax Highlighting](/guide/syntax-highlighting): Rich markup and annotations for code
- [Code Snippets](/guide/code-snippets): Include and reuse code in Markdown
- [Markdown Snippets](/guide/markdown-snippets): Include other Markdown files in MDX
- [Asset Handling](/guide/asset-handling): Manage images, fonts, icons, and other docs assets
- [Frontmatter](/guide/frontmatter): Configure page metadata, layouts, search, and UI visibility
- [Using React in Markdown](/guide/react): Compose MDX pages with React components
- [Twoslash](/guide/twoslash): Add type-aware annotations to code examples
- [Sidebar & Top Navigation](/guide/navigation): Keep docs navigation synced with routes
- [Theming](/guide/theming): Customize colors, typography, spacing, logos, and code themes
- [Tailwind CSS](/guide/tailwind): Use Tailwind utilities in Vocs pages and components
- [Layouts](/guide/layouts): Choose and customize page shells for your docs
- [Dynamic OG Images](/guide/dynamic-og-images): Generate social preview images from page metadata
- [Feedback](/guide/feedback): Collect page-level feedback from readers
- [Changelog Generation](/guide/changelog-generation): Fetch release notes and render a changelog page
- [MCP Server](/guide/mcp-server): Expose your docs and source code to AI assistants
- [AI Support](/guide/ai-support): Make your documentation easier for AI assistants to read
- [Site Configuration](/reference/site-config): Reference for options accepted by defineConfig
- [Components](/reference/components): Reference for the public React components exported from Vocs
- [Hooks](/reference/hooks): Reference for the React hooks exported from Vocs
- [Changelog](/guide/changelog): Release history for Vocs
-->

# Markdown Snippets \[Include other Markdown files in MDX]

Markdown snippets let you reuse Markdown or MDX content across pages by importing one `.mdx` file into another.

:::warning
Markdown snippets require MDX. If the page importing a snippet is a `.md` file, rename it to `.mdx`.
:::

## Quick Start

::::steps

### Create a snippet

Create a snippet file next to the page that will import it, or in a shared snippets directory.

```mdx [snippet.mdx]
### Hello world

This is my snippet.
```

### Import the snippet

Import the snippet into another MDX file, then render it like a React component.

```mdx [example.mdx]
import Snippet from './snippet.mdx'

# Example

This is an example of including a snippet in a Markdown file.

<Snippet />
```

### Output

The rendered page includes both the page content and the imported snippet content.

:::code-group

<div data-title="Preview">
  # Example

  This is an example of including a snippet in a Markdown file.

  ## Hello world

  This is my snippet.
</div>

```mdx [Output]
# Example

This is an example of including a snippet in a Markdown file.

## Hello world

This is my snippet.
```

:::

::::

## Passing Props

Imported MDX snippets compile to React components, so you can pass props when rendering them.

:::code-group

```mdx [example.mdx]
import Snippet from './snippet.mdx'

# Example

This is an example of including a snippet in a Markdown file.

<Snippet title="Hello world" content="This is my snippet." />
```

```mdx [snippet.mdx]
## {props.title}

{props.content}
```

:::

Use props for small variations such as names, labels, or short descriptions. If most of the content changes between pages, prefer separate snippets.

## Organizing Snippets

Keep snippets near the pages that use them when they are page-specific.

:::file-tree

* +src
  * +pages
    * +guide
      * example.mdx
      * snippet.mdx
        :::

Use a shared directory when a snippet is reused across many pages.

:::file-tree

* +src
  * +pages
    * +\_components
      * BetaNotice.mdx
    * guide.mdx
    * reference.mdx
      :::

See also: [Using React in Markdown](/guide/react)
