Langbahn Team – Weltmeisterschaft

Wikipedia:HiddenStructure

On hiding text, see Help:Hidden text

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 [1], lead developer of MediaWiki, describes some of the problems with hiddenStructure.

...it's using a CSS hack to hide structure elements, which can fail for text browsers, plaintext renderings of articles, and any HTML display of the article that doesn't use the stylesheet on this site. This harms both the primary site's accessibility and offsite reuse of material.

— Brion VIBBER (talk · contribs)

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

...I would strongly recommend that the css hacks not be used because there will be a sizable number of people using older screen readers, and they may not be able to upgrade.

— Graham87 (talk · contribs)

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 <div class="hiddenStructure">text to hide</div> is hidden. The class can also be applied to any XHTML element, such as <span> 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{{{parameter|}}} 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.

{| 
|- class{{{parameter|}}}="hiddenStructure"
! Header
| {{{parameter|}}}
|}

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

USS Monitor using CSS hacks
USS Monitor using meta-templates
Blue Whale using CSS hacks
Blue Whale using meta-templates

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[1], 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 {{{parameter|}}}). In this way only the row is displayed, not the ugly {{{parameter}}} 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:

  1. ^ Most websites use PHP or ASP to conditionally send data from the server. More advanced designs cache results so PHP/ASP scripts are only executed once for each possible outcome.

Solutions

Solutions, in order of preference, are.

  • 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 if=) 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.

Other possible solutions, which are ill-advised, include:

  • 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 display: none is to hide kludges inserted only for legacy browsers from modern browsers. A typical example is reset-buttons; no modern browser needs this, as users can clear textareas locally. Legacy browsers 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 <noscript> element.

Known uses

This is an incomplete list of known uses arguably considered to be harmless, please add what you find:
  1. Template:Hidetalk links history) - probably not harmless

See also