Why You Should Choose Markdoc Over MDX for Your Astro Site
Published: September 7, 2026
⏱️ 3 min read | 📝 541 words
Why You Should Choose Markdoc Over MDX for Your Astro Site
If you have built content-heavy websites with Astro, you have likely reached for MDX when you needed to mix interactive UI components into your text. It has been the industry standard for years. However, as projects grow, MDX can start to show its cracks—unforgiving syntax errors, build-time performance bottlenecks, and security headaches.
Markdoc (.mdoc) is an open-source authoring framework created by Stripe to solve the exact pain points that make MDX frustrating.
Here is why you should consider swapping MDX for Markdoc in your next Astro project, written entirely in Markdoc syntax.
1. Validated and Enforced Tag Architecture
In MDX, any React, Vue, or Svelte component is valid by default. While this feels like freedom initially, it quickly turns into a governance nightmare if multiple authors or non-technical content creators are updating your markdown files. One missing self-closing tag (<Component>) breaks your entire website build. Markdoc introduces a strict schema-based model. You explicitly define which custom HTML elements or Astro components are allowed to render via tags. If a writer uses a tag incorrectly, Markdoc safely fails compilation with a descriptive validation error instead of crashing your development server.
2. A Cleaner, Author-Friendly Syntax
MDX forces writers to think like frontend developers. They have to worry about JavaScript import statements at the top of the file and JSX rules mixed into their paragraphs. Markdoc looks like standard Markdown but adds an elegant block syntax inspired by liquid/twig templating engines. Your content creators never have to see an `import Button from '../components/Button' statement again. Astro handles component mapping completely behind the scenes in your configuration file.
Direct Feature Comparison
| Feature | MDX | Markdoc (.mdoc) |
|---|---|---|
| Syntax Style | JSX / Embedded JavaScript | Declarative Tags (% %) |
| Component Mapping | Manual file imports | Centralised schema config |
| Error Handling | Breaks builds on small typos | Graceful validation warnings |
| Security Profile | High risk (executable code) | Safe (strict data isolation) |
| Ideal For | Developer personal blogs | Content teams & CMS nodes |
3. Ultimate Content Separation and Security
Because MDX executes arbitrary JavaScript code during the build process, it poses an inherent security risk if you ingest content from untrusted external sources, user inputs, or a Headless CMS. Markdoc separates content from code execution entirely. The .mdoc file outputs a pure, static Abstract Syntax Tree (AST), while JavaScript logic lives strictly inside your components. This decoupling means you can confidently fetch or store Markdoc text streams anywhere without worrying about remote code execution or build-time script injection.
The Verdict
If you are a solo developer who wants to occasionally throw custom components into a personal layout, MDX works perfectly fine. But if you are building an authoritative blog, managing a team of technical writers, or fetching markdown data out of platforms like Keystatic, Markdoc is the clear winner. It provides the constraints that large projects need to stay fast, structured, and completely unbreakable.
Getting started is simple. Just run npx astro add markdoc in your terminal to plug Markdoc's robust engine directly into your Astro setup.