Key Takeaways
This guide covers migrating from hard coding to MDX in Next.js: Markdown syntax, React component integration, and style mapping
- Example SEO articles demonstrate best practices for title tags, heading hierarchy, internal linking patterns, and overall content structure.
- Follow annotated examples showing keyword placement strategy, meta description crafting rules, schema markup implementation, and consistently reader-friendly formatting.
- Start with content depth requirements—then layer in e-E-A-T signals, multimedia integration based on whether your article answers the full search intent comprehensively.
- Pair with content templates and writing guides for consistent SEO article production.
Use Cursor / OpenClaw to optimize article pages
npx skills add kostja94/marketing-skills --skill article-page-generatorCode Comparison: Hard Coding vs MDX
Hard Coding Approach (.tsx)
export const metadata = {
title: "Article Title",
description: "Article Description",
};Issues:
- Every element requires manual className addition
- Massive code volume, style code mixed with content
- Difficult to maintain, inconsistent styles across pages
- Style changes require modifying each page individually
MDX Approach (.mdx)
import BlogLayout from '@/components/BlogLayout';
import FAQ from '@/components/FAQ';
import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { addUtmToExternalLink, getExternalLinkRel } from "@/lib/utils";
<BlogLayout {...props}>
{/ Using FAQ component /}
<FAQ items={[...]} pageUrl="..." />
{/ Using Card component /}
<Card>
<CardHeader>
<CardTitle>Title</CardTitle>
</CardHeader>
<CardContent>
Content
</CardContent>
</Card>
{/ Using Button and Badge /}
<Button>Click Button</Button>
<Badge>Label</Badge>
</BlogLayout>Advantages:
- Uses Markdown syntax, code is concise and readable
- Styles automatically applied, no need to manually add className
- Global style unification, easy to maintain
- Content separated from styles, focus on content creation
- Code volume reduced by approximately 60-70%
Fundamentals
What is Markdown?
Markdown is a lightweight markup language created by John Gruber and Aaron Swartz in 2004. Its design goal is to enable people to write documents in an easy-to-read and easy-to-write plain text format, then convert it into valid HTML. Markdown uses simple symbols (such as # for headings, ** for bold) to mark text formatting without complex HTML tags.
Markdown syntax is concise and intuitive with a low learning curve. For example, using ## Heading creates a level 2 heading, and using - List item creates an unordered list. This simplicity makes Markdown the preferred format for writing documentation, blogs, README files, etc.
Markdown files typically use .md or .markdown as extensions and can be parsed and rendered by various tools and platforms, including GitHub, GitLab, Reddit, Stack Overflow, etc.
What is MDX?
MDX (Markdown + JSX) is an extension of Markdown that allows you to use JSX (JavaScript XML) syntax directly in Markdown documents, meaning you can embed React components. MDX is developed by the [MDX official team](https://mdxjs.com/), aiming to combine the simplicity of Markdown with the power of React.
In MDX, you can write content just like regular Markdown while inserting React components anywhere. For example, you can embed an interactive chart component in a Markdown paragraph or use custom card components in lists. This capability makes MDX particularly suitable for creating content-rich technical documentation, blog articles, and marketing pages.
MDX files use .mdx as the extension and are supported by modern frontend frameworks like Next.js, Gatsby, and Vite. During compilation, MDX converts Markdown syntax to HTML and JSX to React components, ultimately generating interactive web content.
Why Use Markdown/MDX?
Compared to traditional HTML writing or CMS systems, Markdown and MDX have the following advantages:
- Concise and Readable: Markdown syntax is intuitive and clear, even non-technical people can quickly get started. Code volume is reduced by approximately 60-70% compared to HTML, focusing on content itself rather than formatting markup.
- Version Control Friendly: Markdown files are plain text format, making it easy to use Git for version control, track content change history, and facilitate collaborative editing and code reviews.
- Cross-platform Compatible: Markdown files can be opened and edited in any text editor, not dependent on specific software or platforms. At the same time, most modern development tools and platforms natively support Markdown.
- Unified Styles: Through global component mapping (such as
mdx-components.tsx), you can uniformly manage styles for all articles, ensuring visual consistency while reducing maintenance costs. - Component Reusability: MDX allows embedding React components, enabling creation of reusable content components (such as FAQ, code examples, interactive charts, etc.), improving content creation efficiency.
- Performance Optimization: MDX files are compiled to static HTML at build time, enjoying the performance advantages of Static Site Generation (SSG), fast loading speeds, and SEO-friendly.
- Developer Experience: When writing content with Markdown, developers can focus on content creation without dealing with complex HTML tags and CSS styles. At the same time, MDX provides type safety and code hints, improving development efficiency.
In the Alignify project, we use MDX to write new articles, preserving both the simplicity of Markdown and the flexibility of React components. This approach is particularly suitable for scenarios requiring frequent content updates, unified styles, and embedded interactive components.
MDX Content Writing
The core advantage of MDX is that it supports both Markdown syntax and React components simultaneously, allowing you to write content with concise Markdown while embedding powerful React components. According to the [MDX official documentation](https://mdxjs.com/docs/using-mdx/#components), MDX compiles Markdown syntax to JavaScript and converts HTML elements to custom React components through component mapping mechanisms.
Markdown Syntax Usage
MDX supports full Markdown syntax while allowing React component embedding. Below introduces common Markdown syntax and its style performance in the Alignify project.
Format Syntax
MDX supports complete Markdown format syntax, including headings, lists, tables, code, text formatting, blockquotes, and horizontal rules. These syntax elements automatically apply unified styles through component mapping in mdx-components.tsx, without needing to manually add className.
Supported Format Syntax Types:
- Headings: Use
#to######to represent different heading levels, h2 and h3 are automatically added to the table of contents navigation - Lists: Unordered lists use
-,, or+, ordered lists use numbers with periods - Tables: Use pipe
|to separate columns, header rows need to addclassName="header-row" - Code: Inline code uses single backticks, code blocks use triple backticks, can specify language for syntax highlighting
- Text Formatting: Use
bold,italic,~~strikethrough~~, etc. - Blockquotes: Use
>to represent quoted content - Horizontal Rules: Use three or more
---,, or___
Syntax Examples
Below shows the actual effects of various format syntax:
Headings: Use different heading levels to organize content, h2 and h3 headings are automatically added to the table of contents navigation.
Lists: Lists automatically apply unified styles with appropriate spacing and indentation.
Unordered list example:
- First item
- Second item
- Third item
Ordered list example:
- First step
- Second step
- Third step
Table Example: Tables automatically apply border styles and responsive layout. Header rows need to add className="header-row" to apply background color.
| Feature | MDX | Markdown |
|---|---|---|
| React Components | Supported | Not Supported |
| Markdown Syntax | Supported | Supported |
| Code Highlighting | Supported | Supported |
Code: Use backticks to wrap inline code, use triple backticks to wrap code blocks. Can specify language (such as ```javascript) for syntax highlighting.
Inline code example: Use export const metadata to export metadata.
Code block example:
Text Formatting Example: Use bold to achieve bold text, use italic to achieve italic text, use ~~strikethrough~~ to achieve strikethrough text.
Blockquote Example: Blockquotes have a primary color border on the left, used to highlight important content.
This is a blockquote, typically used to quote others' viewpoints or important information. Blockquotes can help highlight important content and improve reading experience.
Horizontal Rule Example: Used to separate different sections.
Links and Media
Below shows the actual effects of links and media:
Link Usage Best Practices: In MDX files, strongly recommend using Markdown link syntax[text](URL) instead of JSX <a> tags. Markdown links automatically go through component mapping processing, ensuring external links automatically add UTM parameters, open in new tabs, and correctly handle internal/external links. If you must use JSX, use the exported <A> component (uppercase) instead of <a>.
Internal Link Example: Internal links use Next.js Link component, supporting client-side routing.
External Link Example: External links automatically add UTM parameters and open in a new tab.
[Next.js Official Website](https://nextjs.org)
Image Example: In MDX files, you can insert images using Markdown syntax or JSX syntax. Markdown syntax automatically applies styles and enables lazy loading. JSX syntax can override or extend default styles through className property.
YouTube Video Example: Simply add a YouTube link to automatically render as a video thumbnail. Supports youtube.com and youtu.be formats, link text automatically displays as video title, automatically adds UTM parameters, opens in a new tab.
React Component Integration
In MDX files, you can directly use React components. This provides great flexibility for content creation, allowing you to embed interactive components, custom styles, dynamic content, etc. Below introduces common component types in the Alignify project.
MDX Component Mechanism vs Component Library
When using MDX components, you need to understand the difference between two important concepts:
- [MDX Official Documentation](https://mdxjs.com/docs/using-mdx/#components): Explains the mechanism of "how to use components," including component mapping, Props passing, Layout wrapper, and other core concepts. This is not a component library, but a usage guide for the MDX framework.
- [shadcn/ui Component Library](https://ui.shadcn.com/): Provides specific UI components (such as Button, Card, Dialog, etc.), which is a complete component library. The Alignify project has installed 40+ shadcn/ui components, located in the
src/components/ui/directory.
The Relationship: MDX's component mechanism allows you to use any React component in MDX files, including all shadcn/ui components. You can uniformly manage styles through MDX's component mapping mechanism (mdx-components.tsx) while directly importing and using shadcn/ui components to build rich interactive interfaces.
Component Types Supported by MDX:
- All shadcn/ui components (40+)
- Custom components (such as BlogLayout, FAQ, YouTubeVideo)
- Third-party React component library components
- Components defined directly in MDX files
Layout Components
BlogLayout: The core layout component for articles, located at src/components/BlogLayout.tsx. It provides complete article display functionality, including title, excerpt, author information, table of contents navigation, author card, and related article recommendations. Supports responsive layout with a three-column design (table of contents + content + sidebar). Every MDX article needs to wrap content with BlogLayout.
Content Display Components
YouTubeVideo: Located at src/components/YouTubeVideo.tsx, used to render YouTube video thumbnails. Supports automatic detection of YouTube links and rendering as thumbnails with play buttons, clicking opens the video in a new tab. Can be used through Markdown link syntax or JSX <A> component.
FAQ Component: Located at src/components/FAQ.tsx, used to display frequently asked questions. Contains predefined questions and answers, improving user experience and SEO.
Interactive Components
FAQ: Located at src/components/FAQ.tsx, used to display frequently asked questions. Uses shadcn/ui's Accordion component to achieve collapse/expand effects, automatically generates FAQPage structured data (Schema.org) for SEO. Supports passing question lists and page URL.
UI Component Library (shadcn/ui)
The Alignify project uses [shadcn/ui](https://ui.shadcn.com/) as the UI component library, all components are located in the src/components/ui/ directory. The project has installed 40+ shadcn/ui components, including basic components, interactive components, form components, layout components, etc. You can import and use these components in MDX files.
Installed Component Types:
- Basic Components: Button, Card, Badge, Input, Label, Separator, etc.
- Interactive Components: Dialog, Accordion, Tabs, Dropdown Menu, Popover, Tooltip, etc.
- Form Components: Form, Checkbox, Radio Group, Select, Textarea, Switch, etc.
- Layout Components: Aspect Ratio, Resizable, Scroll Area, Skeleton, etc.
- Feedback Components: Alert, Toast, Progress, Skeleton, etc.
- Navigation Components: Navigation Menu, Breadcrumb, Pagination, Command, etc.
- Others: Carousel, Chart, Calendar, Avatar, Hover Card, etc.
Common Component Examples:
- Card Component: Used to create card containers, includes CardHeader, CardTitle, CardDescription, CardContent, CardFooter, and other sub-components
- Button Component: Provides various styles and sizes of buttons, supports different variants (default, destructive, outline, secondary, ghost, link)
- Badge Component: Used to display labels, badges, or status indicators, supports various color variants
- Tabs Component: Used to create tab interfaces, supports multiple content panel switching
- Accordion Component: Used to create collapsible panels, supports single or multiple panel expansion
- Dialog Component: Used to create modal dialogs, supports open/close animations
- Alert Component: Used to display alert messages, supports various types (default, destructive, warning)
Component Usage Examples
Using components in MDX files is very simple, just import at the top of the file, then use in content:
Tip: For more component usage methods, refer to component source code in the src/components/ui/ directory, or visit the [shadcn/ui official documentation](https://ui.shadcn.com).
Markdown vs JSX Selection Guide
In MDX, you can use both Markdown syntax and JSX syntax simultaneously. Choosing the appropriate syntax can make code more concise and easier to maintain. Below is a comparison table to help you quickly make choices.
| Use Case | Recommended Syntax | Example | Advantages |
|---|---|---|---|
| Headings, Paragraphs | Markdown | ## Heading | Concise code, automatic style application |
| Lists | Markdown | - List item | Intuitive syntax, easy to read |
| Links, Images | Markdown | [text](URL) | Automatic handling of internal/external links, adds UTM parameters |
| Text Formatting | Markdown | bold** | Concise syntax, easy to maintain |
| Interactive Components | JSX | | Supports dynamic interaction and complex logic |
| Custom Styles | JSX | | Flexible control of styles and layout |
| Complex Layouts | JSX | Grid, Flex layouts | Supports advanced layout requirements |
| Dynamic Content | JSX | Generated from data | Supports conditional rendering and data processing |
Summary: Prioritize Markdown syntax, code volume reduced by approximately 60-70%, automatic style application, easy to maintain. Only use JSX when special features are needed (interaction, custom styles, complex layouts, dynamic content).
Conclusion
This article distills actionable takeaways for “MDX Guide 2025: Complete Tutorial for Markdown+React Components in Next.js”. Turn the guidance into small, verifiable tasks and review outcomes with data—not vibes alone.
Latest 2025 MDX guide, Markdown syntax, React component integration, and style mapping. Reduce code by 60-70%, improve content cre… When policies or platforms change, verify against primary sources before updating claims.