Skip to content

fix(code-block): size line-number gutter to the widest line number - #483

Open
drPod wants to merge 1 commit into
vercel:mainfrom
drPod:fix/code-block-line-number-gutter-width
Open

fix(code-block): size line-number gutter to the widest line number#483
drPod wants to merge 1 commit into
vercel:mainfrom
drPod:fix/code-block-line-number-gutter-width

Conversation

@drPod

@drPod drPod commented Aug 27, 2026

Copy link
Copy Markdown

The line number is a fixed-width inline-block (before:w-8, 32px) with a 16px margin (before:mr-4). At 14px a mono digit is ~8.4px, so three digits fit and anything longer spills past the box into the gap: at 4 digits the gap shrinks to ~14px, at 5 to ~6px, and at 6 the number overlaps the code.

With showLineNumbers, <code> is now a two-column grid and each line is display: contents, so the ::before number and the line's content span are grid items and the number column sizes to the widest line number. before:min-w-12 (48px incl. padding) keeps blocks up to 999 lines pixel-identical to today; only wider numbers change. Line numbers stay ::before, so select/copy still returns only the code.

Before / After

ai-elements-code-block-gutter-before-after

Related issues: none. pnpm check and pnpm test pass. Includes a patch changeset.

The line number was a fixed-width inline-block (w-8, 32px) followed by a
16px margin. A 14px mono digit is ~8.4px, so three digits fit but longer
numbers spill past the box into the gap: at four digits the gap shrinks to
~14px, at five to ~6px, and at six the number overlaps the code.

Make <code> a two-column grid with line numbers on, render each line as
display: contents, and let the ::before number and the content span be
grid items. The number column now sizes to the widest line number, with
min-w-12 (48px, incl. 16px padding) keeping blocks up to 999 lines
pixel-identical to before.
Copilot AI lite review requested due to automatic review settings August 27, 2026 22:44
@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

@drPod is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants