Diff Viewer
Read-only line diff of two texts, unified or side by side, with folded unchanged lines and word highlights.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
original | string | — | The text before the change. |
modified | string | — | The text after the change. |
mode | DiffViewerMode | unified | unified draws removed and added lines in one column; split draws the original on the left and the modified
text on the right, and draws unified while the element is narrower than --c2-diff-viewer--split-min-width. |
context | number | 3 | Unchanged lines kept above and below each change; longer unchanged runs fold into a row that opens on click. A negative number shows every line. |
line-numbers | boolean | false | Shows the original and modified line numbers beside each line. |
original-label | string | — | Name of the original text, shown in the header (a file name, "Current", "v12"). |
modified-label | string | — | Name of the modified text, shown in the header. |
label | string | — | Accessible name of the diff. Defaults to "Changes". |
Events
| Name | Type | Description |
|---|---|---|
fold-expand | CustomEvent<DiffFoldExpandDetail> | Fired when the reader opens a folded run of unchanged lines; detail holds the run's first line number in each text (originalStart, modifiedStart) and its line count. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
header | Header row above the lines, shown when original-label or modified-label is set. |
original-label | Name of the original text in the header. |
modified-label | Name of the modified text in the header. |
stats | Counts of added and removed lines in the header. |
body | Scrolling area holding the table of lines. |
line | Every row of lines (not the fold rows). |
line-number | Every line-number cell. |
marker | The cell before each line's text, holding + or − on a changed line. |
content | Every cell holding a line's text. |
word | A run of changed words inside a changed line. |
fold | The button standing for a run of folded unchanged lines. |
no-newline | Note after a last line that ends without a line break. |
empty | "No changes" message shown when both texts are identical. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-diff-viewer--background-color | background-color | #ffffff | |
--c2-diff-viewer--color | color | #18181b | |
--c2-diff-viewer--border | border | 1px solid #e4e4e7 | |
--c2-diff-viewer--border-radius | border-radius | 8px | |
--c2-diff-viewer--max-height | max-height | none | The lines scroll past this height. |
--c2-diff-viewer--split-min-width | pixel | 600px | Below this width, in pixels, mode="split" draws the unified layout. Read by script when the element resizes. |
--c2-diff-viewer__code--font-family | font-family | ui-monospace, SFMono-Regular, Menlo, Consolas, monospace | |
--c2-diff-viewer__code--font-size | font-size | 13px | |
--c2-diff-viewer__code--line-height | line-height | 1.5 | |
--c2-diff-viewer__code--tab-size | tab-size | 2 | |
--c2-diff-viewer__code--white-space | white-space | pre-wrap | pre keeps long lines on one line and scrolls them sideways. |
--c2-diff-viewer__header--background-color | background-color | #fafafa | |
--c2-diff-viewer__header--color | color | #18181b | |
--c2-diff-viewer__header--border-bottom | border | 1px solid #e4e4e7 | |
--c2-diff-viewer__header--padding | padding | 8px 12px | |
--c2-diff-viewer__header--font-size | font-size | 12px | |
--c2-diff-viewer__header--font-weight | font-weight | 600 | |
--c2-diff-viewer__stats__added--color | color | #15803d | |
--c2-diff-viewer__stats__removed--color | color | #dc2626 | |
--c2-diff-viewer__divider--border | border | 1px solid #e4e4e7 | Line between the two sides of the split layout. |
--c2-diff-viewer__line--padding | padding | 0 12px 0 4px | |
--c2-diff-viewer__line__added--background-color | background-color | rgba(22, 163, 74, 0.12) | |
--c2-diff-viewer__line__removed--background-color | background-color | rgba(220, 38, 38, 0.12) | |
--c2-diff-viewer__line__empty--background-color | background-color | #fafafa | Blank side of a split row whose line exists on the other side only. |
--c2-diff-viewer__word--border-radius | border-radius | 2px | |
--c2-diff-viewer__word__added--background-color | background-color | rgba(22, 163, 74, 0.3) | |
--c2-diff-viewer__word__removed--background-color | background-color | rgba(220, 38, 38, 0.3) | |
--c2-diff-viewer__line-number--color | color | #71717a | |
--c2-diff-viewer__line-number--width | pixel | 5ch | |
--c2-diff-viewer__line-number--padding | padding | 0 8px | |
--c2-diff-viewer__line-number__added--color | color | #18181b | |
--c2-diff-viewer__line-number__added--background-color | background-color | rgba(22, 163, 74, 0.2) | |
--c2-diff-viewer__line-number__removed--color | color | #18181b | |
--c2-diff-viewer__line-number__removed--background-color | background-color | rgba(220, 38, 38, 0.2) | |
--c2-diff-viewer__marker--width | pixel | 2.5ch | |
--c2-diff-viewer__marker__added--color | color | #15803d | |
--c2-diff-viewer__marker__removed--color | color | #dc2626 | |
--c2-diff-viewer__fold--background-color | background-color | #fafafa | |
--c2-diff-viewer__fold--color | color | #71717a | |
--c2-diff-viewer__fold--padding | padding | 4px 12px | |
--c2-diff-viewer__fold__hover--color | color | rgb(2, 101, 220) | |
--c2-diff-viewer__fold__focus--outline | outline | 2px solid rgba(2, 101, 220, 0.4) | |
--c2-diff-viewer__no-newline--color | color | #71717a | |
--c2-diff-viewer__empty--color | color | #71717a | |
--c2-diff-viewer__empty--padding | padding | 8px 12px | |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under diff-viewer, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
label | Changes | — |
original | Original | — |
modified | Modified | — |
originalLine | Original line | — |
modifiedLine | Modified line | — |
change | Change | — |
text | Text | — |
added | Added | — |
removed | Removed | — |
summary | {0} additions, {1} deletions | {0} additions {1} deletions |
expand | Show {0} unchanged lines | {0} count |
noChanges | No changes | — |
noNewline | No newline at end of file | — |