Learn how Astro supports Markdown and MDX for creating content-rich pages with components
Astro has built-in support for Markdown and MDX files, making it easy to write content-focused pages. You can use standard Markdown syntax, add frontmatter for metadata, and even use components within your content.
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
---title: My Blog Postauthor: Jane Doedate: 2026-03-03---# Welcome to My PostThis is a **Markdown** page in Astro. It supports all standard Markdown syntax.## Features- Easy to write- Familiar syntax- Fast rendering```jsconsole.log('Code blocks work too!');
<Note>Markdown files in `src/pages/` are automatically converted to HTML pages with Astro's default layout.</Note>## FrontmatterFrontmatter is YAML metadata at the top of your Markdown file, enclosed by `---` delimiters. It's available as the `frontmatter` property in your layouts.```markdown src/pages/post.md---title: Understanding Frontmatterdescription: A guide to using frontmatter in Astroauthor: John SmithpublishedDate: 2026-03-03tags: [astro, markdown, frontmatter]layout: ../../layouts/BlogPost.astro---# Content goes here
Once installed, you can use components in .mdx files:
src/pages/interactive.mdx
---title: Interactive Content---import Button from '../components/Button.astro';import Counter from '../components/Counter.jsx';# Interactive MDX PageHere's a regular paragraph of text.<Button>Click me!</Button>And here's a React counter component:<Counter client:load />## More ContentYou can mix Markdown and components seamlessly.
MDX is perfect for documentation, blogs, and any content that benefits from interactive components.
Replace HTML elements with custom components using the components prop in MDX:
src/pages/styled.mdx
---title: Custom Styled Content---import CustomHeading from '../components/CustomHeading.astro';import Note from '../components/Note.astro';export const components = { h1: CustomHeading, blockquote: Note};# This renders as CustomHeading> This renders as the Note component
Use Content Collections for type-safe content management
Layouts
Create reusable layouts for consistent styling
For complex content sites, use Content Collections instead of accessing Markdown files directly. They provide type safety, validation, and better performance.
---layout: ../../layouts/BlogPost.astrotitle: My First Blog Postauthor: Jane Doedate: 2026-03-03tags: [astro, blogging]---# Welcome to my blog!This is my first post using Astro and Markdown.
src/pages/docs/getting-started.mdx
---title: Getting Starteddescription: Learn how to get started---import CodeExample from '../../components/CodeExample.astro';# Getting Started<CodeExample lang="bash">npm create astro@latest</CodeExample>