← Back to Home
markdown

Using MDX

This theme comes with the @astrojs/mdx integration installed and configured in your astro.config.mjs config file. If you prefer not to use MDX, you can disable support by removing the integration from your config file.

Why MDX?

MDX is a special flavor of Markdown that supports embedded JavaScript & JSX syntax. This unlocks the ability to mix JavaScript and UI Components into your Markdown content for things like interactive charts or alerts.

If you have existing content authored in MDX, this integration will hopefully make migrating to Astro a breeze.

Example

Here is how you import and use a UI component inside of MDX.
When you open this page in the browser, you should see the clickable button below.

Embedded component in MDX

More Components

Alongside plain markdown, a handful of Starlight-style components live in src/components/mdx/ and can be imported into any .mdx post.

Card

Did you know?

Cards are handy for callouts, tips, or asides that shouldn’t get lost in a wall of text.

Tabs

A code fence needs a blank line before and after it to be parsed as markdown instead of JSX text — Prettier doesn’t know that and will collapse those blank lines on save, so this block is wrapped in {/* prettier-ignore */} to keep its formatting intact.

npm install astro
pnpm add astro
yarn add astro

FileTree

Leave a blank line after <FileTree> so MDX parses the list as markdown, not JSX text.

  • src/
    • components/
      • Card.astro
      • Tabs.astro
    • content/
      • blog/
  • astro.config.mjs
  • package.json

Charts

Both charts take a shared labels array plus one or more series — each with its own data, an optional name (shown in the legend), and an optional color (falls back to a built-in palette starting with the site accent).

Signups by month
128Jan1814Feb911Mar2416Apr
  • This year
  • Last year
Response time (ms)
MonTueWedThuFri
  • API
  • CDN

Related Topics

← Back to Home