From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manualManual:Extensions
Crystal Clear action run.png

Release status:Extension status beta

ImplementationTemplate:Extension#type Tag
DescriptionTemplate:Extension#description Allows attaching style sheets to templates that are made available in pages that transclude them
Author(s)Template:Extension#username Marc A. Pelletier
Latest versionTemplate:Extension#version 0.9 (2016-04-07)
MediaWikiTemplate:Extension#mediawiki 1.25.0 or higher
PHPTemplate:Extension#php 5.3 or higher
Database changesTemplate:Extension#needs-updatephp No
LicenseTemplate:Extension#license GNU General Public License 2.0 or later

$wgTemplateStylesNamespaces $wgTemplateFunctionWhitelist $wgTemplatePropertyBlacklist

Hooks usedTemplate:Extension#hook

Translate the TemplateStyles extension if it is available at translatewiki.net

Check usage and version matrix.


Open tasks · Report a bug

The TemplateStyles extension introduces a <templatestyles> tag to supply a cascading stylesheet fragment in templates that, when transcluded, are added to the page CSS.

By default, only transclusions of pages within the Template: namespace will allow style sheets; but the extension can be configured to allow it for other namespaces.


  • Download and place the file(s) in a directory called TemplateStyles in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php:
    wfLoadExtension( 'TemplateStyles' );
  • YesY Done - Navigate to Special:Version on your wiki to verify that the extension is successfully installed.


The TemplateStyles extension works through having a <templatestyles> tag defined in the wikitext of a template page (optionally it can be transcluded from a different page as well). This is designed to be compatible with the common layout many wikis have of transcluding template documentation from a separate page (but is not required).

This content of the <templatestyles> tag is a style sheet fragment containing style rules, or @media at-rules.

When a page is rendered, the union of the style sheets attached to all of the templates transcluded on it is added to the header of the HTML document. This makes the styles avaliable to the template expansions (and the rest of the page). One would generally place the styles within a <noinclude> tag so that the description of the stylesheet is not also transcluded; this does not prevent styles themselves from being transcluded.

Unlike global style sheets (such as Common.css), the template's styles are inlined in the HTML document proper and are therefore not cached independently of the page itself.


Variable Default Description
$wgTemplateStylesNamespaces [ NS_TEMPLATE ] Namespaces allowing transclusion of styles.
$wgTemplateStylesFunctionWhitelist [ "rgb" ] Array of allowable function-like values.
$wgTemplateStylesPropertyBlacklist Array of properties that may not be specified in rules.


See also[edit]