shinyaz.com

Fix Markdown table column wrapping with CSS white-space: nowrap

1 min read

In an MDX blog, a Markdown table with short Japanese text in the first column ("新規", "変更" — two full-width characters each) was wrapping vertically, putting each character on its own line.

My first attempt was a Markdown-side fix — widening the separator dashes and adding space padding in cells:

| 区分   | ファイル | 内容 |
|--------|---------|------|
| 新規   | `src/lib/tils.ts` | TIL query functions |

It didn't work. Most Markdown renderers ignore separator width as a column-width hint, and cell padding gets trimmed.

The fix was adding table styles to .prose in CSS:

src/app/globals.css
.prose {
  & table {
    & td:first-child {
      white-space: nowrap;
    }
  }
}

Applying white-space: nowrap to the first column prevents wrapping regardless of content length. CSS is the right layer for this — Markdown has no reliable column-width mechanism.

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this blog.