Skip to main content
Hono’s server-side JSX rendering (hono/jsx) converts JSX components directly to HTML strings. This approach is optimized for server performance and integrates seamlessly with Hono’s request/response model.

Setup

Configure your tsconfig.json for server-side JSX:
tsconfig.json

Using c.html() with JSX

The c.html() method accepts JSX and returns an HTML response:

Functional Components

Create reusable components as functions:

Props and Type Safety

Hono JSX is fully type-safe with TypeScript:

Default Props

Components can have default props:
Source: src/jsx/base.ts:17-21

Context API

Share data across components without prop drilling:
Source: src/jsx/context.ts:15-50

Memo for Performance

Memoize components to avoid re-rendering:
Source: src/jsx/base.ts:381-402

Cloning Elements

Clone and modify existing JSX elements:
Source: src/jsx/base.ts:423-440

Children Utilities

Manipulate children with the Children API:

Handling Events (Server-Side)

On the server, event handlers are rendered as string attributes:
For interactive client-side handlers, use hono/jsx/dom for client-side rendering.

SVG Support

Render SVG elements with proper namespace handling:
Source: src/jsx/base.ts:335-345

Async Components

Components can be async for data fetching:
For streaming async components, see the Streaming documentation.

Raw HTML

Insert raw HTML strings:

Boolean Attributes

Hono automatically handles boolean attributes:
Source: src/jsx/base.ts:68-95

Error Boundaries

Handle errors gracefully:
Source: src/jsx/components.ts:52-231

Layout Composition

Build complex layouts with component composition:

Best Practices

Define proper types for all component props to catch errors at compile time.
Components should be pure functions that return consistent output for the same input.
Break down complex UIs into smaller, reusable components.
Context is great for global data, but overusing it can make components less reusable.

Next Steps

DOM Rendering

Learn about client-side rendering with hono/jsx/dom

Streaming

Stream HTML responses with Suspense

HTML Helper

Use the html helper for template rendering

Middleware

Use the JSX renderer middleware