PreviousNo previous post
On this page
  • Typography
  • Headings
  • Heading 1
  • Heading 2
  • Heading 3
  • Heading 4
  • Heading 5
  • Heading 6
  • Text Emphasis
  • Line Breaks & Escaping
  • Emoji
  • Lists
  • Unordered
  • Ordered
  • Task list
  • Definition list
  • Links
  • Blockquotes
  • Tables
  • Column Alignment
  • Footnotes
  • Horizontal Rule
  • Images
  • Alerts
  • Code
  • Inline Code
  • Code Block
  • Title
  • Line Numbers
  • Highlighting Specific Lines
  • Highlighting Specific Words
  • Combining All Features
  • MDX Components
  • Inline HTML with JSX Expressions
  • Registering Components
  • Custom Components
  • Exporting Variables
  • JavaScript Expressions
  • MDX Frontmatter

Cheat Sheet

This is a comprehensive MDX cheat sheet covering all the essential syntax and features for writing Markdown content.

January 8, 2025

•

2 min read

•

436 words

Loading...
PreviousNo previous post
On this page
  • Typography
  • Headings
  • Heading 1
  • Heading 2
  • Heading 3
  • Heading 4
  • Heading 5
  • Heading 6
  • Text Emphasis
  • Line Breaks & Escaping
  • Emoji
  • Lists
  • Unordered
  • Ordered
  • Task list
  • Definition list
  • Links
  • Blockquotes
  • Tables
  • Column Alignment
  • Footnotes
  • Horizontal Rule
  • Images
  • Alerts
  • Code
  • Inline Code
  • Code Block
  • Title
  • Line Numbers
  • Highlighting Specific Lines
  • Highlighting Specific Words
  • Combining All Features
  • MDX Components
  • Inline HTML with JSX Expressions
  • Registering Components
  • Custom Components
  • Exporting Variables
  • JavaScript Expressions
  • MDX Frontmatter

Typography

Headings

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Text Emphasis

Italic or Italic

Bold

Bold and italic

Strikethrough

Highlighted text

Line Breaks & Escaping

First line
Second line (two trailing spaces forces a line break)

Use a backslash \ before special characters to display them literally.

Example: *not italic*

Emoji

I ❤️ Markdown!


Lists

Unordered

  • Item one
  • Item two
    • Nested item
    • Another nested

Ordered

  1. First
  2. Second
    1. Subfirst
    2. Subsecond

Task list

Definition list

Term 1
Definition 1
Term 2
Definition 2

Links

Inline link

With title tooltip link

Reference-style link

Email user@example.com

Internal anchor link


Blockquotes

Simple quote.

Multi-line quote first paragraph.

Second paragraph.

Outer quote.

Inner nested quote.

Back to outer.


Tables

SyntaxDescription
HeaderTitle
ParagraphText

Column Alignment

LeftCenterRight
leftcenterright

Footnotes

This is a statement.1


Horizontal Rule

Three options all produce a rule:





Images

Inline Image: Inline image

Title tooltip: title tooltip

Reference-style image: Reference style


Alerts

NOTE

Highlights information users should take into account.

TIP

Optional information to help a user be more successful.

IMPORTANT

Crucial information necessary for users to succeed.

WARNING

Critical content demanding immediate user attention.

CAUTION

Negative potential consequences of an action.


Code

Inline Code

Use code for variables or short snippets.

Code Block

js
console.log('hello');

Title

Add title="filename" to the opening fence.

example.py
import sys
 
def main():
    print(sys.version)

Line Numbers

Add showLineNumbers to the opening fence.

tsx
const x = 1;
const y = 2;

Highlighting Specific Lines

Add {line} or {start-end} or {line,start-end} to the opening fence.

tsx
function greeting() {
  const message = "Highlighted";
  console.log("Not highlighted");
  const name = "Developer";
  const result = message + name;
  return result;
}

Highlighting Specific Words

Add /pattern/ to the opening fence to highlight every match.

tsx
import { useState, useEffect } from 'react';

Combining All Features

api.ts
async function fetchUserData() {
  try {
    const response = await fetch(`/api/users`);
    const data = await response.json();
    return data;
  } catch (error) {
    throw error;
  }
}

MDX Components

MDX lets you use JSX components directly in Markdown files.

Inline HTML with JSX Expressions

Red text using JSX style

Registering Components

Components are never imported inside .mdx files. All available components are registered globally in mdx-components.tsx

mdx-components.tsx
import { Badge } from "@/components/ui/badge"
import { Kbd, KbdGroup } from "@/components/ui/kbd"
 
const components = {
  Badge,
  Kbd,
  KbdGroup,
  // add more components here
}

Custom Components

Press Ctrl + C to copy.

⌘⇧K

Badge component:

Badge

Exporting Variables

Written by Jane Doe.

JavaScript Expressions

The current year is 2026.

4 equals four.


MDX Frontmatter

Frontmatter uses YAML and must appear at the very top of the file.

yaml
---
title: "My Post Title"
date: '2025-01-08'
summary: A short description of this page.
---

Footnotes

  1. This is the footnote text. ↩