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

بِسْمِ ٱللّٰهِ ٱلرَّحْمَـٰنِ ٱلرَّحِيمِ

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:

  1. Plain authoring: tables written in Markdown, not JSX.
  2. No client-side JavaScript: a table is content, not an application.
  3. Narrow screens: tables that work on a phone without breaking the layout.
  4. Both themes: tables that follow light and dark mode.
  5. 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` |
external link docs.astro.build /en/guides/integrations-guide/mdx

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.

LeftCenterRight
texttexttext
longer textlonger textlonger 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:

StepActionResult
1Install AstroProject scaffolded
2Write MDXContent ready
3Add the prose classTables 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:

WhatWhereCommand
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 serverRemote (~/.zshrc)export PULSE_SERVER='tcp:127.0.0.1:4713'
Fix ALSARemote (~/.asoundrc)pcm.!default { type pulse }
Install pluginsRemotesudo apt install libasound2-plugins pulseaudio-utils
internal link Claude Code Voice Over SSH When Your Server Has No Microphone

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:

StepToolKindInputOutputFails whenNotes
1BunPackage managerpackage.jsonnode_modules/A package cannot be resolvedbun install
2AstroSite buildersrc/dist/A schema or link check failsStatic build
3Og_ImageCard rendererCard manifestSocial cards in dist/The manifest is missingOne card per page
4CompressorPrecompressiondist/.br, .gz, .zst filesCompressed files already existText files only
5rsyncFile syncdist/New release folderThe copy is interruptedSymlink switch after

And a fifteen-column stress test, where the scroll wrapper does its work:

ABCDEFGHIJKLMNO
valvalvalvalvalvalvalvalvalvalvalvalvalvalval
alphabetagammadeltaepsilonzetaetathetaiotakappalambdamunuxiomicron
123456789101112131415

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

ConcernSolutionCost
AuthoringGFM pipe tablesNone, enabled in Astro’s MDX by default
Base stylingTailwind Typography proseNone, if Tailwind is already in use
Long contentoverflow-wrap: anywhere on code in cellsCSS only; paths break mid-word
Readable columnsmin-width: 8ch on cellsCSS only
Wide tables.table-wrapper with overflow-x: autoOne small component; columns hidden until scrolled
Keyboard accesstabindex="0", role="region" on the wrapperPart of the same component
Header fontfont-family: var(--font-primary) on thCSS only
Both themes--tw-prose-* custom propertiesNone, inherited from prose
JavaScriptNoneNone 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.

AI

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.