Custom styles and branding

Load a branded DOCX template to define document styles, fonts, and table defaults.

DOCX styles control document content. Interface CSS controls the editor's appearance. Load a branded .docx template to set headings, fonts, colors, spacing, and table styles.

Load a branded template

Fetch the template and pass it as the document:

import { useEffect, useState } from 'react';
import { DocxEditor } from '@docx-editor.dev/react';
import '@docx-editor.dev/core/styles/editor.css';

export function BrandedEditor() {
  const [template, setTemplate] = useState<ArrayBuffer>();

  useEffect(() => {
    fetch('/templates/brand.docx')
      .then((r) => r.arrayBuffer())
      .then(setTemplate);
  }, []);

  return <DocxEditor document={template} />;
}

Save preserves styles.xml, theme1.xml, and settings.xml instead of regenerating them.

Prepare document styles

  1. Create a document with your styles, including Normal, Heading1 to Heading9, and table styles.
  2. Remove the document content.
  3. Save the file as your template.
Style elementEditor behavior
Paragraph stylesListed in the style picker. Applying one uses its configured next style for the following paragraph.
Existing table stylesResolved with basedOn inheritance and kept on save.
Default table styleNot applied to new tables. New tables use explicit single-line borders.
Embedded fontsLoaded, rendered, listed in the font picker, and kept on save.

Configure brand fonts

Pass brand fonts through the fonts prop, built with loadFonts. For sources, loading, and failures, see Fonts and measurement.

Limits

  • The style picker does not filter w:qFormat, w:semiHidden, or w:hidden. To restrict it, see Document styles.
  • New tables do not use the document's default table style.
  • CSS @font-face rules and system fonts affect rendering only. They do not provide measurement bytes, so text uses estimated metrics.

See also