created: 20140305091244145 modified: 20150221175658000 tags: [[Customise TiddlyWiki]] title: Using Stylesheets type: text/vnd.tiddlywiki The first steps to changing the appearance of TiddlyWiki are to choose and apply one of the available themes, or to modify the [[colour palette|ColourPalettes]]. In addition, custom [[CSS stylesheets|http://www.w3schools.com/css]] can be defined by tagging a tiddler `$:/tags/Stylesheet`. Try creating a custom stylesheet now with the following content in order to change the page background colour to red: ``` html body.tc-body { background: red; } ``` ! Overriding Theme Settings Custom stylesheets are applied independently from theme stylesheets. Therefore, it is often necessary for the css rules in your custom stylesheet to be more specific than those of the theme you want to override. For example, `html body.tc-body` is more specific than `body.tc-body`. !!! Ordering of stylesheets Ordering of stylesheets is controlled in the main stylesheet $:/core/ui/PageStylesheet by the following list filter: ``` <$list filter="[all[shadows+tiddlers]tag[$:/tags/Stylesheet]]"/> ``` With help of a list-after field in a custom stylesheet, the order of the stylesheets can be rearranged to ease overwriting theme styles. <<< To check the order of all stylesheets in use, enter the following filter in the filter tab of Advanced search: ``` [all[shadows+tiddlers]tag[$:/tags/Stylesheet]] ``` <<< ! Stylesheet Types Usually it is best to use the type `text/css` for stylesheets. This treats them as plain stylesheets, and ensures that TiddlyWiki doesn't apply any wiki processing to them. If you wish to use macros and transclusions in your stylesheets you should instead use the default WikiText type `text/vnd.tiddlywiki`. This allows full WikiText processing to be performed. Here is an example: ``` \rules only filteredtranscludeinline transcludeinline macrodef macrocallinline html body.tc-body pre { <> } ``` The `\rules` pragma at the top of the tiddler restricts the WikiText to just allow macros and transclusion. This avoids mistakenly triggering unwanted WikiText processing. A stylesheet tiddler is processed such that it is first wikified and then the text portion of the ouput is extracted to apply as the CSS. Any HTML tags you will use in your stylesheet are thus ignored. For example, HTML elements generated by the RevealWidget will not affect the output. As in the following example, you can wrap CSS rules in `
` tags to display them as a codeblock without affecting processing, including handling the inner macro.

```
\rules only filteredtranscludeinline transcludeinline macrodef macrocallinline html

body.tc-body pre {
	<>
}
``` !! Stylesheet Macros The ~TiddlyWiki core provides several [[global macros that are helpful in constructing stylesheets|Stylesheet Macros]].