Expand description
CSS contextual output encoders.
provides two encoding contexts:
for_css_string— safe for CSS string values (inside quotes)for_css_url— safe for CSSurl()values
both use CSS hex escape syntax (\XX) with a trailing space appended
when the next character could be misinterpreted as part of the hex value.
§security notes
- CSS string values must be quoted. these encoders produce output safe
inside
"..."or'...'delimiters. - these encoders do not validate CSS property names, selectors, or expressions. encoding cannot make arbitrary CSS safe — validate the structure separately.
- for
url()values, the URL itself must be validated (scheme whitelist, etc.) before encoding. encoding only prevents syntax breakout.
Functions§
- for_
css_ string - encodes
inputfor safe embedding in a quoted CSS string value. - for_
css_ url - encodes
inputfor safe embedding in a CSSurl()value. - write_
css_ string - writes the CSS-string-encoded form of
inputtoout. - write_
css_ url - writes the CSS-url-encoded form of
inputtoout.