Skip to main content
Hono provides helpers for writing HTML with tagged template literals and experimental CSS-in-JS functionality with scoped styles and SSR support.

HTML Helper

The html 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:
Only use raw() with trusted content. Never use it with user-generated content as it bypasses XSS protection.

Value Types

The html helper handles various types:

Arrays

Arrays are automatically flattened:

Async Content

Supports Promise values for async rendering:

CSS Helper

The CSS helper is experimental. The API may change in future versions.
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

Use cx 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 helper

Reuse 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.

SSR Support

Both helpers work seamlessly with server-side rendering, with styles injected inline for immediate availability.