From Citroen SM Wiki

Content can be made collapsible with Javascript (acting on CSS classes and manipulating their display properties).

This functionality (unlike sortable tables) is not part of MediaWiki. It depends on the code added by admins to the project's MediaWiki:Common.js.

Collapsible table

To make any table collapsible, add a special class collapsible

For example, the following table is defined with {| class="prettytable collapsible":

Always displayed header
Optionally displayed text; optionally displayed text

Initial state

Collapsible table is initially expanded by default.

You can change this with two additional special classes:

  • autocollapse: table will be collapsed if there are more than 2 collapsible tables on the page,
  • collapsed: table will be initially collapsed.

Example: {|class="prettytable collapsible collapsed"

Table width

Since usually the natural width of the header is smaller than of the main content, the table' width will increase after expanding and it will "jump" around. (Also, even if the header would fit in the width of the browser window, the layout engine might divide it over two lines.) It is ugly in itself and inconvenient if you want only to have a quick look at the hidden content and then collapse it again without having to hunt the link with cursor in between. This is prevented by explicitly setting table's width, which then remains the same in the collapsed and expanded state.

Compare this to the first example: {| class="collapsible prettytable" style="width:34em"

Always displayed header, table has width:34em
optionally displayed text: you can see it doesn't matter at all that this is so much longer, table width has been set at 34em


For content that is not a table one can create a table with only one element with content, and a header. However there's a table-less, purely DIV-based solution available on the Wikipedia - see #Collapsible DIV below.

For existing table one can simply add collapsible class. If the table has several colums, it might be a good idea to add a heading row consisting of one cell otherwise the link will be in the first one. Sometimes an easy solution is to put the whole table as element inside another table (see example below); however this is bad from the webdesign and usability viewpoint.

Sortable collapsible table

Sortable table inside a collapsible table:

initially expanded initially collapsed
class="collapsible" class="collapsible collapsed"
name number
a 123
b 6
c 45

If the sortable table is itself made collapsible the positioning of the hide/show button is a bit odd:

initially expanded initially collapsed
class="wikitable sortable collapsible" class="wikitable sortable collapsible collapsed"
name number
a 123
b 6
c 45

Personal customization

Registered users can edit their own monobook.js to change these variables (default values are shown):

<source lang=javascript> autoCollapse = 2 //how many collapsible tables on the page before autocollapse works var collapseCaption = 'hide' //text of the [hide] link var expandCaption = 'show' //text of the [show] link </source>

Collapsible DIV

This functionality is not implemented on Meta, for information see Template:Mlww.

See also

  • Help:Footnotes - another way of separating "main" and "supplementary" content.