Files
docx/docs/usage/checkboxes.md
DolanandClaude Opus 5.5 78b04e52c6 docs: give the checkbox options' real type, defaults and what alias does (#3855)
The options table named a SymbolState type that doesn't exist and marked
value as required, though both value and font are optional, defaulting
to Word's own ☒/☐ in MS Gothic. alias writes the content control's
w:alias, which Word for Mac shows as a title tab above the checkbox, so
it's described as that rather than as an accessibility label.


Claude-Session: https://claude.ai/code/session_01X5zGDL3sgGVBMXPfny376c

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 02:40:45 +00:00

6.5 KiB

Checkboxes

!> Checkboxes require an understanding of Paragraphs.

Checkboxes allow you to add interactive checkbox controls to your Word documents. These are commonly used in forms, checklists, and surveys.

?> These checkboxes are interactive in Word - users can click to toggle them on and off.

Basic Checkbox

Create a simple checkbox:

import { CheckBox, Document, Paragraph, TextRun } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [new CheckBox(), new TextRun(" Unchecked item")],
                }),
            ],
        },
    ],
});

Checked Checkbox

Create a pre-checked checkbox:

import { CheckBox, Document, Paragraph, TextRun } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [new CheckBox({ checked: true }), new TextRun(" Completed task")],
                }),
            ],
        },
    ],
});

Custom Checkbox Symbols

A checked box shows ☒ (2612) and an unchecked one ☐ (2610), both in MS Gothic, as Word's own checkboxes do. checkedState and uncheckedState set another symbol for each, as its Unicode code point in hex, and the font to draw it in:

import { CheckBox, Document, Paragraph } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [
                        new CheckBox({
                            checked: true,
                            checkedState: {
                                value: "2611", // Unicode ballot box with check
                                font: "MS Gothic",
                            },
                            uncheckedState: {
                                value: "2610", // Unicode ballot box
                                font: "MS Gothic",
                            },
                        }),
                    ],
                }),
            ],
        },
    ],
});

Common Unicode Values

Symbol Unicode Description
☐ 2610 Ballot Box
☑ 2611 Ballot Box with Check
☒ 2612 Ballot Box with X
✓ 2713 Check Mark
✗ 2717 Ballot X

Checkbox Options

Property Type Notes Description
checked boolean Optional Whether the box starts checked. Defaults to false
checkedState ICheckboxSymbolProperties Optional The symbol, and its font, when checked
uncheckedState ICheckboxSymbolProperties Optional The symbol, and its font, when not checked
alias string Optional The checkbox's title, which Word shows above it when the cursor is in it

checkedState and uncheckedState

Property Type Notes Description
value string Optional The symbol's Unicode code point in hex, such as 2611. Defaults to 2612 (☒) when checked and 2610 (☐) when not
font string Optional The font to draw the symbol in. Defaults to MS Gothic

Title

alias gives the checkbox a title. Word shows it on a tab above the checkbox when the cursor is in it:

import { CheckBox, Document, Paragraph, TextRun } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    children: [
                        new TextRun("Do you agree to the terms?"),
                        new TextRun({ break: 1 }),
                        new CheckBox({
                            checked: false,
                            alias: "Terms agreement checkbox",
                        }),
                        new TextRun(" Yes, I agree"),
                    ],
                }),
            ],
        },
    ],
});

Building a Checklist

Create a complete checklist:

import { CheckBox, Document, Paragraph, TextRun } from "docx";

const tasks = [
    { text: "Review documentation", done: true },
    { text: "Write unit tests", done: true },
    { text: "Deploy to production", done: false },
    { text: "Update README", done: false },
];

const doc = new Document({
    sections: [
        {
            children: tasks.map(
                (task) =>
                    new Paragraph({
                        children: [new CheckBox({ checked: task.done }), new TextRun(` ${task.text}`)],
                    }),
            ),
        },
    ],
});

Form with Multiple Checkboxes

import { CheckBox, Document, HeadingLevel, Paragraph, TextRun } from "docx";

const doc = new Document({
    sections: [
        {
            children: [
                new Paragraph({
                    text: "Survey Form",
                    heading: HeadingLevel.HEADING_1,
                }),
                new Paragraph({
                    text: "Which features do you use?",
                    heading: HeadingLevel.HEADING_2,
                }),
                new Paragraph({
                    children: [new CheckBox(), new TextRun(" Tables")],
                }),
                new Paragraph({
                    children: [new CheckBox(), new TextRun(" Images")],
                }),
                new Paragraph({
                    children: [new CheckBox(), new TextRun(" Headers/Footers")],
                }),
                new Paragraph({
                    children: [new CheckBox(), new TextRun(" Styles")],
                }),
            ],
        },
    ],
});

Demo

Example

Source: https://github.com/dolanmiu/docx/blob/master/demo/text/check-boxes.ts