How to manage sections and the table of contents of articles in MediaWiki

On each article page in MediaWiki there can be added subheadings. With them the article can be divided into sections. The headings that can be inserted can go six levels down. The main title of the page is heading level 1. A main section of the article is added by adding a heading level 2. A subsection of a section can be added with a heading level 3, and so on.

This is done on the form for editing the page by using the appropriate wiki markup; for your convenience at the top of the bult-in text editor there's a button for adding headings level 2. The markup for them looks like this == Title ==; that's two equals symbols on each side and the title between them (just replace Title with whatever you want the text for the heading to be). For each level down just add one more symbol for equals on each side; for instance, for heading level 3 add === Title ===.

When a page has sections it can have a table of contents that makes it easier to see what the structure of the article is and to navigate more quickly to a particular section. The table of contents lists the sections and subsections of the page. Each title of a section in the table of contents is also a link that scrolls down the page to the corresponding section. By default, the sections in the table are numbered and subsections are listed with an indentation to indicate they are subordinate to the particular section.

The table of contents is automatically placed right before the first section of the page. If there's text (e.g. a summary) before the section, the table will be put between that text and the section.

Add a Table of Contents

MediaWiki is configured in such a way so that a table of contents is automatically added after four or more section headings are added to the page. It doesn't matter what levels the headings are. Regardless of whether there are four main sections (i.e. with headings level 2) or one section with three subsections, a table of contents will be added.

In case the page contains fewer sections but you want to add a table of contents, edit the page and anywhere in its content add the following:


That's two underscore symbols on each side with FORCETOC between them. This will add the table in its usual place before the first section.

If you prefer to place it somewhere else, type __TOC__ at the exact place in the content where you want the table to appear.

Change the Position of the Table of Contents

By default the table of contents is placed right before the first section heading. To place it elsewhere on the page (e.g. before the article summary), edit it and type __TOC__ in the content of the page in the position you want the table of contents to appear.

Remove the Table of Contents

As we mentioned, a table of contents is automatically added when the page has four or more sections/subsections. If you want to, you can hide the table of contents. You can do that for all pages or per page. In MediaWiki version 1.22 and older ones there's also an option in the account preferences with which registered users can choose whether to see or not the table of contents on all pages. Depending on how the user configures that option, when the user is logged in the table of contents will be visible or hidden; it can be configured by going to Preferences button>Appearance tab>Advanced options section. In MediaWiki 1.23 and newer releases this user option is removed.

  • If you want to hide the table of contents on all pages, you can do that by adding some code to the MediaWiki:Common.css page. That's a Cascading Style Sheet for modifying the look of all skins. The code that you add in it is added to the CSS of skins. By default, it can be modified only by users belonging to the sysop/administrator user group. You have to add the following code on a new line:

.toc, #toc { display: none; }

This can be done from the frontend of the site. Open the URL of the page by adding MediaWiki:Common.css to the main URL of your site. If, for example, the homepage of the site is, then open Edit the page that opens as any regular page; just click on the Edit button and use the built-in text editor to add the code shown above. Then save the change. You may need to flush the browser cache to see the result.

  • If you want to hide the table of contents only on a particular page(s), edit that page and in its content add:


That's two underscores on each side and the text NOTOC between them.

Was this answer helpful?

 Print this Article

Also Read