A unified diff is a table: old line number, new line number, the line. Added lines get a green wash, removed ones a red wash, and the gutter of each takes a stronger tint so changes can be found by scanning the edge. The + and − come from CSS, so selecting and copying the code gives clean lines. Hunk headers sit on a faint blue band with the function they are in.
Old on the left, new on the right, for config and short files where the before matters as much as the after. A side with no line is hatched. Inside a changed line, <del> and <ins> mark the words that changed, which in YAML is usually the only thing worth reading.
Dense, and changed files
Light
services/checkout/retry.ts+2−2
@@ -17,4 +17,4 @@ export async function charge(orderId: string) {
17
17
const order = await db.lock(orderId)
18
await drainRetries(order)
18
queue.drainInBackground(order.id)
19
19
await db.commit()
38 lines hidden
Dark
services/checkout/retry.ts+2−2
@@ -17,4 +17,4 @@ export async function charge(orderId: string) {
17
17
const order = await db.lock(orderId)
18
await drainRetries(order)
18
queue.drainInBackground(order.id)
19
19
await db.commit()
38 lines hidden
390px, dark
services/checkout/retry.ts+2−2
@@ -17,4 +17,4 @@ export async function charge(orderId: string) {
.diff.dense is for a diff inside a tool call or a pane: 11.5px mono on 20px lines, a 28px file head, tighter line numbers. Also set by data-density="dense" on an ancestor.
A changed-file row is 24px: a change letter in its tone, the folder, the file name in ink and the line counts. The folder truncates, the name never does. The letter's word is in its title and accessible name, and a deleted file is also struck through, so the change reads without colour.
Class
On
What it does
.diff
div
The frame. .split for side by side.
.diff-file
div
File header: .path, .diff-n counts, actions.
.diff-scroll
div
Sideways scroll for long lines; code never wraps.
tr.add / tr.del
tr
A whole added or removed line (unified).
td.ln / td.cd
td
Line number and code. In split view, put .add, .del or .none on the cells.
tr.hunk
tr
The @@ header, one cell spanning the row.
tr.fold
tr
Collapsed unchanged lines: "38 lines hidden".
ins / del
td.cd
The changed words inside a line.
.dense
.diff
11.5px mono on 20px lines, a 28px file head. Also set by data-density="dense".
.diff-rows
ul
A list of changed files.
.diff-row
a, button, div
One changed file, 24px: .diff-row-mark, .diff-row-path (a span for the folder, b for the name) and .diff-n.
data-change
.diff-row
modified (default), added, deleted, renamed.
Do
Word-level marks for one-token changes; without them the reader diffs the two lines by eye.
Three lines of context around each change, and a fold for the rest.
The counts in the file header, so a 400-line change is obvious before it is opened.
Don't
Wrapping code lines. Scroll sideways instead.
Green and red text on top of green and red washes.
Hiding whitespace changes without saying so.
Accessibility
Colour is not the only signal: a changed line has a sign before its code and only one line number. Add a visually hidden "added" or "removed" in each changed row for screen readers.
Keep the table semantics; a diff read row by row is still a diff.