What a strict CSP blocks in inline styles, and what it lets through
Nine ways of writing a style under style-src 'self', measured in three engines, and what it cost TaishoDS Core to take the style attributes out of its HTML.
Pablo Di Filippo
Under style-src 'self', the three engines I tested, the ones Playwright ships (Chromium 156, Firefox 157 and WebKit 27.2), refuse a style attribute, and they refuse el.setAttribute('style', …). They apply el.style.left = '7px' and report nothing. I measured nine ways of writing a style. According to the W3C's CSP Level 3 working draft, cssText and insertRule should be gated on 'unsafe-eval'; the test policy doesn't have it, and no engine blocked them.
| How the style is written | Result in all three engines |
|---|---|
<div style="color: rgb(255, 0, 0)"> | Blocked, style-src-attr violation |
el.setAttribute('style', 'left: 7px') | Blocked, style-src-attr violation |
el.innerHTML = '<div style="width: 7px">' | Blocked, style-src-attr violation |
el.style.left = '7px' | Applied, no violation |
el.style.setProperty('--ts-x', '123px') | Applied, and a stylesheet rule reads it with var() |
el.style.cssText = 'left: 7px' | Applied, no violation |
el.attributeStyleMap.set('width', '7px') | Applied with no violation in Chromium and WebKit; Firefox 157 has no attributeStyleMap |
sheet.insertRule('#x { width: 7px; }'), on a same-origin stylesheet | Applied, no violation |
new CSSStyleSheet(), replaceSync and adoptedStyleSheets | Applied, no violation |
I served the 59 components of TaishoDS Core under that policy. Chromium and Firefox reported no style violations. WebKit and Safari reported them on two components, because of a WebKit regression in the native <select> that, according to its bug report, is already fixed on the engine's main branch. Taking the attributes out had a cost: on four components the value started arriving only once the JavaScript runs, and version 0.18.0 gets part of that back, depending on the browser.
TaishoDS Core is a design system in plain HTML, CSS and JavaScript with no framework (MIT, @taishods/core on npm). On October 20, 2026 the HTML catalog of its components had 98 style attributes, and it has none now. I set the rule because finding where a width or a position came from meant searching the markup and the JavaScript as well as the CSS. With the rule there's one place to look. It's a rule about maintenance, about having one systematic way of doing things, and about consistency; not triggering violations under a strict CSP is a consequence, and I measured it afterwards.
"No inline styles" means something narrow here: the system's HTML ships with no style attribute and no <style> tag. Once the JavaScript has run, an element does end up with style="--ts-progress-value: 35%;" in the DOM: that's what setProperty, the fifth row of the table, leaves behind.
The policy and its two directives
This is the policy I served the components under:
Content-Security-Policy: default-src 'none'; style-src 'self'; script-src 'self'; img-src 'self' data:; font-src 'self'; connect-src 'self'style-src 'self' lets same-origin stylesheets load and nothing else. MDN's pages for style-src-attr and style-src-elem explain that there are two directives underneath it: the first governs inline styles applied to individual elements, the second governs <style> elements and <link rel="stylesheet">; when they're absent the browser falls back to style-src. So the style attribute and the <style> tag are both blocked.
The el.style.left and setProperty rows are what make the rest possible. MDN's style-src page says that style properties set from JavaScript directly on an element's style property are not blocked, and that this can be prevented by disallowing JavaScript through script-src. If the script is already running, the policy has trusted it. I'm not arguing here for or against having a policy like this; I'm writing for people who already have one.
An example on that page lists style.cssText among the things that get blocked, and the W3C's CSP Level 3 specification (the October 27, 2026 working draft) gates the cssText setters and insertRule on 'unsafe-eval'; the same draft flags that part as unfinished ("This needs to be better explained", w3c/webappsec-csp issue 212). The test policy has no 'unsafe-eval' and both rows were applied: no browser currently blocks those methods, as the same MDN page notes. For replaceSync, which the specification doesn't name, all I have is the measurement.
One more detail decides what can be fixed. According to the CSP Level 3 specification, nonces apply to inline scripts and inline styles, not to attributes. A <style> tag can be allowed with a nonce. A style attribute can't: in CSP Level 3 it takes 'unsafe-inline', or 'unsafe-hashes' plus the hash of every exact value, which is no use for a position computed at runtime.
That tells you what breaks. A library that injects <style> tags needs a nonce passed to it. One whose HTML arrives with style attributes forces the policy to be loosened. And one that positions its floating elements from JavaScript, property by property, violates nothing.
The rule: the value travels in a variable
TaishoDS Core had both kinds: 98 attributes in 9 files of its HTML catalog, and 19 writes to .style in 5 JavaScript modules, 12 of them to real properties. I measured that on the code as it was on October 20.
The progress bar was the first kind:
<!-- before -->
<div data-progress-fill="" style="width: 35%"></div>
<!-- now -->
<div data-progress-fill="" data-ts-value="35"></div>The value moved to a data attribute. Core's JavaScript reads it on startup and whenever it changes, and writes it as a variable:
export function pintar(relleno: HTMLElement): void {
const v = relleno.getAttribute(`${P}value`);
setVars(relleno, { '--ts-progress-value': v === null || v.trim() === '' || !Number.isFinite(Number(v)) ? null : `${v}%` });
}P is the data-ts- prefix (the source is in Spanish; pintar is "paint", relleno is "fill"). The other half is in the stylesheet:
&:not(.is-indeterminate) [data-progress-fill] { width: clamp(0%, var(--ts-progress-value, var(--ts-progress-reposo, 0%)), 100%); }--ts-progress-reposo ("reposo" is "at rest") is the value for before the JavaScript runs; it comes up again in what typed attr() gives back.
The tooltip was the second kind: its module wrote seven properties on the element (position, left, top, margin, right, bottom and transform). A strict CSP blocks none of that. I changed it anyway, because with those seven lines part of the tooltip's CSS lived in a JavaScript module. The rule I set is narrower than the browser's: JavaScript writes no property that isn't a --ts-* variable. Today the function that places it adds a class and writes two numbers:
panel.classList.add('is-placed');
// …
setVars(panel, { '--ts-overlay-x': `${x}px`, '--ts-overlay-y': `${y}px` });&.is-placed { position: fixed; inset: auto; left: var(--ts-overlay-x); top: var(--ts-overlay-y); margin: 0; transform: none; max-block-size: var(--ts-overlay-h); }--ts-overlay-h caps the height of a panel that doesn't fit on the side it opens on; it's never written for the tooltip.
The only things that go through JavaScript are the numbers nobody can know ahead of time: where the pointer is, how wide a tab is, what value the slider holds.
What the 98 were made of
78 of the 98 attributes didn't hold a value like the bar's width. They held an anchor name, in an anchor-name or a position-anchor. DatePicker had 64 attributes and 56 of them were those; Combobox had 20 and Popover had 2, every one a name.
Each instance carried its own name (--ts-popover-s3, --ts-popover-s5) so every panel would anchor to its own field. anchor-scope removed the need: the stylesheet declares one fixed name, --ts-anchor, and each component scopes it to its own subtree. Those rules sit inside @supports (anchor-scope: all). All three engines in the test support it. For a browser that doesn't, 0.18.0 ships a fallback: Core's JavaScript places the Menu, Popover, DatePicker and Combobox panels with the same two position variables the tooltip uses. I don't have an engine without anchor-scope to measure that under the policy; I ran it simulated, and it's listed among the limits.
What it cost
It cost three things.
The most expensive: four components that had their value in the HTML started getting it only once the JavaScript runs. Progress, AspectRatio and ScrollArea carried it in a style, and the browser painted it as it parsed; Slider shipped its initial fill in a style="--ts-slider-fill: 40%". Through version 0.17.5, until Core ran, the progress bar looked empty, any ratio other than 1 or 16/9 looked square, a scroll area whose size was neither 100% nor on the scale had no limit, and the Slider showed no fill except in Firefox, where the stylesheet doesn't take it from that variable.
There was a way out, and I turned it down. Leaving a style in the HTML with just the variable, style="--ts-progress-value: 35%", would have made all four look right without JavaScript. It would also have put a style attribute back into the system's HTML, so the rule would have had an exception, and under a strict CSP the browser would block that attribute and log a violation for every bar.
The second cost is the cascade. According to CSS Cascading and Inheritance Level 4, declarations in a style attribute have a higher specificity than any selector, so they beat any application rule that isn't !important; Level 5 of the same specification defines it as a cascade step of its own, "Element-Attached Styles", and the conclusion doesn't change. With classes and variables, an ordinary application rule can now beat the system on AspectRatio's ratio, ScrollArea's limit, Progress's width, or the fallback position of a floating element. If you want to adjust those values, that's an advantage; the cost is that they can now be overridden by accident too, by an application rule that wasn't aimed at the system.
The third is minor: variables that had no prefix were renamed and the old names are gone. --mouse-x, which was in Card's example HTML, is now --ts-spotlight-x.
What typed attr() gives back
With typed attr() the stylesheet reads the number from the attribute with no JavaScript. I didn't evaluate it when I set the rule; version 0.18.0 uses it. In Progress:
@supports (width: attr(x type(*))) {
&:not(.is-indeterminate) [data-progress-fill] { --ts-progress-reposo: calc(attr(data-ts-value type(<number>), 0) * 1%); }
}The variable Core writes still comes first in the var(), so nothing changes once the JavaScript is there, and the HTML still carries no style. AspectRatio reads its ratio the same way, and ScrollArea its limit. On December 2 I measured it under the policy, without Core:
| Before Core runs | Chromium 156, Firefox 157 and WebKit 27.2 (Playwright's build) | Safari 27.2 |
|---|---|---|
| Progress with value 35: bar width | 35% of the track | 0% |
| 4/3 AspectRatio: width over height | 1.33 | 1 |
| ScrollArea capped at 120px: height | 120px | 804px, uncapped |
There were no violations, and with JavaScript turned off in the browser the three engines gave the same numbers. In Safari, CSS.supports('width', 'attr(x type(*))') returns false; with Core, it gives 35%, 1.33 and 120px. According to MDN's compatibility data for attr(), type() is supported from Chrome 133 and Firefox 155, and arrives in Safari 27.3. With the same number, 27.2, Playwright's WebKit applies it and the Safari on my Mac doesn't.
Slider uses it halfway. The stylesheet reads the fill from value only inside @media (scripting: enabled): with Core not loaded yet, the first Slider in the docs (value 40) showed up filled in Chromium and WebKit. With JavaScript turned off in the browser it shows no fill in either, so there's never a fixed fill that doesn't follow the handle; Firefox paints its own in both cases.
One door
A rule like this lasts until someone types el.style.left in a hurry. So every write goes through one function, setVars, and the file it lives in is the only one in Core that writes to .style:
export type TsVars = Record<`--ts-${string}`, string | number | null | undefined>;
const compartido = globalThis as unknown as Record<symbol, WeakMap<HTMLElement, Map<string, string>> | undefined>;
const propias = (compartido[Symbol.for('taisho.core.vars')] ??= new WeakMap());
export function setVars(el: HTMLElement, vars: TsVars): void {
let mias = propias.get(el);
for (const [nombre, valor] of Object.entries(vars)) {
if (valor === null || valor === undefined) {
if (mias?.delete(nombre)) el.style.removeProperty(nombre);
continue;
}
const v = String(valor);
if (!mias) propias.set(el, (mias = new Map()));
mias.set(nombre, v);
if (el.style.getPropertyValue(nombre) !== v) el.style.setProperty(nombre, v);
}
}The type only accepts keys that start with --ts-, so setVars(el, { left: '10px' }) doesn't compile. The function remembers in propias what it wrote on each element and removes only that; a variable the application set is left alone. In 0.18.0, 12 modules import it and write 24 variables.
The type doesn't stop anyone from going around the function. A check does that, check:estilos: in the system's TypeScript it looks for any write to .style, variables included (in Core, that file is the only one exempt), and in its HTML it looks for <style> and the style attribute. It runs in CI and reports 0 violations today. It lives in the repository where I develop the system, not in the public one.
The code half can be taken to any project as an ESLint rule. Core doesn't use it today (its check is the script); I tested it with ESLint 10.15.0:
// eslint.config.mjs
const message = 'Runtime styles are written with setVars(), not directly on the element.';
export default [
{
files: ['src/**/*.js'],
rules: {
'no-restricted-syntax': ['error',
{ selector: "AssignmentExpression[left.object.property.name='style']", message },
{ selector: "AssignmentExpression[left.property.name='style']", message },
{ selector: "CallExpression[callee.object.property.name='style'][callee.property.name=/^(setProperty|removeProperty)$/]", message },
{ selector: "CallExpression[callee.property.name='setAttribute'][arguments.0.value='style']", message },
{ selector: "CallExpression[callee.object.property.name='attributeStyleMap'][callee.property.name=/^(set|append|delete|clear)$/]", message },
],
},
},
{ files: ['src/vars.js'], rules: { 'no-restricted-syntax': 'off' } },
];It forbids el.style.x = … (cssText included), el.style = …, setProperty, removeProperty, setAttribute('style', …) and the attributeStyleMap methods that write (set, append, delete and clear), except in the door's own file. On a file with seven of those writes it reports seven errors, and on one that uses setVars, none. It doesn't look at HTML. It also misses these four writes, each of which I tested:
- an alias:
const s = el.style; s.left = '7px'; Object.assign(el.style, { left: '7px' });- bracket access:
el['style'].left = '7px'; - a
setAttributewith the name in a template literal:el.setAttribute(`style`, 'left: 7px').
The script matches text, so it won't stop code written to fool it. Both of them stop carelessness, not someone who wants to get around them.
The test, and how far it goes
On December 4, 2026 I took version 0.18.1 as published, served it from the same origin under that policy, and built one page per component out of the 179 HTML examples in the docs. Playwright went through the 59 pages in three engines: it hovered, clicked, pressed arrow keys, typed into fields and opened the context menu; on links, hover and focus only. A control page with one style attribute and one <style> tag confirmed the policy was on. Then I loaded the same pages in Safari, with no interactions.
| Engine | Components with style violations | Elements visited |
|---|---|---|
| Chromium 156 | 0 | 386 |
| Firefox 157 | 0 | 387 |
| WebKit 27.2 (Playwright's build) | 2 | 388 |
| Safari 27.2 | 2 | None, page load only |
The test scripts, including the control page and the simulated run without anchor-scope, ship in the public repository with version 0.19.0.
After the interactions, no page had a <style> tag, and no element had a property in its style that wasn't --ts-*. createTheme, which applies a theme using the form in the last row of the first table, produced no violations either, in the three engines or in Safari.
One violation had nothing to do with styles. The Card page logged an img-src violation in all three engines and in Safari: one of its examples loads an image from another origin, and the policy blocks it. It isn't in the table. Anyone copying that example under this policy has to serve the image from their own origin or add the image's origin to img-src.
WebKit's <select>
The violations are on Select and DatePicker, all of them style-src-attr, one per native <select>: 9 on the Select page and 2 on the DatePicker page. They happen on page load, because that <select> is the fallback for when there's no JavaScript and Core removes it on startup.
They don't come from Core. It's a known WebKit regression: "REGRESSION(321159@main): Every <select> triggers a CSP style-src-attr violation from its UA shadow tree". According to the report, filed on October 11, 2026, the engine set a style attribute (text-overflow:inherit) on an internal part of the <select> before attaching it to its internal tree. It's marked as resolved: according to the same report, the fix landed on WebKit's main branch on October 20 and on a Safari branch on November 2, and Safari 27.0.1 didn't have the problem.
On December 2, Safari 27.2 on my Mac (macOS 27.2.1) still has it, and so does Playwright's WebKit 27.2, and I don't know which version the fix ships in. To check whether a given Safari already has it, this page, served with the policy header, is enough:
<!doctype html>
<meta charset="utf-8">
<script src="repro.js"></script>
<select><option>a</option><option>b</option></select>// repro.js
document.addEventListener('securitypolicyviolation', (e) => console.log(e.effectiveDirective, e.blockedURI));With the regression, the console logs style-src-attr inline and an error about a stylesheet ("Refused to apply a stylesheet…"), even though the directive violated is the one for attributes. In Chromium and Firefox it logs nothing.
According to the report, what you'd see is that a <select> the author gave text-overflow: ellipsis loses its ellipsis. My page doesn't use text-overflow, which is why in Safari that <select> measured the same with and without the policy, with the same computed appearance, display, color, background and font size; I didn't compare screenshots.
The limits:
- The test counts violations; apart from those
<select>measurements, it doesn't check that each component looks and behaves right under the policy. - The interactions are generic: a state that only shows up after a particular sequence isn't covered. "Elements visited" are the visible ones among the 647 that match the test's selector in each engine, counted at the end of the run;
<select>elements and file inputs only get hovered. The count differs between engines on three components. - 15 of the 59 pages have nothing interactive (Badge, Separator, Skeleton and twelve others): for those the test only says they load without violations.
- Of the 24 variables, 15 showed up written; the other nine (
--ts-overlay-w,--ts-overlay-h,--ts-scroll-area-max-w,--ts-sticky-top,--ts-sticky-offset,--ts-table-pad-start,--ts-table-pad-end,--ts-tabs-yand--ts-tabs-h) go through the same function, but I didn't see them in that run;--ts-overlay-wshows up in the simulated run in the next item. - All three engines support
anchor-scope, so the 0.18.0 position fallback never runs on its own in any of them. I forced it with a same-origin script that makesCSS.supportsreturnfalsefor anything that namesanchor-, and repeated the run on Menu, Popover, DatePicker and Combobox. The panels ended up withis-placed, with--ts-overlay-xand--ts-overlay-yand, on Combobox, with--ts-overlay-w. There were no violations in Chromium or Firefox; in WebKit, the two from DatePicker's<select>. The stylesheet was still that of an engine with anchoring: a browser that really lacks it is still unmeasured. - Of the other ten values that used to sit in a
style, nine left no visible difference. DatePicker had eight, all of them--ts-date-ch: 10, the field's width in characters; the stylesheet reads it asvar(--ts-date-ch, 10)and in the docs examples Core writes that same 10, but I didn't measure a date format of any other length. Tabs' was aview-transition-namethat neither Core's stylesheet nor its JavaScript used; the active tab is marked from the stylesheet. - Card's did change something. It set the glow's position to zero, and the glow shows up with CSS alone on hover. Without JavaScript and with the pointer over the card, the October 20 markup and stylesheet centered the glow on the top-left corner (
0px 0px); in 0.18.0 it sits at the center of the card. It follows the pointer in neither. The samestylerepeated in--ts-card-paddingthe 32px of thepadding-lgclass: the padding measured 32px then and now, at 1200px and 400px wide. Under compact density, where that class dropped to 20, the variable stayed fixed at 32; I didn't measure that case. attr()only reads the form the stylesheet expects: according to the Behavior guide, the ratio as a decimal number (1.3333, not4/3) and the limit with its unit. Anything else falls back until Core runs; I didn't measure those cases.- The range Slider doesn't use
attr(): until Core runs, its rail doesn't mark the span between the handles in any of the three engines. - Testing in Playwright's WebKit is no substitute for testing in Safari: with the same version number, they differ on typed
attr(). - I ran it by hand: it isn't a test in the repository yet, and what CI checks is the rule (
check:estilos), not the policy.
Try it
I ran it with the published 0.18.1 files copied to the same origin. With the CDN from the installation guide, https://taisho.design has to be added to style-src and script-src; I haven't tested that variant. The scripts ship in the public repository with version 0.19.0; until then, the <select> page above is enough to reproduce the WebKit case.
The source is on GitHub. What I'd like to see in the issues is a component and a state that trigger, under that policy, a violation other than the <select> one; especially in Safari, where I only tested page load.
To try Core on a page of your own, the installation guide starts with an index.html to copy, in the block that expands, with a button and a modal that work with the CDN files. Serving it with the policy above and https://taisho.design in those two directives is testing the variant I didn't. The sign that it passes is a console with no violations: the modal opens and closes even when the JS is blocked.





