Help:Collapsing

Collapsible tables provide a way to collapse and uncollapse a table when a show/hide button is clicked. The code for this feature is found in the MediaWiki:Common.js.

The initial state of any collapsible content can be controlled using a "collapsible table", because it also allows a table with only one element with content, and a header.

Simple example
Tables are simpler to work with, as you merely need to add the  class to the table itself. For the [hide]/[show] link to appear, the table's first row must be a header row, that is, one of the cells in the first row must be declared with an exclamation mark (in wikisyntax). The use of the class  in the example below is merely for appearance; it is not needed for   to function.

Using the syntax above, collapsible tables are often used to always display an introduction to, or summary of, a lengthy discussion or section of content, while hiding the majority of that content from immediate view. The summary message is put in the header cell, and the content is placed into the body cell. The content is then easily accessible by clicking the 'show' button. The collapsible functionality is also available in larger and more complicated tables, as long as there is a header cell in the first row of the table.

Collapsing tables by default
Just using the  class produces a table which is expanded by default, but can be collapsed by the reader. It is also possible to create tables which are collapsed by default, and can be optionally expanded. There are several methods for doing this, depending on the situations in which you want the table to collapse.

"collapsed"
Adding the  class will cause the table to  be initially collapsed, no matter what happens around it. It is the simplest method for doing so. Using the examples above:

"autocollapse"
Adding the  class causes the table to collapse when there are 2 or more collapsible tables on the page (this threshold might be different on other projects). The example below, therefore, collapses because there are numerous collapsible tables on the page.

"innercollapse" and "outercollapse"
Using this pair of classes, it is possible to make a table collapsed by default only when it is a particular object, such as another table. This is mainly useful for tables inside templates, which are often nested.

{| class=wikitable style="width:80%;" align=center !Code entered!!Output produced {| class="wikitable outercollapse" ! This table does not collapse
 * width=50%|&#32;
 * style="width:50%; text-align:center;"|
 * style="width:50%; text-align:center;"|
 * But the table inside this cell
 * But the table inside this cell


 * }


 * }

Sortable tables
Collapsible tables can be combined with the sortable tables functionality without difficulty. However, because the hide/show button is placed in the first header cell located, its positioning can look a bit peculiar if the table is not wide enough:

Possible alternative is sortable table inside one-cell collapsible table, see example on the right.

Customization
Registered users can edit their personal js file file to change some of the variables used.

Other HTML elements
The code that performs the manipulation only checks for table elements, so these classes will not work for other elements, such as  or. There is a similar feature for use with  elements, called "NavFrame".

Limitations
This functionality requires the end-user's browser to have JavaScript enabled. If Javascript is disabled, the default behaviour is to show the content.