Compile-time wrapper for CSS string literals assigned to element styles.
CssValue wraps CSS string literals assigned to inline styles, which the library parses when written. It checks the literal at compile time to catch mistyped numbers and units before your code runs.
String literals convert to CssValue on their own when assigned to style properties:
hud.style.width = "50%";
hud.style.margin = "0 auto";
hud.style.fontSize = "12pt";
Strings Built at Run Time
Style properties provide a separate overload for dynamic values, parsing the CSS text when it's written.
Wrap a char array filled at run time in std::string_view so the compiler doesn't treat the buffer as a string literal and fail to compile:
std::snprintf(
text,
sizeof(
text),
"%dpx", bar_width);
hud.style.width = std::string_view(
text);
constexpr const char * text() const
Get the literal's text as written (null-terminated).
Definition StyleValue.h:383
- Note
- On older MSVC toolsets (before Visual Studio 2026), a mistyped literal causes a compile error only in a constant expression. In ordinary style writes, it's ignored when written.
- See also
- dom::StyleValue, dom::Element::style