Skip to Content
Nextra 4.0 is released. Read more
DocumentationAdvancedRendering Tables

Rendering Tables

This guide covers different ways to render tables in MDX, including GFM syntax and literal HTML tag.

GFM syntax

In Markdown, it is preferable to write tables via GFM syntax .

MDX
| left   | center | right |
| :----- | :----: | ----: |
| foo    |  bar   |   baz |
| banana | apple  |  kiwi |

will be rendered as:

leftcenterright
foobarbaz
bananaapplekiwi

Literal HTML Tables

If you try to render table with literal HTML elements <table>, <thead>, <tbody>, <tr>, <th> and <td> – your table will be unstyled because MDX  doesn’t replace literal HTML elements with components provided by useMDXComponents()1.

💡

Instead, use the built-in <Table> component available via nextra/components.

Changing Default Behaviour

If you want to use standard HTML elements for your tables but have them styled with components provided by useMDXComponents()1, you can do this by configuring Nextra.

To achieve this, pass the whiteListTagsStyling option to the Nextra function, including an array of tags you want to replace.

Here’s an example configuration in your next.config.mjs file:

next.config.mjs
import nextra from 'nextra'
 
const withNextra = nextra({
  whiteListTagsStyling: ['table', 'thead', 'tbody', 'tr', 'th', 'td']
})
 
export default withNextra()

In this example, the tags <table>, <thead>, <tbody>, <tr>, <th>, and <td> will be replaced with corresponding MDX components, allowing for customized styling.

Footnotes

  1. https://mdxjs.com/packages/vue/#usemdxcomponentscomponents  ↩ ↩2

Last updated on