HTML Helper
Thehtml helper allows you to write HTML using tagged template literals with automatic escaping.
Import
Basic Usage
Automatic Escaping
String values are automatically escaped for security:Values are escaped by default to prevent XSS attacks. Use the
raw helper only when you trust the content.Raw HTML
When you need to insert unescaped HTML:Value Types
Thehtml helper handles various types:
Arrays
Arrays are automatically flattened:Async Content
Supports Promise values for async rendering:CSS Helper
The CSS helper provides CSS-in-JS functionality with automatic class name generation and scoped styles.Import
Basic Styling
The
<Style /> component must be included in the document head to inject generated styles.CSS Variables
Use JavaScript variables in your styles:Combining Classes
Usecx to combine multiple class names:
Conditional Classes
cx supports conditional classes:
Keyframes
Define CSS animations:View Transitions
Support for View Transitions API:Multiple CSS Contexts
Create separate CSS contexts for isolation:CSP Nonce Support
Add nonce for Content Security Policy:Raw CSS Strings
For advanced use cases, work with raw CSS strings:Best Practices
Always Escape User Input
Use the default escaping behavior for all user-generated content
Include Style Component
Remember to add
<Style /> in the document head when using CSS helperReuse Classes
Define common styles once and reuse them with
cx()Test Browser Support
CSS helper is experimental - test thoroughly in your target browsers
Performance
The CSS helper automatically deduplicates styles and only injects each class once, even if used multiple times.