Appearance
Theme the DOCX editor interface with CSS color tokens, dark mode, interface fonts, and control states.
Theme the editor interface with --doc-* CSS properties on the .docx-editor element. Themes never change saved document formatting.
Apply a theme
Map your tokens to both editor palettes. Load this CSS after @docx-editor.dev/core/styles/editor.css.
.docx-editor.contract-workspace,
.docx-editor.contract-workspace.dark {
--doc-primary: var(--app-brand);
--doc-primary-hover: var(--app-brand-hover);
--doc-primary-light: var(--app-brand-surface);
--doc-on-primary: var(--app-on-brand);
--doc-focus-ring: var(--app-focus-ring);
--primary: var(--app-brand-hsl);
--primary-foreground: var(--app-on-brand-hsl);
--ring: var(--app-brand-hsl);
}--doc-* properties take CSS colors. Utility properties such as --primary take bare HSL components.
Set colorMode on DocxEditor.Root or the packaged DocxEditor.
<div className="docx-editor contract-workspace">
<DocxEditor.Root document={bytes} colorMode="system">
{/* Toolbar, Viewport, Content */}
</DocxEditor.Root>
</div><template>
<div class="docx-editor contract-workspace">
<DocxEditor.Root :document="bytes" color-mode="system">
<!-- Toolbar, Viewport, Content -->
</DocxEditor.Root>
</div>
</template>colorMode takes 'light' (default), 'dark', or 'system'. Dark mode adds .dark beside .docx-editor on each scoped part. For details, see Dark mode.
Choose theme properties
Interface palette reference
These properties take CSS colors.
| Purpose | Properties |
|---|---|
| Main surfaces | --doc-surface, --doc-popover-bg, --doc-card, --doc-bg, --doc-bg-subtle |
| Hover, input | --doc-bg-hover, --doc-bg-input |
| Primary actions | --doc-primary, --doc-primary-hover, --doc-primary-light, --doc-on-primary |
| Assistant accents | --doc-accent, --doc-accent-bg |
| Active toggles | --doc-toggle-active-bg, --doc-toggle-active-fg |
| Text and icons | --doc-text, --doc-popover-fg, --doc-text-muted, --doc-text-subtle, --doc-text-placeholder |
| Borders | --doc-border, --doc-border-light, --doc-border-dark, --doc-border-input |
| Errors, destructive | --doc-error, --doc-error-bg, --doc-danger, --doc-destructive, --doc-destructive-hover-bg |
| Success | --doc-success, --doc-success-bg |
| Warnings | --doc-warning, --doc-warning-bg, --doc-warning-text |
| Links | --doc-link |
| Focus, selection | --doc-focus-ring, --doc-selection, --doc-cell-selection |
| Highlights | --doc-text-highlight-color, --doc-text-highlight-active-color, --doc-refresh-highlight-color, --doc-anchor-highlight-color |
| Caret | --doc-caret, --doc-caret-contrast |
| Field shading | --doc-field-shading |
| Shadow and overlay colors | --doc-shadow, --doc-shadow-strong, --doc-shadow-subtle, --doc-overlay |
Full box-shadow values | --doc-card-shadow, --doc-card-shadow-strong, --doc-shadow-lg |
| Scrollbars | --doc-scrollbar-thumb, --doc-scrollbar-thumb-hover, --doc-scrollbar-track |
For revision, author, and comment colors, see Review styling.
Utility palette reference
Utility classes such as bg-primary read these. Values are HSL components without hsl(), such as 221.2 83.2% 53.3%.
| Purpose | Properties |
|---|---|
| Base interface | --background, --foreground |
| Cards, popovers | --card, --card-foreground, --popover, --popover-foreground |
| Actions | --primary, --primary-foreground, --secondary, --secondary-foreground |
| Secondary surfaces | --muted, --muted-foreground, --accent, --accent-foreground |
| Destructive | --destructive, --destructive-foreground |
| Inputs, focus | --border, --input, --ring |
| Corner radius | --radius |
Size, typography, and layer reference
| Property | Default |
|---|---|
--doc-font-ui | System font stack. |
--doc-dialog-font-family | --doc-font-ui. |
--doc-dialog-font-size | 13px. |
--doc-dialog-radius | 8px. |
--doc-dialog-control-radius | 4px. |
--doc-dialog-padding | 24px. Takes one length. |
--doc-dialog-gap | 12px. |
--doc-scrollbar-size | 14px. |
--doc-hf-dim-opacity | 0.45 in light mode. Dims body text during header editing. |
--doc-motion-ease-out | Shared transition timing function. |
--doc-z-chrome | 40. Persistent interface elements. |
--doc-z-overlay | 50. Menus and temporary surfaces. |
--doc-z-context | 55. Context menu. |
Style control states
Add your own class through a part's className prop.
.docx-editor.contract-workspace .contract-toolbar [data-active] {
background: var(--doc-toggle-active-bg);
}
.docx-editor.contract-workspace .contract-toolbar [data-disabled] {
opacity: 0.5;
}Toolbar buttons expose data-active and data-disabled presence attributes. For review card attributes, see Comments and review cards.
Limits
- Put the theme class on the element that carries
.docx-editor. Nested scopes, dialogs, and pop-out windows each need the theme. - Write dark overrides as
.docx-editor.<your-class>.dark, after the editor stylesheet. - Dark mode changes on-screen colors only. Saved document colors stay unchanged.
- Keep the
--doc-z-*order. An ancestor stacking context can still clip an overlay.