Wikipedia:HiddenStructure

By using Cascading Style Sheets (CSS), it is possible to hide text in templates from popular web browsers, dependent upon the emptiness of a template parameter. Please, don't use it. This page documents a specific highly controversial method to achieve that.


 * Brion VIBBER [], lead developer of MediaWiki, describes some of the problems with hiddenStructure.


 * Graham87 [], a blind Wikipedian, discusses screen reading software and the limitations therein, and also states that he doesn't believe we should use CSS hacks.

How it works
This method relies on the existence of a CSS class "hiddenStructure". For the en: wiki this is defined in MediaWiki:Common.css as (revision as of 20:50, January 17, 2006): /* hiddenStructure from Monobook - allows selective hiding of markup in templates */ .hiddenStructure { display: none; speak: none; } Any text that is contained within the HTML construct  is hidden. The class can also be applied to any XHTML element, such as  and wikitable rows (|-).

This function is then combined with the parameter default function to achieve selective hiding of text depending on the emptiness of the template parameter. Here is an example of a simple table, which could be part of a template. if the "parameter" is left blank, class  resolves to simply class, completing the CSS call as above. For any value of "parameter", the style becomes meaningless and is stripped by the MediaWiki software, making the table row visible, as well as the data.

Caveats
This method does not hide text from any non-CSS browsers (including text-only browsers, like Lynx), nor from users of many types of screen readers and other accessibility software. Pages relying on this method also fail to display properly when copied to other sites which have not been configured to use the 'hiddenStructure' class, including foreign language Wikipedias and possibly some Wikipedia mirrors. Therefore, it is important that the template be readable and make sense to someone using such a browser. If a page depends on this technique to make sense, then it will break a WAI priority 1 accessibility checkpoint. Some common pitfalls involve overuse of this by marking every row in an Infobox as optional, or using this method to hide punctuation around an optional parameter.
 * Using CSS to hide unintentionally-created document structure is considered poor web authoring practice.
 * This approach will transmit redundant information to the clients
 * In some cases, this approach includes raw wikitext, which is meaningless in the context of an article (e.g. template:Infobox President)
 * This approach creates a slightly different version of an article's content in a visual browser than for other browsers and search engines.
 * If the two versions of an article differ in meaning, then the page fails all three levels of accessibility validation.

Problems
The problem with using hiddenStructure is that it hides rows in a non-standard way. Whereas other websites hide data by simply not sending it out from the server, hiddenStructure defers this hiding process to the client. Because of this, some non-CSS aware or compliant browsers incorrectly render pages using this hack (see pictures at right).

Some pages minimize the damage by only displaying the parameter if it's actually non-blank (using the syntax ). In this way only the row is displayed, not the ugly parameter name. Of course in templates with large numbers of conditional rows, this still results in unnecessary data being displayed to non-CSS compliant browsers.

Because of these problems many articles render poorly for the disabled. In the worst case, a number of Wiki-markup parameters are displayed/read to the reader. In the best case, a number of rows are displayed/read which are empty.

For these reasons, hiddenStructure should not be used.

Footnote:

Solutions
Solutions, in order of preference, are.

Other possible solutions, which are ill-advised, include:
 * Use ParserFunctions
 * Advantage: less server load and less likely to break than other methods.
 * Use Weeble code (such as row).
 * Advantage: Can avoid meta-templates altogether.
 * Problem: Requires that a blank parameter (usually ) be passed. Also, if and when conditionals are implemented in MediaWiki, it may be more difficult to find and replace templates utilizing this method. Finally, templates that use Weeble are generally the ugliest as far as the code is concerned.
 * Limit or eliminate conditional rows.
 * Advantage: Avoids the issue of conditional row displays.
 * Problem: Avoids the issue of conditional row displays.
 * Breaking apart a single template into various multiple other templates, with each handling different combinations of parameters.
 * Problem: This is a maintenance nightmare, and goes against the purpose of templates (centralizing maintenance to one place).

Other uses
One of several accepted uses of CSS  is to hide kludges inserted only for legacy browsers from modern browsers. A typical example are reset-buttons, no modern browser needs this, users can clear textareas locally. Legacy browers don't offer this feature and depend on a reset-button. Users clicking reset unintentionally would lose their modifications in the form. A hidden reset-button only visible with legacy browsers avoids this problem.

Other examples are media specific applications: Emoticons (smileys) as ASCII art are arguably pointless for speech browsers, it's possible to hide them there, maybe offering a WAV. Sometimes copyright info can be restricted to the printed output. Info normally only available for visual browsers with a mouse could be additionally displayed as normal text hidden from most output media except from text, print, and speech. A similar concept is the &lt;noscript&gt; element.

Known uses

 * This is an incomplete list of known uses arguably considered to be harmless, please add what you find:


 * 1) hide - probably not harmless
 * 2) nocss