MDX and Markdown
Learn how to use MDX and Markdown for content routes in Bini.js.
What is MDX?
MDX is an extension to Markdown that allows you to write JSX components directly in your Markdown files. Bini.js supports .mdx and .md files as content routes out of the box.
@mdx-js/rollup is bundled internally, so no separate installation or Vite configuration is required. This makes it easy to create rich, interactive content pages.
MDX Pages
Create an MDX page by adding a .mdx file anywhere in src/app/. The file is compiled to a React component and rendered as a page.
Markdown Pages
Bini.js also supports plain .md files. They go through the same MDX pipeline, which means they also support JSX and imports.
Both .mdx and .md are compiled through the same MDX pipeline with full JSX, import, and export support. There is no plain-markdown-only mode.
Metadata in MDX
Export metadata from any MDX page to set page titles, descriptions, and Open Graph tags.
Root layout metadata is injected into index.html at build time. Nested layout titles update document.title at runtime.
Imports in MDX
You can import components, utilities, and other files directly in MDX:
Auto-imports (useState, Link, getEnv, etc.) apply to MDX files the same as any other page.
Extension Priority
When multiple files share the same base name in a folder, Bini.js uses this priority order:
.tsx > .jsx > .ts > .js > .mdx > .mdFor example, if both page.tsx and page.mdx exist in the same folder:
page.tsxwill be used (higher priority)page.mdxis ignored
Styling MDX Content
CSS Modules, plain CSS imports, and Tailwind utility classes work directly in MDX files:
Note: Tailwind's Preflight reset strips default styling from headings and bold text. Wrap plain-markdown regions in a prose class from @tailwindcss/typography if you want them to look styled by default.
MDX Configuration
You can pass options directly to the bundled @mdx-js/rollup plugin via the biniroute() configuration:
This is useful for adding syntax highlighting, custom markdown transformations, or other content processing.
Complete Example
Here is a comprehensive example showing MDX and Markdown usage: