Word Table of Contents Field Codes and Switches Explained

Learn what a Word table of contents field code is and how switches like \o, \h and \u control which headings appear and how the TOC behaves.

If your Word table of contents keeps dropping a heading, shows the wrong levels, or refuses to update the way you expect, the answer is usually in the field code behind it. A word table of contents field code is a set of instructions that tells Word which paragraphs to collect, how deep to go, and whether entries should link to their sections. Once you can read those instructions, the behavior stops looking random.

This article is for anyone who has inserted a table of contents in a Word document and wants to understand what Word is doing with it. You do not need to know any programming. You will learn what the TOC field is, what the main switches such as \o, \h, \u, \t and \z control, and which misunderstandings cause most of the confusion. The how-to steps for inserting and updating a table of contents, and the troubleshooting steps for specific errors, are covered in separate articles. Here the focus is on the mechanism.

What does a Word table of contents field code control? The short answer

A TOC field code controls which paragraphs appear in the table, how many levels are included, and how each entry is formatted, so each switch changes one part of that behavior. Read the switches as rules that Word applies every time the field updates.

Your situationWhat to doWhy
Headings use built-in Heading stylesKeep \o "1-3" or your level range\o collects paragraphs by heading level
Headings use custom stylesAdd \t with the style name and level\t maps custom style names to levels
Headings use outline levels set in paragraph settingsKeep or add \u\u collects paragraphs that have an outline level
Entries should jump to their sectionsKeep \h\h turns each entry into a hyperlink
Page numbers or tab leaders look wrong in Web LayoutKeep \z\z hides tab leaders and page numbers in that view

What is a TOC field code, and how is it different from the result?

In Word, a table of contents is a field. A field has two parts: the field code, which holds the instructions, and the field result, which is the text Word generates from those instructions. A typical code looks like this: TOC \o "1-3" \h \z \u. The result is the list of entries with page numbers that you see on the page.

Word can display either the code or the result. When you update the field, Word reads the code, scans the document, and rebuilds the result. Anything you typed into the result by hand is replaced at that point, which is why manual edits to the entries disappear after an update. To change what appears in the list, you change the code or the heading paragraphs, not the entries.

Field codes sit inside the document's structure, so they travel with the .docx file. If you receive a file from someone else, you can check the code the same way you would check your own.

How the main switches shape the list

Switches are the options after the TOC keyword. Each one starts with a backslash, and some take a value in quotation marks. Word reads them left to right, and a space must separate each switch from the next.

\o: which heading levels count

The \o switch tells Word to collect paragraphs formatted with built-in heading styles. The value in quotation marks sets the range. For example, \o "1-3" includes Heading 1 through Heading 3 and skips Heading 4 and deeper. If you narrow the range, fewer entries appear, and if you widen it, the list gets longer.

\u and \t: outline levels and custom styles

Some documents do not use built-in heading styles. The \u switch collects any paragraph that has an outline level set in its paragraph settings, regardless of its style name. The \t switch maps custom style names to levels. It takes pairs of style names and level numbers, separated by a comma and enclosed in quotation marks, such as \t "Chapter Title,1". Use \t when your headings use a style Word does not recognize as a heading.

\h, \z, and \n: links, view, and page numbers

The \h switch makes each entry a clickable hyperlink in digital copies, so a reader can jump to the section. Printed copies show the same text without the link behavior. The \z switch hides tab leaders and page numbers when the document is viewed in Web Layout, which keeps the list tidy in that view without changing the printed layout. The \n switch omits page numbers, either for all levels or for levels you specify, which suits short lists or on-screen documents.

Common misconceptions

  • Switches do not format your headings. The TOC only decides which paragraphs to collect. Heading appearance still comes from the paragraph's style.
  • Changing a heading does not update the list automatically. After you rename or restyle a heading, the table of contents stays the same until you update the field.
  • Typed corrections are temporary. If you fix an entry by typing over it in the result, the next update restores whatever the code produces.
  • \o and \u can both add entries. If a paragraph matches either switch, it can appear in the list, so a paragraph you did not expect may come from the outline-level setting.
  • A missing entry usually means a mismatch. A common cause is a heading that uses a custom style without a matching \t entry, or a level range that stops above the heading's level.

📊 At a glance

SwitchControlsTypical use
\o "1-3"Built-in heading levels in the rangeStandard reports and manuals with Heading styles
\uParagraphs with an outline levelDocuments where levels are set in paragraph settings
\t "Style,level"Custom style names mapped to levelsTemplates with their own heading style names
\hEntries as hyperlinksDigital copies that readers browse on screen
\zHides tab leaders and page numbers in Web LayoutTidier on-screen view
\nOmits page numbersShort lists or on-screen-only documents

Putting it to use

  1. Open the document in Word and turn on the display of field codes, so the table of contents shows its code instead of its entries. The general option is usually found in the view or field settings.
  2. Read the code from left to right. Note the TOC keyword, then the level range and each remaining switch.
  3. Compare the switches with the styles in your headings. If a heading uses a custom style, check that \t names it exactly, including capitalization.
  4. Make one change at a time, such as widening the level range, then update the field and compare the new result with the old one.
  5. Turn the field-code display off again to see the entries, and confirm the result matches what you expected.

If you edit the .docx in the UniDoc web editor at app.unidoc.top, which is Word-compatible, open the table of contents and check the result after editing. Field handling can differ between editors, so confirm the entries before you share the file.

🎯 Which approach fits you?

If your headings use built-in Heading styles and you want a standard list, \o with a level range plus \h is usually enough. If your template uses custom style names or outline levels, add \t or \u so those paragraphs are collected. If the list will be printed, decide whether you need \h at all, since links only matter on screen.

❓ FAQ

1. Can I see a table of contents field code without changing the document?

Yes. Showing field codes only changes how Word displays the field on your screen, and it does not alter the content. Switch the display back to results when you are done.

2. Do the switches need to be in a particular order?

Word reads switches from left to right, but the usual order does not change the result. What matters most is spacing and quotation marks: put a space before each switch and keep the style names and level ranges inside quotation marks.

3. Why does the \h switch seem to do nothing in a printed copy?

The hyperlink behavior only works in digital copies, where a reader can click an entry. A printed page shows the same entry text and page numbers, so the link has no effect there.

4. How do I check the switches in a file someone else sent me?

Show the field code as described above, then read the switches the same way. If you see a level range or a \t entry, compare it with the styles used in that file's headings.

5. Will a switch fix a table of contents that was damaged by manual edits?

Often it will, because updating the field rebuilds the entries from the code. Make sure the switches match your headings first, then update the field so the manual text is replaced.

📝 Summary

A Word table of contents is a field whose code decides which paragraphs appear and how they behave. Each switch, such as \o, \u, \t, \h and \z, controls one part of that behavior, so reading the code explains most surprises. Keep the switches matched to your heading styles, and the table of contents will update the way you expect.

Open OmniDoc to edit and export your documents

Updated 2026-11-04