Skip to main content
How text works in React DOCX and when to use each component.

The basics

Three ways to add text:

When to use what

Plain strings

For unstyled text. No wrapper needed:

Text component

When you need styling:

Formatting shortcuts

For common formatting without class names:

Mixing styles

Combine multiple styles in one paragraph:
Nest formatting shortcuts:
Add classes to shortcuts:

Text containers

These components can contain text:
ComponentPurpose
ParagraphBody text
H1-H6Headings
LiList items
Td / ThTable cells
LinkHyperlinks
All work the same way:

Common patterns

Label + value

Status indicators

Highlighted text

Small print

Inline code

Superscript / subscript


Style inheritance

Styles flow from parent to child:
Child styles override parent styles:

Special characters

Line breaks

Tabs


Formatting reference

StyleClassShortcut
Boldfont-bold<Bold>
Italicitalic<Italic>
Underlineunderline<Underline>
Strikethroughline-through<Strike>
All capsuppercase
Small capscapitalize
Superscriptalign-super text-xs
Subscriptalign-sub text-xs

Anti-patterns

Unnecessary Text wrappers

Nested paragraphs