Review colors and styling

Color tracked changes and comments by author or change type, add avatars, and style review chrome with CSS tokens.

Each author gets one color for tracked changes and comments. Authors take slots --doc-review-author-0 through --doc-review-author-7 in first-appearance order, and the palette repeats after eight authors.

For marks, named colors, change bar position, and cell shading, see Customize revision markup.

Set author styles

Mount AuthorStyle and ColorByChangeType declarations anywhere inside the editor root:

import { DocxEditor } from '@docx-editor.dev/react';
import { reviewModule } from '@docx-editor.dev/pro/react';

const MODULES = [reviewModule()];

<DocxEditor.Root document={bytes} modules={MODULES} author="Jess Lin">
  <DocxEditor.AuthorStyle author="Jess Lin" color="#7c3aed" avatarUrl="/avatars/jess.png" />
  <DocxEditor.ColorByChangeType />
  <DocxEditor.Viewport>
    <DocxEditor.Content />
  </DocxEditor.Viewport>
</DocxEditor.Root>;
AuthorStyle propEffect
authorExact w:author value to match.
colorDocument ink, decorations, and card accents.
backgroundBackground tint behind that author's changes.
activeBackgroundHighlight band of the open change. Removes its default underline.
spanClassName / span-class-nameClasses on painted change spans.
avatarUrl / avatar-urlReview card avatar.

ColorByChangeType colors unmatched insertions green and deletions red. Author declarations take precedence for matched authors. Declarations render no DOM elements, and changing one repaints without resetting selection or undo history.

Update styles through the editor

Call setRevisionStyles with a RevisionStyles value. A headless host can pass revisionStyles when it creates the editor:

editor.setRevisionStyles({
  others: 'kind', // 'author' (default) or 'kind'
  authors: {
    'Jess Lin': '#7c3aed',
    'Sam Reyes': { color: '#0e7490', avatarUrl: '/avatars/sam.png' },
  },
});

Use declarations or setRevisionStyles as the single source of style state. A setRevisionStyles call replaces mounted declarations until a declaration changes.

Read authors and add avatars

useReviewAuthors() returns the document's authors for legends and color controls. Without an adapter, call getReviewAuthors(). React returns the list directly, and Vue returns a shallow ref.

Field or behaviorDetail
OrderTracked-change authors first, then comment-only authors.
slotUnbounded first-appearance rank. The CSS slot is slot % 8.
colorResolved card color, such as var(--doc-review-author-N).
UpdatesAfter document load and style changes.

useReviewAuthor returns one author's resolved color, slot, and declared style. In Vue, it accepts a ref or getter and returns a computed ref. Add .docx-editor to a legend or its ancestor so palette tokens resolve.

Set avatarUrl to replace initials on review cards. A rejected URL falls back to initials.

avatarUrl valueResult
Host URLAccepted
Application-held blob: URLAccepted
Non-SVG data:image/* URLAccepted
SVG data image or other data: URLRejected
Script scheme or protocol-relative hostRejected

The packaged image uses referrerPolicy="no-referrer". The editor never loads an avatar address from the document.

Customize CSS tokens

Override tokens under .docx-editor, and load your stylesheet after editor.css:

.docx-editor {
  --doc-review-author-0: #7c3aed;
  --doc-review-author-1: #0e7490;
  --doc-revision-insertion-decoration-style: dashed;
  --doc-revision-insertion-decoration-thickness: 0.08em;
}
TokenUse
--doc-review-author-0 through --doc-review-author-7Author palette.
--doc-revision-insertion, --doc-revision-deletionColors under ColorByChangeType.
--doc-revision-insertion-decoration-styleUnderline style, such as dotted.
--doc-revision-insertion-decoration-thicknessUnderline thickness. Default: 0.06em.
--doc-revision-insertion-underline-offsetUnderline distance. Default: 0.15em.
--doc-revision-color-<name>On-screen value of a named markup color.
--doc-review-author-currentThe element's author color on bands, cards, replies, balloons, and markers.

Painted spans carry data-review-author. Bands, cards, replies, balloons, markers, and pilcrows also carry data-review-author-slot. Spans use inline ink, so a selector cannot override it. Use currentColor for metric-safe effects:

.docx-editor [data-review-author='Jess Lin'] {
  outline: 1px dotted currentColor;
}

Style the change bar

Change bars use separate tokens for All Markup and Simple Markup. They paint outside the dark-mode inversion, so define dark values too:

.docx-editor {
  --doc-review-change-bar: #8a8a8a;
  --doc-review-change-bar-width: 2px;
  --doc-review-change-bar-simple: #d32f2f;
  --doc-review-change-bar-simple-width: 3px;
}
.docx-editor.dark {
  --doc-review-change-bar: #b0b0b0;
  --doc-review-change-bar-simple: #ef5350;
}

Each .docx-change-bar sits in one .docx-change-bars overlay per page. It carries docx-change-bar-insertion, docx-change-bar-deletion, or docx-change-bar-format, plus data-docx-story.

To color bars by kind, redefine --doc-review-change-bar on those classes. To hide them, set display: none on .docx-change-bars.

Export the same preferences

Pass the viewer state to the PDF exporter:

Exporter optionSource
revisionMarkupeditor.snapshot().revisionMarkup
displayModeeditor.snapshot().reviewDisplayMode
revisionAuthorSlotsThe session's author color assignments.

PDF output uses named print colors and the default author palette. Host CSS and revisionStyles colors do not apply. Pass revisionAuthorSlots to keep the session's color assignments after edits.

Limits

  • Author matching uses the exact document name. It does not prove identity, because a sender can use any name.
  • Keep span CSS metric-safe. Font size, weight, or family changes make painted text differ from measured layout.
  • --doc-review-author-current holds the light-theme value in both themes. Add a dark rule when you tint by author.
  • Comment highlights use one yellow for all authors by default.

See also