![]() | Note: When you edit this page, you agree to release your contribution under theCC0. SeePublic Domain Help Pages for more info. | ![]() |
The section header syntax allows a page to be divided intosections.
To create asection, define its headings as follows:
==Section=====Subsection=======Sub-subsection====
=text here=
) cause a title the size of the page name.==Section Header==<br>
will not as render a header, but a paragraph./(^={1,6}.*?={1,6}\s*?$)/m
(m
refers to a multi-line mode).Atable of contents (TOC) is automatically generated for pages containing more than three section headings.However, editors may choose to exclude the TOC by adding themagic word__NOTOC__
(enclosed indouble underscores) in the edit box of the article.
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. |
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__ |}
You can control the depth of the Table of Contents (TOC) by adjusting the$wgMaxTocLevel setting in theLocalSettings.php
file.For instance, setting it to 3 limits the TOC to show only up to three levels deep.
Section headers will automatically generate HTML with theid
attribute, which can be directlylinked 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><spanclass="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).
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<span>
tag and theid
attribute:
<spanid="anchor_name"></span>
Please ensure that the chosen name is unique by incorporating abbreviated titles from higher-level sections, such asOntario-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 theid
contains spaces.For example:
<span>(optional text)</span>[will not work]<span>(optional text)</span>[will work]...See[[#Ontario-Natural features|natural features of Ontario]] and[[#Newfoundland-Natural features|natural features of Newfoundland]]
Replace spaces in theid with underscores to ensurelinks work seamlessly with both underscores and spaces.
[[#section|]]
-> [[#section|]][[page#section|]]
-> [[page#section|]][[namespace:page#section|]]
-> [[namespace:page#section|]]Seemanual anchors for linking to any section on a page.
Linking to a specific section of a page through aHelp: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 distinctbacklink feature for sections; pages linking to a section are listed among pages linking to the entire page. To address these issues:
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 outw:Wikipedia:Categorizing redirects.
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§ion=9
Instead of using sectiontitles, section editing uses sectionnumbers.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.
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§ion=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§ion=new&preloadtitle=pqr
The preload can be edited before it is saved.
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§ion=0
Alternatively, you can modify any section edit link on the page by changing the section number.
To generate the same URL using JavaScript, seew:Wikipedia:WikiProject User scripts/Scripts/Edit Top.
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.
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 headingformat 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
If a page has large sections or lacks division into sections, users can still modify the content by:
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 fromHelp: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:
Additionally, consider the following practices for managing templates effectively:
{{{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.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
When conditionally transcluding a template with sections using aparser 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.
To edit a footnote in a section using<references/>
, find the section with the footnote mark and edit it.CheckHelp:Footnotes for more help.
You can use the section editing feature toview a specific section without loading the entire page.
Here are some advantages of each of them:
Advantages of one large page with sections:
Advantages of separate pages:
Advantages ofcompound documents byTransclusion:
Disadvantages:
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):
{||-! | <h4>Stuff</h4>|-| Contents about stuff here|}{||-! | <h4>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>Your heading here</h4>
This section is linked to from#Linking to a section.