Customization
Document styles
Apply DOCX paragraph styles from your template with the packaged style picker or your own React and Vue picker.
Paragraph styles come from the loaded DOCX template. Use Toolbar.StylePicker or the useParagraphStyle() hook to apply them.
Apply a document style
Mount this picker inside DocxEditor.Root. It applies the option's styleId, not its display name.
import { useParagraphStyle } from '@docx-editor.dev/react';
export function ContractStylePicker() {
const { value, options, isEnabled, setValue } = useParagraphStyle();
return (
<select
aria-label="Paragraph style"
disabled={!isEnabled}
value={value ?? ''}
onChange={(event) => setValue(event.currentTarget.value)}
>
<option value="" disabled>
Mixed or default
</option>
{options.map((option) => (
<option key={option.styleId} value={option.styleId}>
{option.name}
</option>
))}
</select>
);
}<script setup lang="ts">
import { useParagraphStyle } from '@docx-editor.dev/vue';
const { value, options, isEnabled, setValue } = useParagraphStyle();
function onChange(event: Event) {
setValue((event.target as HTMLSelectElement).value);
}
</script>
<template>
<select
aria-label="Paragraph style"
:disabled="!isEnabled"
:value="value ?? ''"
@change="onChange"
>
<option value="" disabled>Mixed or default</option>
<option v-for="option in options" :key="option.styleId" :value="option.styleId">
{{ option.name }}
</option>
</select>
</template>To use the packaged picker, render <DocxEditor.Toolbar.StylePicker />. Its Trigger, Content, and Item parts support a custom arrangement.
Configure picker options
useParagraphStyle() member | Use |
|---|---|
value | Current styleId. null can mean a mixed selection. |
options | Paragraph styles from the document, standard styles first. |
isEnabled | Whether the selection accepts a style change. |
setValue(styleId) | Applies a style. |
| Option field | Use |
|---|---|
styleId | Stable identifier to apply. |
name | Display label. |
preview | fontFamily, fontSizePt, bold, italic, and color. |
Prepare the template
- Give each style a stable
styleIdand a readable name. - Use
w:basedOnto inherit a shared design. - Define tables, lists, sections, headers, and theme fonts in the template.
For template preparation, see Custom styles and branding.
Limits
- The built-in picker does not filter by
w:qFormat,w:hidden, orw:semiHidden. Filteroptionsin a custom picker. - Do not show a
nullvalue as a selected style. - Direct formatting can override a style's properties. Clear Formatting removes it where the engine allows.
- Existing tables keep their style references and
w:tblLook. New tables use explicit borders and do not inherit the default table style. - Interface CSS does not change saved document styles or supply font metrics. Load font bytes through Fonts.
- For rendering support, see DOCX feature support.