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} />;
}<script setup lang="ts">
import { DocxEditor, useDocxSource } from '@docx-editor.dev/vue';
import '@docx-editor.dev/vue/styles.css';
const { document: template } = useDocxSource('/templates/brand.docx');
</script>
<template>
<DocxEditor :document="template" />
</template>Save preserves styles.xml, theme1.xml, and settings.xml instead of regenerating them.
Prepare document styles
- Create a document with your styles, including
Normal,Heading1toHeading9, and table styles. - Remove the document content.
- Save the file as your template.
| Style element | Editor behavior |
|---|---|
| Paragraph styles | Listed in the style picker. Applying one uses its configured next style for the following paragraph. |
| Existing table styles | Resolved with basedOn inheritance and kept on save. |
| Default table style | Not applied to new tables. New tables use explicit single-line borders. |
| Embedded fonts | Loaded, 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, orw:hidden. To restrict it, see Document styles. - New tables do not use the document's default table style.
- CSS
@font-facerules and system fonts affect rendering only. They do not provide measurement bytes, so text uses estimated metrics.