No inline CSS
This page is for designers who write templates. The project rule is short: no <style> block and no style=""
attribute in a template. All CSS lives in the design's stylesheets/ folder and is loaded through ezjscore. The page
explains why, and how to handle the cases that seem to need inline CSS.
Contents
Why
- A Content Security Policy with
style-src 'self'blocks inline styles (CSP-safe design). - Inline CSS is not packed or cached, and is sent again with every page.
- Copies drift: the admin once had 55 templates with their own
<style>blocks, four different accent colors and dozens of white cards that ignored dark mode (the story is in Admin styling, "Why"). - Inline styles beat stylesheet rules, so a theme can no longer restyle the element.
Where the CSS goes
| CSS for | Goes in |
|---|---|
| the whole design | your main stylesheet, loaded by ezcss_load in the pagelayout |
| one kind of page | its own file, asked for by the view template with ezcss_require |
| an admin module page | the shared components first, then stylesheets/modules/<group>.css or the extension's admin stylesheet |
Per-element values
A value that really belongs to one element (a progress percentage, a bar height, a color an editor picked):
A class from a fixed set. admin4 has
.a4-pct-0to.a4-pct-100in steps of 4 for meters and bars:<span class="a4-meter"><span class="a4-pct-$percent|div( 4 )|round|mul( 4 )"></span></span>A
data-*attribute that a script turns into a CSS custom property:<div class="chart-bar" data-value="$value|wash"></div>document.querySelectorAll('.chart-bar').forEach(function (el) { el.style.setProperty('--value', el.dataset.value); /* set from a script file: allowed by style-src 'self' */ });.chart-bar { inline-size: calc(var(--value) * 1%); }Setting a style property from a script file is not an inline style attribute in the markup and is allowed by a policy without
'unsafe-inline'.
Styles that come from content
Rich text can contain alignment or classes chosen by editors; the datatype templates turn them into classes, not
style="". Keep it that way in overrides of ezxmltags/*.tpl. Note that the CSP page says sites with content-made
style="" (embedded players, legacy rich text) should start with Mode=report-only.
Finding inline CSS
grep -rn -E "<style|style=\"" extension/mytheme/design --include=*.tplFor admin designs, tests/tests/design/AdminStylingRulesTest.php fails on every occurrence; the only exception is
design/admin/templates/pagelayout.tpl, for the editor's column widths before the page is drawn, documented in the test
(The admin styling rules test).
Related pages
- No inline JavaScript
- Loading stylesheets
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.