Inline CSS
How to style stimulus content. Inline `style="..."` attributes inside HTML markup are the only path — no `style:` property on questions, no `class:` property, no platform-wide stylesheet block. The runtime sanitises every CSS declaration against an allow-list of properties and values.
There’s no style: property on questions
A common assumption is that questions accept a style:
property for visual CSS. They don’t. The style: keyword
is used in the YAML — but for picking a question’s skin
variant, not for CSS.
# style: here means "render this single as image cards", not "apply CSS"
- qid: QPickPackaging
type: single
style: imageCards
text: Which packaging do you prefer?
There’s also no class: property at the question level,
no style: on options or rows, and no top-level - styles:
block for shared rules. Survey skinning is the platform’s job
(theme tokens); per-question CSS goes through inline
style="..." inside HTML.
Inline style="..." is the only path
The sanitiser allows a style attribute on every tag
(it’s in the global allow-list — see
Safe HTML). What goes inside the
attribute is parsed declaration-by-declaration and filtered
against the property and value allow-lists below.
- qid: QStimulus
type: info
text: |
<div style="display: flex; gap: 16px; align-items: center;">
<img src="https://cdn.example.com/logo.png"
style="width: 80px; height: 80px;"
alt="Brand logo">
<p style="font-size: 1.1em; line-height: 1.4;">
Take a moment to look at this brand mark before
continuing.
</p>
</div>
Each declaration is checked independently. Allowed
declarations render. Disallowed declarations are dropped with
a blocked-html-style diagnostic; the rest of the style
attribute survives.
Allowed CSS properties
The sanitiser accepts exactly these property names. Anything else is dropped.
Layout
display
width min-width max-width
height min-height max-height
margin margin-top margin-right margin-bottom margin-left
padding padding-top padding-right padding-bottom padding-left
border border-top border-right border-bottom border-left
border-radius border-collapse border-spacing
overflow overflow-x overflow-y
object-fit
Flex / grid
flex flex-direction flex-wrap
flex-grow flex-shrink flex-basis
gap row-gap column-gap
justify-content align-items align-self
grid-template-columns
grid-template-rows
grid-column grid-row
Typography & colour
color
background background-color
font font-family font-size font-weight font-style
line-height
letter-spacing
text-align text-decoration text-transform
white-space
vertical-align
The list above is exhaustive — the sanitiser allows nothing else. A handful of properties that look like they should be on the list aren’t:
border-color/border-style/border-width— use the shorthandborder:(or per-sideborder-top:etc.) instead.background-image— theurl(...)value syntax is blocked anyway. Drop an<img>inside a positioned container instead.align-content,order,grid-template-areas— intentionally not in the allow-list. Reach for Custom HTML/JS if you need them.text-indent— not allowed. Usepadding-leftinstead.position,transform,animation,filter,clip-path,cursor— also intentionally absent.
Blocked properties and values
Even within allowed properties, the runtime rejects values that contain dangerous patterns:
| Pattern | Reason |
|---|---|
expression(...) | Legacy IE CSS expression — JavaScript injection vector |
javascript: | URL-as-value injection vector |
url(...) | Fetch instruction; rejected to prevent tracking-pixel injection |
position: fixed / position: absolute | Layout escape hatches that overlap UI chrome |
behavior: ... | Legacy IE behaviour binding |
@import ... | Imports another stylesheet — rejected |
The diagnostic surfaced is blocked-html-style in every
case. Authors see it during testing through the diagnostics
panel; the rest of the surrounding style attribute is kept.
Common patterns
Constrain an image to a card layout
- qid: QHero
type: info
text: |
<img src="https://cdn.example.com/hero.jpg"
alt="Hero shot"
style="width: 100%; max-width: 480px; height: auto; object-fit: cover; border-radius: 8px;">
max-width constrains responsively; object-fit: cover
crops to fit; border-radius softens the corners. Every
property here is on the allow-list.
Two-column flex layout
- qid: QSideBySide
type: info
text: |
<div style="display: flex; gap: 24px; align-items: center;">
<img src="https://cdn.example.com/old.jpg" alt="Before"
style="width: 50%; border-radius: 4px;">
<img src="https://cdn.example.com/new.jpg" alt="After"
style="width: 50%; border-radius: 4px;">
</div>
Emphasise piped text
- qid: QGreeting
type: info
text: |
Welcome,
<span style="font-weight: 600; color: #1d4ed8;">{{ QName.value }}</span>.
We have <span style="font-style: italic;">three quick questions</span> for you.
Boxed-out instruction block
- qid: QSection
type: info
text: |
<div style="
background-color: #fef3c7;
border: 1px solid #fcd34d;
border-radius: 6px;
padding: 12px 16px;
margin-bottom: 16px;
">
<strong>Heads up:</strong> the next section asks about
sensitive topics. You can skip any question.
</div>
What you can’t do with inline CSS
- Position elements outside the question frame.
position: fixed/position: absoluteare rejected. Stimulus stays in document flow. - Animate or transition.
animation,transition,transformaren’t on the allow-list. - Background images via
url(...). The wholeurl(...)syntax is rejected. For a background image, drop an<img>inside a positioned container instead, or use Custom HTML/JS for fully bespoke rendering. - Cursor changes / hover effects. Pseudo-classes (
:hover) aren’t in scope at all — inline CSS is per-element only. - Apply a class-based theme. The
class:property doesn’t exist on questions; theme variants come from the platform’s skin tokens, not from author-authored CSS.
For anything beyond the allow-list — animations, custom interactivity, dynamic styling tied to question state — Custom HTML/JS is the escape hatch.
See also
- Safe HTML —
style="..."lives inside the global attribute allow-list; the same diagnostic codes surface - Media — common patterns for sizing and constraining stimulus media
- Custom HTML/JS — when the inline-CSS allow-list isn’t enough, the
custom:block bypasses sanitisation - Theming → Skin variants — platform-level skinning that’s separate from author CSS