This Astro integration enables the usage of MDX components and allows you to create pages as
Why MDX?Section titled Why MDX?
MDX allows you to use variables, JSX expressions and components within Markdown content in Astro. If you have existing content authored in MDX, this integration allows you to bring those files to your Astro project.
InstallationSection titled Installation
Quick InstallSection titled Quick Install
astro add command-line tool automates the installation for you. Run one of the following commands in a new terminal window. (If you aren’t sure which package manager you’re using, run the first command.) Then, follow the prompts, and type “y” in the terminal (meaning “yes”) for each one.
If you run into any issues, feel free to report them to us on GitHub and try the manual installation steps below.
Manual InstallSection titled Manual Install
First, install the
@astrojs/mdx package using your package manager. If you’re using npm or aren’t sure, run this in the terminal:
Then, apply this integration to your
astro.config.* file using the
Editor IntegrationSection titled Editor Integration
VS Code supports Markdown by default. However, for MDX editor support, you may wish to add the following setting in your VSCode config. This ensures authoring MDX files provides a Markdown-like editor experience.
UsageSection titled Usage
With the Astro MDX integration, you can add MDX pages to your project by adding
.mdx files within your
src/pages/ directory. You can also import
.mdx files into
Astro’s MDX integration adds extra features to standard MDX, including Markdown-style frontmatter. This allows you to use most of Astro’s built-in Markdown features like a special frontmatter
layout property and a property for marking a page as a draft.
See how MDX works in Astro with examples in our Markdown & MDX guide.
Visit the MDX docs to learn about using standard MDX features.
ConfigurationSection titled Configuration
Once the MDX integration is installed, no configuration is necessary to use
.mdx files in your Astro project.
You can configure how your MDX is rendered with the following options:
Options inherited from Markdown configSection titled Options inherited from Markdown config
markdown configuration options except
drafts can be configured separately in the MDX integration. This includes remark and rehype plugins, syntax highlighting, and more. Options will default to those in your Markdown config (see the
extendMarkdownConfig option to modify this).
📚 See the Markdown Options reference for a complete list of options.
Section titled extendMarkdownConfig
MDX will extend your project’s existing Markdown configuration by default. To override individual options, you can specify their equivalent in your MDX configuration.
For example, say you need to disable GitHub-Flavored Markdown and apply a different set of remark plugins for MDX files. You can apply these options like so, with
extendMarkdownConfig enabled by default:
You may also need to disable
markdown config extension in MDX. For this, set
Section titled recmaPlugins
We suggest using AST Explorer to play with estree outputs, and trying
ExamplesSection titled Examples
- The Astro MDX starter template shows how to use MDX files in your Astro project.
TroubleshootingSection titled Troubleshooting
For help, check out the
#support channel on Discord. Our friendly Support Squad members are here to help!
You can also check our Astro Integration Documentation for more on integrations.
ContributingSection titled Contributing
This package is maintained by Astro’s Core team. You’re welcome to submit an issue or PR!
ChangelogSection titled Changelog
See CHANGELOG.md for a history of changes to this integration.