---
title: "MDX Formatter Online: Format .mdx Files Safely | Prettify"
description: Format MDX online with Prettier. The Markdown is cleaned up, while
  JSX, imports, and exports stay as written. If Prettier would change the
  meaning, nothing changes.
url: https://prettify.tools/mdx-formatter
---

# MDX Formatter

Paste an .mdx file and Prettier formats the Markdown parts: headings, lists, tables, and spacing. Imports, exports, and JSX components stay as you wrote them. If formatting would change how MDX reads the file, Prettify keeps your text and tells you so.

## Why MDX formatting needs care

The MDX parser of Prettier follows MDX 1, while current MDX tools use MDX 3, and the two read some files differently. For example, Prettier can re-indent a list that follows a paragraph inside a \<Callout>. MDX 3 then reads a different document, or rejects the file.

Prettify formats with embedded code formatting off, so ESM and JSX are not rewritten. It then parses the input and the output with MDX 3 and compares the two trees. If they differ, it keeps the original text and shows the note "Kept your MDX as written".

## Key features

The formatter cleans up the Markdown around your components and leaves the code alone. It checks its own result with MDX 3 before it hands the result to you.

- Heading markers, list markers, blank lines between blocks, emphasis, and table alignment are formatted.
- Import and export lines keep their exact text.
- JSX components, their props, and expressions in braces keep their exact text.
- Frontmatter keeps its exact text; the formatter does not respace its keys.
- The result is kept only when MDX 3 reads it as it reads your input.
- A file that MDX 3 cannot parse is formatted as plain Prettier output, because there is no meaning to protect.

## How to use the MDX formatter

Paste the file in the box. The MDX 3 check runs on the text you paste, so you see the result and any warning in one place. Nothing is sent to a server.

1. Paste your MDX into the box, or select Try an example.
2. Read the Result pane. It updates a moment after you stop typing.
3. Look for a warning above the result. "Kept your MDX as written" means your text is unchanged.
4. Select Copy to use the text, or Download to save it as prettify.mdx.
5. Select Open in full editor to continue in the Raw view, or switch to Preview to see the components.
6. Select Format in the toolbar to format again after you edit.

## Worked example: formatting a page with a Note

This page has loose Markdown above a \<Note> component. The heading has extra spaces, the bullets use asterisks, and the frontmatter has an extra space after the colon.

```
---
title:  Install
---

#   Install
*   one
*   two

<Note>
  Keep **this**.
</Note>
```

## Reading the result

The heading and the list are cleaned up. The component lines are the same. The extra space in title: Install stays, because MDX frontmatter keeps its exact text.

The \<Note> holds Markdown, so the risk is real here. Prettier keeps the lines of that component, and MDX 3 reads the same tree before and after. The formatted text is therefore kept, and no warning shows.

```
---
title:  Install
---

# Install

- one
- two

<Note>
  Keep **this**.
</Note>
```

## When the formatter keeps your text

Some layouts do not survive Prettier. A \<Callout> that holds a paragraph, a blank line, and a list is one of them. In MDX 1 the blank line ends the component, so Prettier moves the closing tag in a way that MDX 3 reads differently.

Paste the next snippet and the box returns it unchanged, with the warning "Kept your MDX as written: Prettier would change its meaning."

```
<Callout type="info">
  Intro.

  - a
  - b
</Callout>
```

## Check the result in the Preview

Open the result in the editor and switch to the Preview. Each component shows as a labeled box with its props and its content. You can see at a glance that a list is still inside its \<Callout> and that each \<Tab> still holds its own content.

The box on this page formats documents under 200 KB. A larger file is not formatted there, and above 512 KB the box asks you to open the editor. In the editor, select Format when you want a large file formatted.

## Common use cases

Format MDX before it reaches a build that would reject a broken file. These are the situations where people reach for an MDX formatter, and why the safety check matters in each.

- Tidy a docs page from Docusaurus, Nextra, or a similar docs setup before you commit it.
- Clean an MDX blog post that several authors edited.
- Check that a formatter pass will not change how a component reads its children.
- Compare your hand formatting with Prettier output.
- Format a page that holds Markdown inside components, such as a list in a Callout, without breaking it.

## Frequently asked questions

### Does the MDX formatter change my JSX?

No. Components, their props, expressions in braces, and the import and export lines keep their exact text. Only the Markdown between them is formatted.

### What happens when formatting would break my file?

Prettify compares how MDX 3 reads the file before and after Prettier. If the two differ, it keeps your text exactly and shows "Kept your MDX as written", so you never get a file that reads differently.

### Which MDX version does it check against?

MDX 3, the current major version. Prettier itself follows MDX 1, which is why Prettify checks the result before it keeps it.

### Why was my frontmatter not reformatted?

With the MDX parser, frontmatter keeps its exact text. If you want Prettier to space YAML keys, use the Markdown formatter on a .md file.

### Is the MDX formatter free?

Yes. Formatting, the Raw view, the Preview with component boxes, and the frontmatter Properties card are free with no sign-up.

### Is my MDX uploaded to a server?

No. Prettier and the MDX 3 check run in your browser, so your component names and unreleased docs stay on your device.

## Related tools

- [MDX Preview](https://prettify.tools/mdx-preview)
- [Markdown Formatter](https://prettify.tools/markdown-formatter)
- [Online Markdown Editor](https://prettify.tools/markdown-editor)
- [Markdown Preview](https://prettify.tools/markdown-preview)
- [JSON Formatter: Prettify and Pretty Print JSON](https://prettify.tools/json-formatter)
- [Claude Skill Validator](https://prettify.tools/claude-skill-validator)

## Structured data

```json
{
  "@context": "https://schema.org",
  "@type": "SoftwareApplication",
  "name": "Prettify",
  "url": "https://prettify.tools",
  "description": "Multi-format data viewer, editor, and query engine for JSON, YAML, CSV, XML, Mermaid, Markdown, MDX, HTML, and SVG",
  "applicationCategory": "DeveloperApplication",
  "operatingSystem": "Web, macOS, Windows, Linux",
  "offers": [
    {
      "@type": "Offer",
      "price": "0",
      "priceCurrency": "USD",
      "description": "Free tier with core features"
    },
    {
      "@type": "Offer",
      "price": "19.99",
      "priceCurrency": "USD",
      "description": "Pro: lifetime access to all features"
    }
  ],
  "publisher": {
    "@id": "https://prettify.tools/#organization"
  }
}
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "@id": "https://prettify.tools/#organization",
  "name": "Prettify",
  "legalName": "Off Leash Labs",
  "url": "https://prettify.tools/",
  "logo": {
    "@type": "ImageObject",
    "url": "https://prettify.tools/icon-512.png",
    "width": 512,
    "height": 512
  },
  "contactPoint": {
    "@type": "ContactPoint",
    "contactType": "customer support",
    "email": "offleashlabs@gmail.com",
    "availableLanguage": "English"
  }
}
{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "WebPage",
      "@id": "https://prettify.tools/mdx-formatter",
      "url": "https://prettify.tools/mdx-formatter",
      "name": "MDX Formatter Online: Format .mdx Files Safely | Prettify",
      "description": "Format MDX online with Prettier. The Markdown is cleaned up, while JSX, imports, and exports stay as written. If Prettier would change the meaning, nothing changes.",
      "isPartOf": {
        "@type": "WebSite",
        "name": "Prettify",
        "url": "https://prettify.tools"
      }
    },
    {
      "@type": "FAQPage",
      "mainEntity": [
        {
          "@type": "Question",
          "name": "Does the MDX formatter change my JSX?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "No. Components, their props, expressions in braces, and the import and export lines keep their exact text. Only the Markdown between them is formatted."
          }
        },
        {
          "@type": "Question",
          "name": "What happens when formatting would break my file?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Prettify compares how MDX 3 reads the file before and after Prettier. If the two differ, it keeps your text exactly and shows \"Kept your MDX as written\", so you never get a file that reads differently."
          }
        },
        {
          "@type": "Question",
          "name": "Which MDX version does it check against?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "MDX 3, the current major version. Prettier itself follows MDX 1, which is why Prettify checks the result before it keeps it."
          }
        },
        {
          "@type": "Question",
          "name": "Why was my frontmatter not reformatted?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "With the MDX parser, frontmatter keeps its exact text. If you want Prettier to space YAML keys, use the Markdown formatter on a .md file."
          }
        },
        {
          "@type": "Question",
          "name": "Is the MDX formatter free?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Yes. Formatting, the Raw view, the Preview with component boxes, and the frontmatter Properties card are free with no sign-up."
          }
        },
        {
          "@type": "Question",
          "name": "Is my MDX uploaded to a server?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "No. Prettier and the MDX 3 check run in your browser, so your component names and unreleased docs stay on your device."
          }
        }
      ]
    }
  ]
}
```
