Wiki source code of HTML & CSS Code Style

Last modified by Lucas Charpentier on 2026/03/11 10:23

Hide last authors
Manuel Smeria 3.3 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
Ecaterina Moraru (Valica) 4.1 5 This document covers some basic conventions that are used in XWiki codebase. Please read over this document and make sure your code conforms to the rules here.
6
Lucas Charpentier 27.1 7 = HTML =
Ecaterina Moraru (Valica) 4.1 8
Vincent Massol 1.1 9 The following rules must be followed:
Manuel Smeria 3.3 10
Thomas Mortagne 10.1 11 * The HTML output produced by XWiki pages must be valid HTML 5.
Lucas Charpentier 26.1 12 * Use kebab-case for values of the {{code language="html"}}class{{/code}} and {{code language="html"}}id{{/code}} attributes
Vincent Massol 1.1 13
Lucas Charpentier 27.1 14 == WCAG ==
Vincent Massol 12.2 15
Lucas Charpentier 37.1 16 The XWiki project is following the [[W3C WCAG 2.1 Guidelines>>https://www.w3.org/TR/WCAG21/]] (level AA). See the [[XWiki accessibility statement>>doc:xwiki:Documentation.UserGuide.Features.Accessibility.WebHome]] for more information about this.
Vincent Massol 12.2 17
Lucas Charpentier 22.1 18 The following WCAG-related rules (not verified automatically) **must** be followed (in addition to the ones automatically enforced by the [[XWiki's WCAG Tests>>Community.Testing.WCAGTesting]]):
Manuel Leduc 15.2 19
Lucas Charpentier 23.1 20 * Only use icons along text alternatives. The text alternative can be visually hidden.
Lucas Charpentier 30.1 21 * The size of the target for pointer inputs must be at least 24 by 24 CSS pixels, in LESS use {{code language="css"}}@target-size-minimum{{/code}} [[see exceptions>>Target size exceptions]].
Vincent Massol 12.3 22
Lucas Charpentier 17.1 23 The following WCAG-related rules **should** be followed:
24
Lucas Charpentier 30.1 25 * The size of the target for pointer inputs should be at least 44 by 44 CSS pixels, in LESS use {{code language="css"}}@target-size-recommended{{/code}} [[see exceptions>>Target size exceptions]].
Lucas Charpentier 29.1 26 * [[Properly hide elements>>Properly hiding elements]]
Lucas Charpentier 17.1 27
Ecaterina Moraru (Valica) 3.1 28 = CSS =
29
30 The following rules must be followed:
Manuel Smeria 3.3 31
32 * the CSS must be valid conform [[CSS 2.1 specification>>http://www.w3.org/TR/CSS21/]]. This can be tested using the [[W3C CSS Validator>>http://jigsaw.w3.org/css-validator/]]
Lucas Charpentier 39.2 33 * don't use ##!important## declarations.
34 ** An exception to this rule is allowed for a generic CSS class whose purpose is to force some styling (which cannot be forced otherwise).
Ecaterina Moraru (Valica) 3.1 35 * don't use inline style declarations
Lucas Charpentier 36.1 36 * (((
Lucas Charpentier 39.1 37 Some properties must not be hardcoded. Instead they must use Flamingo ColorTheme variables ([[LESS variables>>doc:xwiki:Documentation.DevGuide.FrontendResources.Style variables.WebHome||anchor="HLESSvariables"]] or [[CSS properties>>doc:xwiki:Documentation.DevGuide.FrontendResources.Style variables.WebHome||anchor="HUsingCSSproperties"]]). Those properties are:
Lucas Charpentier 36.1 38
Lucas Charpentier 36.2 39 * Colors
40 * Font weights
Lucas Charpentier 36.1 41 )))
Lucas Charpentier 35.1 42 * All colors must be defined for either a foregound or a background. To name those, use the “color” word in the variable name for foreground color, and the “background” or “bg” words in the variable name for background colors. For example, we use {{code language="css"}}@btn-default-color{{/code}} for the text color in the default button, and {{code language="css"}}@btn-default-bg{{/code}} for its background color.
Manuel Leduc 15.2 43 * test your code all the [[supported browsers>>doc:Community.SupportStrategy.BrowserSupportStrategy]]
Manuel Leduc 14.1 44 * the unit must be omitted when the value is zero (i.e., ##width: 0;## is ok, and ##width: 0em;## is not) 1) the unit is optional in this case 2) it is more concise
Lucas Charpentier 38.1 45 * Use kebab-case for CSS properties (and LESS variables) names.
Ecaterina Moraru (Valica) 3.1 46
47 The following recommendations could be followed:
Manuel Smeria 3.3 48
Vincent Massol 3.2 49 * Properties:
Manuel Smeria 3.3 50 ** alphabetical order
51 ** 2 spaces indentation
Ecaterina Moraru (Valica) 8.1 52 ** put a space between selector and declaration start, ex. "##a {}##"
Lucas Charpentier 31.1 53 ** put a space before the property value, ex. "background-color: @dropdown-bg;"
54 ** use CSS shorthands
Manuel Smeria 3.3 55 ** use relative sizes (em, %) instead of fixed ones (px)
Manuel Leduc 16.1 56 ** IE hacks must be removed when updating existing code (since we do not support it anymore)
Lucas Charpentier 18.1 57 ** Avoid using {{code language="css"}}display: contents{{/code}}.
Ecaterina Moraru (Valica) 3.1 58 * Organization:
Manuel Smeria 3.3 59 ** comment headers for separation and grouping of different parts of the code
Lucas Charpentier 24.1 60 ** Separate adjacent rulesets with an empty line.
Ecaterina Moraru (Valica) 3.1 61 * Overwriting:
Manuel Smeria 3.3 62 ** document the localization of the overwrite using "Overwrites" and "Should be in" comments
Ecaterina Moraru (Valica) 3.1 63
Manuel Leduc 10.4 64 == Comments ==
65
Manuel Leduc 11.2 66 **Short comments** (less then 120 characters):
Manuel Leduc 10.4 67
68 {{code language="css"}}
69 /* This is a short comment. */
70 {{/code}}
71
Manuel Leduc 11.2 72 **Long comments**:
Manuel Leduc 10.4 73
74 {{code language="css"}}
75 /* This is a very long comment that wraps
76 on multiple lines ...
77 and so on. */
78 {{/code}}
79
Manuel Leduc 11.2 80 **Sectionning**:
Manuel Leduc 10.4 81
82 This style should be used to declare sub-sections on a CSS file.
83
84 {{code language="css"}}
85 /**
86 * Section title.
87 */
88 {{/code}}
89
Ecaterina Moraru (Valica) 5.1 90 == Tools ==
Ecaterina Moraru (Valica) 3.1 91
Manuel Smeria 3.3 92 * [[Firebug>>http://getfirebug.com/]]
Ecaterina Moraru (Valica) 3.1 93 * [[CSS Optimizer>>http://www.cssoptimiser.com/]] and [[CSS Compressor>>http://www.csscompressor.com/]] are two excellent online tools that can shrink CSS
94
Vincent Massol 1.1 95 = Testing =
96
Vincent Massol 12.2 97 See the [[Community.Testing]].

Get Connected