mobile wallpaper 1
mobile wallpaper 2
mobile wallpaper 3
mobile wallpaper 4
593 words
3 minutes
MDX Syntax Guide
2026-08-08

MDX Syntax Guide#

MDX lets you write familiar Markdown while adding components and JavaScript expressions where ordinary Markdown is not enough. This guide introduces the syntax that is most useful when authoring an article in a content-driven Astro site.

NOTE

What is MDX?

An .mdx file is still a Markdown document. Headings, lists, links, images, code blocks, and other Markdown syntax continue to work, while imports, components, JSX, and expressions become available as optional extensions.

Frontmatter#

Every article begins with YAML frontmatter. It defines metadata used by article pages, lists, search results, and feeds:

---
title: My MDX Article
published: 2026-08-08
description: A short introduction shown in article previews.
tags: [Markdown, MDX]
category: Guides
draft: false
---

Keep frontmatter focused on metadata. Imports and JavaScript declarations belong immediately after the closing --- delimiter.

Standard Markdown#

Most of an MDX article should remain ordinary Markdown. This keeps the source easy to read and gives RSS and Atom readers a useful static version.

## A section heading
- A list item
- **Bold text** and *emphasis*
- [A normal link](https://example.com/)
> A blockquote remains a blockquote.

Importing and Using Components#

MDX can import Astro components at the top level and use them directly in the document. Component names must begin with a capital letter.

import Notice from "../../components/Notice.astro";
export const message = "Props can come from an MDX expression.";
<Notice label={message} />

The following panel is a live component rendered by this article:

Use components for reusable interface elements or structured content. Prefer Markdown for regular prose so the article remains portable and readable.

JavaScript Expressions#

Top-level export const declarations can prepare values for the document. Insert a JavaScript expression with braces:

export const topics = ["components", "expressions", "extended Markdown"];
This guide covers {topics.length} topics: {topics.join(", ")}.

This live expression counts 3 topics: components, expressions, extended Markdown.

Expressions should be deterministic during the build. Browser-only APIs such as window and document belong inside a component script rather than the MDX module body.

Callouts#

Callouts highlight information without requiring a custom component:

TIP

Use the simplest syntax that works

Choose Markdown for prose, an MDX expression for a small dynamic value, and a component when markup or behavior needs to be reused.

:::tip[Optional title]
This content is emphasized as a tip.
:::

An inline Wiki Link points to another article while keeping the sentence readable. For example, continue with the content guide.

A standalone Wiki Link becomes an article card with its available metadata and cover image:

Cover image for Writing a Blog Post
Writing a Blog Post
A generic example of article structure and frontmatter.
2024-04-01Guides#Example#Writing#Markdown
Read [[guide|the content guide]] for more details.
[[guide]]

Math and Chemistry#

Inline math uses single dollar signs, while display equations use a pair. The mhchem extension is also available for chemical notation.

Einstein’s mass-energy relation is E=mc2E = mc^2.

ex2dx=π\int_{-\infty}^{\infty} e^{-x^2}\,dx = \sqrt{\pi}

A chemical reaction can be written as HX2O+COX2HX2COX3\ce{H2O + CO2 -> H2CO3}.

Inline: $E = mc^2$
Display: $$\int_0^1 x^2\,dx = \frac{1}{3}$$
Chemistry: $\ce{H2O + CO2 -> H2CO3}$

Code Groups#

Use a code group when readers may choose between equivalent examples. Each label corresponds to one fenced code block:

content.ts
export const renderTarget = "page";
::: code-group labels=[TypeScript, Shell]
```ts
export const renderTarget = "page";
```
```bash
pnpm build
```
:::

Images and Captions#

Image alt text describes the image for assistive technology. A Markdown title becomes a visible caption, and an optional w-N% token controls the width.

A square demonstration image
A caption generated from the Markdown image title
![Descriptive alt text w-60%](./image.webp "Visible image caption")

Valid widths range from w-1% to w-100%. Omit the token when the image should use the normal responsive width.

Relative links and absolute URLs that use the configured site origin are classified as internal. Links to other origins receive the external-link attributes configured by the theme.

Use relative paths for internal content. External origins such as https://example.com/ are classified separately by the theme.

Writing Portable MDX#

The article page, RSS, and Atom share the same content pipeline. Interactive scripts are removed from feeds, but semantic HTML produced by components, callouts, Wiki Links, math, code groups, and images remains readable.

For reliable output:

  1. Keep the main explanation in Markdown.
  2. Give images meaningful alt text and components semantic HTML.
  3. Avoid browser globals in top-level expressions.
  4. Ensure useful information is visible before client-side JavaScript runs.
  5. Run pnpm test, pnpm check, and pnpm build before publishing.

MDX works best as an extension of Markdown—not a replacement for it. Start with plain content, then introduce expressions and components only where they make the article clearer or more reusable.

Share

If this article helped you, please share it with others!

MDX Syntax Guide
https://mizuki.mysqil.com/posts/content-pipeline-fixture/
Author
まつざか ゆき
Published at
2026-08-08
License
CC BY-NC-SA 4.0

Some information may be outdated

Table of Contents