What is a `.md` file in Astro

Category: astro

Understanding Astro's use of Markdown files for content.

A typical Astro Markdown file looks like this:

---
title: "My First Blog Post"
description: "An intro to Astro"
pubDate: 2025-01-01
tags: ["astro", "markdown"]
---

## Hello World

This is my blog post written in**Markdown**.

It has two parts:

  1. Frontmatter (YAML)
    • Structured data (like JSON, but more readable)
    • Used for metadata (title, date, tags, SEO, etc.)
  2. Markdown content
    • Human-readable content
    • Converted to HTML at build time

Astro turns this into:

  • A page (or data source)
  • With typed metadata
  • And compiled HTML at build time

Why Astro uses Markdown so heavily

Astro is designed for content-driven sites:

  • Blogs
  • Documentation
  • Marketing pages
  • Portfolios
  • Landing pages

Markdown aligns perfectly with Astro’s core philosophy:

Ship less JavaScript. Render at build time.

Why use Markdown instead of JSON?

Markdown is for content, JSON is for data

MarkdownJSON
Written by humansWritten for machines
Supports rich textNo formatting
Readable in GitHubHard to read
Supports headings, links, codeNeeds rendering logic

Markdown vs Headless CMS (Sanity, Contentful)

High-level positioning

AspectMarkdown (.md / .mdx)Headless CMS (Sanity / Contentful)
Primary audienceDevelopersNon-technical editors
Content locationGit repoExternal service
Update modelGit commit → deployLive publishing
Build modelBuild-timeBuild-time or runtime
Infra costFreePaid (at scale)
ComplexityVery lowMedium → high
SEOExcellentExcellent
Best forBlogs, docs, marketingEditorial, product content

Authoring Experience

Markdown

✅ Pros:

  • GitHub-native
  • Easy PR reviews
  • No CMS UI needed
  • Offline editing
  • Perfect for dev teams

❌ Cons:

  • Not editor-friendly
  • No previews without tooling
  • No role-based permissions

Sanity / Contentful

✅ Pros:

  • Visual editor
  • Rich previews
  • Permissions & roles
  • Structured relationships
  • Image pipelines

❌ Cons:

  • Setup time
  • Learning curve
  • Vendor lock-in

Rule of thumb

If developers write content → Markdown

If editors write content → CMS