Markdown Pages
Create Markdown pages by adding.md files to your src/pages/ directory. Each file becomes a route based on its file path.
src/pages/blog/post.md
Accessing Frontmatter
In your layout, access frontmatter data through thefrontmatter prop:
src/layouts/BlogPost.astro
MDX Support
MDX extends Markdown by allowing you to import and use components directly in your content. First, add the MDX integration:Using Components in MDX
Once installed, you can use components in.mdx files:
src/pages/interactive.mdx
Markdown Features
Syntax Highlighting
Code blocks support syntax highlighting out of the box:astro.config.mjs:
astro.config.mjs
GitHub-Flavored Markdown
Astro supports GitHub-Flavored Markdown (GFM) including:- Tables
- Task lists
- Strikethrough
- Autolinks
Custom Components
Replace HTML elements with custom components using thecomponents prop in MDX:
src/pages/styled.mdx
Layouts for Markdown
Specify a layout in frontmatter to wrap your Markdown content:src/pages/article.md
src/layouts/Article.astro
Programmatic Access
Import Markdown files in Astro components to access their content and frontmatter:src/pages/index.astro
Dynamic Imports
Load Markdown files dynamically:src/pages/blog/[slug].astro
Configuration Options
Customize Markdown processing inastro.config.mjs:
astro.config.mjs
Remark Plugins
Remark Plugins
Remark plugins process Markdown AST before HTML conversion:
Rehype Plugins
Rehype Plugins
Rehype plugins process HTML after Markdown conversion:
Best Practices
Content Collections
Use Content Collections for type-safe content management
Layouts
Create reusable layouts for consistent styling
MDX-Specific Features
Export Variables
Export variables from MDX to use in your content:JavaScript Expressions
Use JavaScript expressions inline:Component Props
Pass props to components:Common Use Cases
- Blog
- Documentation
- Landing Page
src/pages/blog/first-post.md
Related Resources
Content Collections
Type-safe content management
Layouts
Wrap content with layouts
Components
Build reusable components
Assets
Optimize images in Markdown