Files
docx/docs/usage/numbering.md
T
DolanandClaude Opus 5.5 e0ff13ee3d chore: organise the demos into a folder for each topic (#3552)
* chore: organise the demos into a folder for each topic

The demos were one flat list of 124 numbered files, which made it hard to
find the one you wanted. Each is now in a folder for its topic, such as
demo/tables/basic-table.ts, with a name that says what it shows instead of
a number.

npm run demo lists every demo and narrows the list as you type. It also
takes a demo's path or name, a topic, or search words.

The demos' images moved to demo/assets/images, as images is now a topic.
The docs' links, the Demos workflow, the shape render script and its
reference images use the new paths and names.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TmyffPd5QMJYjXiMBQ3EnZ

* fix: list only a topic's own demos, and drop stale output file names

npm run demo text also offered the text-boxes demos and others with
"text" in their name, so a topic now searches for "text/". Three demos
logged their old numbered file name after writing My Document.docx.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 01:40:45 +01:00

19 KiB

Bullets and Numbering

!> Bullets and Numbering requires an understanding of Sections and Paragraphs.

docx is quite flexible in its bullets and numbering system, allowing the user great freedom in how bullets and numbers are to be styled and displayed. E.g., numbers can be shown using Arabic numerals, roman numerals, or even ordinal words ("one", "two", "three", ...). The format also supports re-using bullets/numbering styles throughout the document, so that different lists using the same style need not redefine them.

Configuration

Numbering is configured by adding config into Document:

new Document({
    numbering: {
        config: [...]
    }
})

Each config entry includes the following properties:

. Each level includes the following properties:

Property Type Notes Possible Values
reference string Required A unique string
levels ILevelOptions[] Required a series of levels which form a sequence starting at 0 indicating the top-level list look and increasing from there to describe the sublists, then sub-sublists, etc

Level Options

Levels define the numbering definition itself, what it looks like, the indention, the alignment and the style. The reason why it is an array is because it allows the ability to create sub-lists. A sub list will have a different configuration because you may want the sub-list to have a different indentation or different bullet.

Property Type Notes Possible Values
level number Required The list level this definition is for. 0 is for the root level, 1 is for a sub list, 2 is for a sub-sub-list etc.
format LevelFormat Optional DECIMAL, UPPER_ROMAN, LOWER_ROMAN, UPPER_LETTER, LOWER_LETTER, ORDINAL, CARDINAL_TEXT, ORDINAL_TEXT, HEX, CHICAGO, IDEOGRAPH__DIGITAL, JAPANESE_COUNTING, AIUEO, IROHA, DECIMAL_FULL_WIDTH, DECIMAL_HALF_WIDTH, JAPANESE_LEGAL, JAPANESE_DIGITAL_TEN_THOUSAND, DECIMAL_ENCLOSED_CIRCLE, DECIMAL_FULL_WIDTH2, AIUEO_FULL_WIDTH, IROHA_FULL_WIDTH, DECIMAL_ZERO, BULLET, GANADA, CHOSUNG, DECIMAL_ENCLOSED_FULLSTOP, DECIMAL_ENCLOSED_PARENTHESES, DECIMAL_ENCLOSED_CIRCLE_CHINESE, IDEOGRAPH_ENCLOSED_CIRCLE, IDEOGRAPH_TRADITIONAL, IDEOGRAPH_ZODIAC, IDEOGRAPH_ZODIAC_TRADITIONAL, TAIWANESE_COUNTING, IDEOGRAPH_LEGAL_TRADITIONAL, TAIWANESE_COUNTING_THOUSAND, TAIWANESE_DIGITAL, CHINESE_COUNTING, CHINESE_LEGAL_SIMPLIFIED, CHINESE_COUNTING_THOUSAND, KOREAN_DIGITAL, KOREAN_COUNTING, KOREAN_LEGAL, KOREAN_DIGITAL2, VIETNAMESE_COUNTING, RUSSIAN_LOWER, RUSSIAN_UPPER, NONE, NUMBER_IN_DASH, HEBREW1, HEBREW2, ARABIC_ALPHA, ARABIC_ABJAD, HINDI_VOWELS, HINDI_CONSONANTS, HINDI_NUMBERS, HINDI_COUNTING, THAI_LETTERS, THAI_NUMBERS, THAI_COUNTING, BAHT_TEXT, DOLLAR_TEXT, CUSTOM
text string Optional A unique string to describe the shape of the bullet
alignment string Required START, CENTER, END, BOTH, MEDIUM_KASHIDA, DISTRIBUTE, NUM_TAB, HIGH_KASHIDA, LOW_KASHIDA, THAI_DISTRIBUTE, LEFT, RIGHT, JUSTIFIED
style object Optional An object containing run, paragraph, and style sub-properties (see below)

Style sub-properties

Property Type Notes Description
run object Optional Run style properties for the numbering text (font, size, bold, etc.)
paragraph object Optional Paragraph style properties for the level (indent, spacing, etc.)
style string Optional A paragraph style ID to associate with the level. Paragraphs using that style will automatically adopt this numbering level. See Associating a level with a paragraph style

Using ordered lists in docx

Add a numbering section to the Document to numbering style, define your levels. Use LevelFormat.UPPER_ROMAN for the format in levels:

const doc = new Document({
    ...
    numbering: {
        config: [
            {
                reference: "my-numbering",
                levels: [
                    {
                        level: 0,
                        format: LevelFormat.UPPER_ROMAN,
                        text: "%1",
                        alignment: AlignmentType.START,
                        style: {
                            paragraph: {
                                indent: { left: 2880, hanging: 2420 },
                            },
                        },
                    },
                    ...
                ],
            },
        ],
    },
    ...
});

And then on a Paragraph, we can add use the numbering created:

new Paragraph({
    text: "Hey you!",
    numbering: {
        reference: "my-numbering",
        level: 0,
    },
}),

Numbering options

Along with reference and level, the numbering object supports an optional instance property:

Property Type Notes
reference string The numbering style reference, must match a defined config
level number The list level (0 = top-level, 1 = sub-list, etc.)
instance number (Optional) Identifies the instance of the list. Lists with the same instance (or none) continue numbering across paragraphs. A new instance value restarts numbering from 1.

Example:

new Paragraph({
    text: "First list item",
    numbering: { reference: "my-numbering", level: 0, instance: 1 },
});

new Paragraph({
    text: "Second list item",
    numbering: { reference: "my-numbering", level: 0, instance: 1 },
});

new Paragraph({
    text: "New list, starts again at 1",
    numbering: { reference: "my-numbering", level: 0, instance: 2 },
});

Un-ordered lists / Bullet points

Add a numbering section to the Document to numbering style, define your levels. Use LevelFormat.BULLET for the format in levels:

const doc = new Document({
    ...
    numbering: {
        config: [
            {
                reference: "my-bullet-points",
                levels: [
                    {
                        level: 0,
                        format: LevelFormat.BULLET,
                        text: "\u1F60",
                        alignment: AlignmentType.LEFT,
                        style: {
                            paragraph: {
                                indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
                            },
                        },
                    },
                ],
            },
        ],
    },
    ...
});

And then on a Paragraph, we can add use the numbering created:

new Paragraph({
    text: "Hey you!",
    numbering: {
        reference: "my-bullet-points",
        level: 0,
    },
}),

Disabling numbering inherited from paragraph style

If the numbering is set on a paragraph style, you may wish to disable it for a specific paragraph:

const doc = new Document({
    ...
    numbering: {
        config: [
            {
                reference: "my-bullet-points",
                levels: [
                    {
                        level: 0,
                        format: LevelFormat.BULLET,
                        text: "\u1F60",
                        alignment: AlignmentType.LEFT,
                        style: {
                            paragraph: {
                                indent: { left: convertInchesToTwip(0.5), hanging: convertInchesToTwip(0.25) },
                            },
                        },
                    },
                ],
            },
        ],
    },
    styles: {
        paragraphStyles: [
            {
                id: 'bullet',
                name: 'Bullet',
                basedOn: 'Normal',
                next: 'Normal',
                run: {},
                paragraph: {
                    numbering: {
                        reference: 'my-bullet-points',
                        level: 0,
                    },
                },
            },
        ],
    },
    ...
});
new Paragraph({
    text: "No bullet points!",
    style: "Bullet",
    numbering: false,
}),

Associating a level with a paragraph style

You can link a numbering level to a paragraph style using style.style. Any paragraph that uses the associated style will automatically adopt the numbering level without needing to specify numbering on each paragraph individually.

This is useful for creating reusable list styles — define the numbering once and apply it via the paragraph style:

const doc = new Document({
    styles: {
        paragraphStyles: [
            {
                id: "numberedListParagraph",
                name: "Numbered List Paragraph",
                paragraph: {
                    numbering: {
                        reference: "styled-numbering",
                        level: 0,
                    },
                    spacing: { after: 120 },
                },
            },
        ],
    },
    numbering: {
        config: [
            {
                reference: "styled-numbering",
                levels: [
                    {
                        level: 0,
                        format: LevelFormat.DECIMAL,
                        text: "%1.",
                        alignment: AlignmentType.START,
                        style: {
                            style: "numberedListParagraph",
                            paragraph: {
                                indent: { left: 720, hanging: 260 },
                            },
                        },
                    },
                ],
            },
        ],
    },
    sections: [
        {
            children: [
                new Paragraph({
                    text: "First styled list item",
                    style: "numberedListParagraph",
                }),
                new Paragraph({
                    text: "Second styled list item",
                    style: "numberedListParagraph",
                }),
            ],
        },
    ],
});

The style.style value must match the id of a paragraph style defined in styles.paragraphStyles. This creates a <w:pStyle> element inside the numbering level definition, linking the two.

Examples

Numbering and Bullet Points

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-and-bullet-points.ts

Numbering with Paragraph Styles

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/lists/numbering-level-paragraph-style.ts