PD Note: When you edit this page, you agree to release your contribution under the CC0. See Public Domain Help Pages for more info. PD

The section header syntax allows a page to be divided into sections.

Section creation and numbering

edit

To create a section, define its headings as follows:

==Section==

===Subsection===

====Sub-subsection====

Guidelines for using section headers

edit
  • Headers with only one equals sign on a side (=text here=) cause a title the size of the page name.
  • The section header cannot be combined with other content on the same line. For instance, ==Section Header==<br> will not as render a header, but a paragraph.
  • Section names should be unique within a page, including subsection names. Disadvantages of duplicate section names include:
    • Editing Confusion - Multiple sections with the same title can cause editing confusion, leading to errors and making it difficult for contributors to accurately edit content
    • Ambiguous edit summaries - MediaWiki generates edit summaries for page edits, but if multiple sections have the same title, they can become ambiguous. For example, the edit summary of two 'Diet' sections could be 'I edited the Diet section', confusing contributors and making it difficult to review recent changes effectively.
  • You can create separate sections on different pages with their own edit histories using a template/page. Each template/page can be inserted into a main page, adding content without changing the overall look. This setup makes it easier to track changes and manage specific parts of a page. (See Help:Template#Possible uses of templates.)
  • A template with sections in a new page maintains its original order, joining content before and after the template. This ensures proper numbering of sections within the template, without affecting the numbering of sections on the main page.
    This feature is not supported in skins that display a table of contents outside the article content, such as the Vector 2022 skin.
  • A section header in wikitext on MediaWiki is specified by the regular expression, /(^={1,6}.*?={1,6}\s*?$)/m (m refers to a multi-line mode).

Table of contents (TOC)

edit
This feature is not supported in skins that display a table of contents outside the article content, such as the Vector 2022 skin. In the Vector 2022 skin, a TOC is generated even with only one section heading.

A table of contents (TOC) is automatically generated for pages containing more than three section headings. However, editors may choose to exclude the TOC by adding the magic word __NOTOC__ (enclosed in double underscores) in the edit box of the article.

Guidelines for using table of contents

edit
  • A TOC is added to the wikitext, overriding __NOTOC__ when either __FORCETOC__ or __TOC__ (with two underscores on either side of the term) is added even if the page has fewer than four headings.
  • Using __FORCETOC__ forces the Table of Contents (TOC) to appear before the first section heading, while __TOC__ places it where you want the TOC to begin, allowing for flexible positioning such as on the right or within a table cell.
  • __TOC__ helps control where the table of contents (TOC) appears in an article. You put __TOC__ where you want the TOC to show up, like after an introduction or at the end of the page. This makes sure the TOC is in the right spot without needing extra headings.
  • Using __NOTOC__ stops the automatic table of contents from showing up on a page. If you want to make your simple table of contents, you can manually create links to different sections on the page using headings like == A == and then linking to them using section links like this [[#A|A]]".

Summary:

Word Explanation
__NOTOC__ The current page's ToC (table of contents) is hidden.
__FORCETOC__ Makes the ToC show up.
__TOC__ Adds a ToC somewhere on the page, hence, overriding any __NOTOC__. If there are multiple __TOC__ magic words, only the first one takes effect.

Moving the table of contents

edit

The code below allows the Table of Contents to be positioned as a floating table on the right side of the screen.

  {| align="right"
  | __TOC__
  |}

Limiting the TOC depth globally

edit

You can control the depth of the Table of Contents (TOC) by adjusting the $wgMaxTocLevel setting in the LocalSettings.php file. For instance, setting it to 3 limits the TOC to show only up to three levels deep.

Linking to a section

edit

Section headers will automatically generate HTML with the id attribute, which can be directly linked to, either within the same page or from other pages.

For instance, the HTML code that was created at the start of this section on the English version of this page is:

<h2><span class="mw-headline" id="Linking_to_a_section">Linking to a section</span></h2>

A link to this (section) appears as:

[[Help:Section#Linking to a section|Section linking]]

You can link to a section within a page using [[#section link|displayed text]], and also link to a section within a different page using [[page name#section name|displayed text]].

A link to a subsection, sub-subsection, etc. will be [[#subsection name]] and [[#sub-subsection name]] etc. since the anchors do not take into account the depth of the section.

Duplicate section names are denoted by appending an underscore and a number. For instance, if there are three sections named "Example", they will be labeled "Example", "Example_2", and "Example_3". However, when editing sections "Example_2" or "Example_3", the edit summary confusingly directs to "Example". A blank heading in a section distorts the Table of Contents (TOC).

Linking sections using an arbitrary id

edit

Section link anchors can change without notice, especially when an article contains multiple sections with the same name. Additional identifiers like " 2", " 3", etc., are added to distinguish these sections. If a section is added, deleted, or renamed, it may alter the link's destination, potentially leading to incorrect or non-existent sections. This can be avoided using the HTML tag and the id attribute:

<span id="anchor_name"></span>

Please ensure that the chosen name is unique by incorporating abbreviated titles from higher-level sections, such as Ontario-Natural_features for the "Natural Features" subsection within the "Ontario" section of a Canadian provinces article. This method may not function on older browsers, particularly those before MediaWiki 1.4.10, and it might not work even with modern browsers if the id contains spaces. For example:

<span id="Ontario-Natural features">(optional text)</span> [will not work]
<span id="Newfoundland-Natural_features">(optional text)</span> [will work]
...
See [[#Ontario-Natural features|natural features of Ontario]] and [[#Newfoundland-Natural features|natural features of Newfoundland]]

Replace spaces in the id with underscores to ensure links work seamlessly with both underscores and spaces.

* Internal links in section headings do not complicate section linking:

See manual anchors for linking to any section on a page.

Linking sections and redirects

edit

Linking to a specific section of a page through a Help:redirect usually functions similarly to linking directly to that section.

Renaming a page generates a redirect, but renaming a section does not. Additionally, there is no distinct backlink feature for sections ; pages linking to a section are listed among pages linking to the entire page. To address these issues:

  • Instead of directly linking to a section, use a page that redirects to the section. This approach facilitates tracking changes to section names and provides a "what links here" functionality for sections. To identify links to the section, check for redirects linking to the page and select the relevant one.
  • Insert an anchor within the section and link to it accordingly.
  • Add a comment at the beginning of a section in the wikitext, listing pages that link to that section.
  • Create a separate page or template for the section and either transclude it into the parent page or link to it. Then, instead of linking directly to the section, link to the separate page or template.

Redirect pages can be put into categories by adding a category tag after the redirect command. If the redirect leads to a section, it somewhat categorizes that section too. However, the section will not link back to the category unless specifically done. On category pages, redirects are shown in italics. For more details, check out w:Wikipedia:Categorizing redirects.

Editing sections

edit

To edit specific sections of a page, you can click on the "[edit]" link next to the section heading. Clicking on these links takes you to an edit page with a URL structured like this:

https://www.mediawiki.org/w/index.php?title=Help:Advanced_editing&action=edit&section=9

Instead of using section titles, section editing uses section numbers. Subsections are represented with a single number (e.g., In the link above, section 2 in the table of content is numbered as 9 in the link. This allows for focused editing without the need to have the entire text of the page visible. It is particularly useful for large pages, as it simplifies the editing process and reduces clutter. Adding __NOEDITSECTION__ section editing via a URL you already have still works.

When inserting a section, edit the previous or following section, merge by deleting the heading if necessary, and adjust the edit summary accordingly.

Including a section at the end

edit

To add a new section at the end of a page, you can use a URL like the following:

https://www.mediawiki.org/w/index.php?title=Project:Sandbox&action=edit&section=new

On talk pages and pages with wikitext, you can use the code __NEWSECTIONLINK__ to generate a special link beside the edit tab titled "⧼skin-action-newsection⧽". Clicking this link will open a text box where you can enter a headline for the new section. The edit summary is automatically generated. The edit summary produced will be /* Section Name */ /* Section Name */ new section, which is automatically rendered as a right arrow. This leaves no option for providing a custom edit summary.

If the subject box is left blank, no empty == ==  delimiter is inserted, and the content is appended to the page's last section. This approach does not support creating a new section without a title and does not allow for providing an edit summary. The "Preloadtitle" parameter determines the first text displayed in the "Subject/headline" field:

https://www.mediawiki.org/w/index.php?title=Project:Sandbox&action=edit&section=new&preloadtitle=pqr

The preload can be edited before it is saved.

Editing before a first section

edit

Generally, there is no designated link for editing the introductory text before the first section heading (phab:T2156). However, you can apply the section editing feature to this part by using 0 as the section number in the link, like this:

https://www.mediawiki.org/w/index.php?title=Help:Advanced_editing&action=edit&section=0

Alternatively, you can modify any section edit link on the page by changing the section number.

To generate the same URL using JavaScript, see w:Wikipedia:WikiProject User scripts/Scripts/Edit Top.

See Help:Section editing demo .

Preview

edit

Section editing preview may differ from the full page if an image from a previous section overlaps with the current section.

The edit page displays all templates used on the entire page, including those from other sections.

Working with subsections

edit

When editing a section, subsections are included and numbered relative to the edited part, starting at 1. Subsections are denoted with numbers like 1.1, 1.2, etc. The heading format follows the absolute level, with sub-subsections numbered accordingly. For example, a sub-subsection 3.2 would be numbered 3.2.1, 3.2.2

Editing a page with large sections

edit

If a page has large sections or lacks division into sections, users can still modify the content by:

  • Starting with a blank line before the new section heading, and adding a section with a specified large section number.
  • Adding content to the last section without a heading, but unable to revert or edit the new text due to browser or connection limitations.

Editing sections of included templates

edit

You can edit sections within included pages or templates. Clicking the edit link for a section takes you to the edit page of the separate page. This section (transcluded from Help:Section/Editing sections of included templates ) shows how it works.

The size of the section within the included page or template is determined by the headings in the main page where it is included. Also, texts before the first heading of the separate page is part of the section, but clicking its edit link won't show its text. Similarly, if there are texts after the template tag without a heading, you need to click the headings before the template to edit it. This section shows how it works. To ensure clarity and consistency in rendered parent pages, follow these guidelines:

  • Template structure - Avoid placing any text before the first heading within a template.
  • Handling sections - After using a template with sections, start a new section on the parent page. This prevents conflicts between template sections and parent page sections.

Additionally, consider the following practices for managing templates effectively:

  • Template heading - Sometimes it's helpful to start a template with a heading, even if it's just one section. This makes editing easier.
  • Parameter use - When editing templates, remember parameters, such as {{{1}}}, are changed in the calling page, not directly in the template. Although this may not be immediately apparent in the rendered page, providing explanatory text or an additional edit link can enhance user understanding.
  • NOEDITSECTION tag - The __NOEDITSECTION__ tag affects the template and any pages it's added to, along with other templates on the same page. Instead, consider replacing MediaWiki section header markup with HTML header markup within the template, causing the headers to remain visually consistent while avoiding recognition as editable sections. This approach eliminates the need for __NOEDITSECTION__ within the template.

For example, think of a template structured as follows:

==Template heading 1==
Content
===Template heading 2===
Content

To prevent "edit section" links from appearing when transcluding a template, add NOEDITSECTION within the template's code. However, this suppresses all "edit section" links on pages where the template is used. Alternatively, structuring the template with HTML heading tags (‎<h2>, ‎<h3>, etc.) achieves the same visual effect without affecting other sections' edit links on transcluding pages.

<h2>Template heading 1</h2>
Content
<h3>Template heading 2</h3>
Content

Sections within a parser function

edit

When conditionally transcluding a template with sections using a parser function , the edit links for these sections may direct to the wrong section or show an error message claiming the section does not exist. This occurs because the content of conditionally included templates is considered part of the page itself, causing the sections to be counted after expansion.

As a result, the edit links for sections within the included template link to the page instead of the template, and the subsequent edit links refer to the correct page but with incorrect section numbers. This issue does not arise when transcluding a template with a conditional name, which offers additional advantages.

Editing footnotes

edit

To edit a footnote in a section using ‎<references />, find the section with the footnote mark and edit it. Check Help:Footnotes for more help.

Viewing a section

edit

You can use the section editing feature to view a specific section without loading the entire page.

Sections vs. separate pages vs. transclusion

edit

Here are some advantages of each of them:

Advantages of one large page with sections:

  • Faster access and simpler searching compared to accessing multiple smaller pages.
  • Maintains conceptual cohesion for complex topics.

Advantages of separate pages:

  • Easy navigation and editing with separate links and histories using the what links here feature.
  • Faster loading times due to smaller page sizes.
  • Automatic redirection upon renaming.
  • Improved organization and data management through independent categorization and annotation.
  • A few templates limit the apply per page.

Advantages of compound documents by Transclusion :

  • Transclusion involves including the content of one page within another, often accomplished through templates.
  • Users can navigate and search within the combined rendered page, which enhances usability.

Disadvantages:

  • Users cannot search within the combined wikitext directly.
  • Providing titles for each included page can be cumbersome.
  • There is a limitation related to the size of post-expand includes, potentially causing technical issues, particularly with large or numerous included pages.

Sections and Table of Content (ToC)

edit

Adding Non-Section Text to TOC

edit

You can mark text as a TOC entry by using ‎<h4>...‎</h4> header tags. Customize formatting as usual inside these tags. An Example usage (the second one is better formatted for clarity):

{| class="collapsible collapsed" style="text-align:left; border:0px; margin-top:0.2em"
|-
! style="background-color:#f2dfce" | <h4>Stuff</h4>
|-
| Contents about stuff here
|}

{| class="collapsible collapsed" style="text-align:left; border:0px; margin-top:0.2em"
|-
! style="background-color:#f2dfce; padding-top:0; padding-bottom:0" |
 <h4 style="margin:0; padding:0;font-size:95%">More stuff</h4>
|-
| Contents about more stuff here
|}

To clarify, you want the collapse boxes headers treated as section titles, included in the table of contents (TOC), without necessitating formal "section titles" on the page itself.

Although not recommended, it is possible to create a TOC entry that is not in the text but acts as an anchor for linking to a section header with slightly different wording:

<h4 style="display:none">Your heading here</h4>

Sections for the above demo

edit

This section is linked to from #Linking to a section.

See also

edit

Notes

edit