Tables in MDX Without External Libraries
GFM Pipes, CSS, and One Astro Component
- Subject
- Web
- Sheet
- 4 of 8
- Date
- 21 Shawwal 1447
- Reading
- 7 min
بِسْمِ ٱللّٰهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ
Size
Spacing
Font
Static tables, not data grids
A blog post in MDX needs a table sooner or later. Search for one and the results are TanStack Table, AG Grid, shadcn/ui Table and a dozen more packages, all built for interactive data grids with sorting, filtering and pagination.
A post has none of those needs. Its tables are static content: rows and columns of text and code. What they actually need is:
- Plain authoring: tables written in Markdown, not JSX.
- No client-side JavaScript: a table is content, not an application.
- Narrow screens: tables that work on a phone without breaking the layout.
- Both themes: tables that follow light and dark mode.
- Long content: file paths and commands that do not blow out the column widths.
All five work without an external library. Every table in this post is rendered with the approach it describes.
Writing the table
GFM (GitHub Flavored Markdown) pipe tables are part of Astro’s MDX pipeline: the MDX integration enables GFM by default, so there is nothing to install. The source looks like this:
| What | Where | Command ||------|-------|---------|| TCP module | Local | Add `"tcp:127.0.0.1:4713"` to `server.address` || SSH tunnel | Local (`~/.ssh/config`) | `RemoteForward 4713 127.0.0.1:4713` |Astro renders a real <table> with <thead>, <tbody>, <tr>, <th> and <td>. No imports and no component tags in the content file.
GFM also sets column alignment in the separator row: :--- for left, :---: for center, ---: for right.
| Left | Center | Right |
|---|---|---|
| text | text | text |
| longer text | longer text | longer text |
What the prose class already does
A site on Tailwind CSS most likely uses @tailwindcss/typography. Its prose class styles every table inside the article: padding, borders, header weight, and colours taken from the --tw-prose-* variables, so the table follows the theme along with the text. Together with GFM, that covers simple tables with no extra work:
| Step | Action | Result |
|---|---|---|
| 1 | Install Astro | Project scaffolded |
| 2 | Write MDX | Content ready |
| 3 | Add the prose class | Tables styled |
Long content in cells
Real content breaks this quickly. The browser sizes columns by their content, and a cell with ~/.config/pipewire/pipewire-pulse.conf asks for more width than the article has.
This table comes from a real setup, the audio forwarding in the Claude Code voice post. Narrow the browser window to see how it behaves:
| What | Where | Command |
|---|---|---|
| TCP module (permanent) | Local (~/.config/pipewire/pipewire-pulse.conf) | Add "tcp:127.0.0.1:4713" to server.address |
| SSH tunnel (permanent) | Local (~/.ssh/config) | RemoteForward 4713 127.0.0.1:4713 under Host your-server |
| Set audio server | Remote (~/.zshrc) | export PULSE_SERVER='tcp:127.0.0.1:4713' |
| Fix ALSA | Remote (~/.asoundrc) | pcm.!default { type pulse } |
| Install plugins | Remote | sudo apt install libasound2-plugins pulseaudio-utils |
A few CSS rules
A handful of rules in the prose stylesheet handle it, with no JavaScript:
/* The wrapper div comes from a component override (next section) */& .table-wrapper { overflow-x: auto;}
& table { min-width: 100%;}
& th { font-family: var(--font-primary);}
& td, & th { min-width: 8ch;}
& td code, & th code { overflow-wrap: anywhere;}What each rule does
min-width: 100% on the table: it fills the prose column at least. If the column minimums push it wider, the table grows and the wrapper scrolls the excess.
overflow-wrap: anywhere on code inside cells: long unbroken strings such as file paths and commands break inside their column instead of stretching it.
The scope matters. Astaghfirullah, the first version set overflow-wrap: anywhere on whole cells, plus word-break: break-word on the table. Both also lower the narrowest width a column may take, so in the seven-column table further down the browser squeezed columns and split ordinary words: “Compre” on one line, “ssor” on the next. Applied to code only, words stay whole, paths still wrap, and a table that cannot fit scrolls instead.
min-width: 8ch on the cells: columns never collapse below a readable width. When many columns push the total past the container, the table grows and the wrapper scrolls. Without it, a fifteen-column table would squeeze every cell to a few characters.
font-family: var(--font-primary) on headers: table headers use the same font as the post’s headings.
overflow-x: auto on the wrapper: the safety net. If a table is still too wide after breaking, the wrapper scrolls sideways instead of pushing into the rest of the layout.
The cost: a path that breaks mid-word is harder to read and to copy by eye, and a table that scrolls hides some of its columns on a phone, as the seven-column table below does. For reference tables in a post, both are better than a layout that breaks.
One component for the wrapper
The scroll wrapper needs a <div> around the <table>, and CSS cannot add a parent element. Astro’s MDX components prop can, without touching a single MDX file. The component:
---/* Table_Wrapper.astro: wraps GFM pipe tables in a scrollable container */---<div class="table-wrapper" tabindex="0" role="region" aria-label="Table"> <table><slot /></table></div>tabindex="0" makes the scroll area reachable by keyboard, so a wide table can be scrolled with the arrow keys; role="region" with a label tells a screen reader what that focus stop is.
It goes into the components map that every post receives through <Content components={mdx_Components} />:
export const mdx_Components = { h1: Header_Lvl_1, h2: Header_Lvl_2, table: Table_Wrapper, // every pipe table gets the wrapper};Authors keep writing | ... |. The wrapper is invisible to them, and every pipe table in every post gets it.
Wide tables
A seven-column table, here the steps of this site’s build and deploy pipeline:
| Step | Tool | Kind | Input | Output | Fails when | Notes |
|---|---|---|---|---|---|---|
| 1 | Bun | Package manager | package.json | node_modules/ | A package cannot be resolved | bun install |
| 2 | Astro | Site builder | src/ | dist/ | A schema or link check fails | Static build |
| 3 | Og_Image | Card renderer | Card manifest | Social cards in dist/ | The manifest is missing | One card per page |
| 4 | Compressor | Precompression | dist/ | .br, .gz, .zst files | Compressed files already exist | Text files only |
| 5 | rsync | File sync | dist/ | New release folder | The copy is interrupted | Symlink switch after |
And a fifteen-column stress test, where the scroll wrapper does its work:
| A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
val | val | val | val | val | val | val | val | val | val | val | val | val | val | val |
| alpha | beta | gamma | delta | epsilon | zeta | eta | theta | iota | kappa | lambda | mu | nu | xi | omicron |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
On a desktop, breaking keeps ordinary tables inside the column. On a phone, or with extreme column counts, the wrapper scrolls sideways and the table stays inside the article.
What reaches the browser
Everything is compiled at build time. The output is static HTML and CSS, with no hydration and no framework island:
<div class="table-wrapper" tabindex="0" role="region" aria-label="Table"> <table> <thead><tr><th>What</th><th>Where</th></tr></thead> <tbody><tr><td>Value</td><td>Value</td></tr></tbody> </table></div>The whole setup
| Concern | Solution | Cost |
|---|---|---|
| Authoring | GFM pipe tables | None, enabled in Astro’s MDX by default |
| Base styling | Tailwind Typography prose | None, if Tailwind is already in use |
| Long content | overflow-wrap: anywhere on code in cells | CSS only; paths break mid-word |
| Readable columns | min-width: 8ch on cells | CSS only |
| Wide tables | .table-wrapper with overflow-x: auto | One small component; columns hidden until scrolled |
| Keyboard access | tabindex="0", role="region" on the wrapper | Part of the same component |
| Header font | font-family: var(--font-primary) on th | CSS only |
| Both themes | --tw-prose-* custom properties | None, inherited from prose |
| JavaScript | None | None shipped |
A data-grid library solves problems a post does not have. For static tables, Markdown, a few CSS rules and one wrapper component are the whole job.
Like every post here: drafted with my AI assistant. I use AI every day, openly. My assistant has read the brand docs, the voice rules, the honesty rules, and the whole writing system. Shaped for this site, not a generic tool.
Web 4 of 8
Back to Web