Skip to main content

HTML Responses

Prism includes a .html() response helper for serving HTML content. Combined with Swift’s multi-line strings and string interpolation, you can generate dynamic HTML pages directly from your route handlers.

Basic HTML Response

Simple HTML Page

Dynamic Content

Swift’s string interpolation makes it natural to inject data:
Dynamic HTML

Reusable Layout Functions

Keep your HTML DRY with layout functions:
Layout Helper

Rendering Lists

HTML Table from Data
Always escape user-provided content before inserting it into HTML to prevent XSS attacks. Swift’s string interpolation does not auto-escape HTML entities. Replace <, >, &, and " with their HTML entity equivalents.
For API-first applications, use .html() primarily for admin dashboards, error pages, and occasional server-rendered pages. Pair it with Content Negotiation to serve HTML to browsers and JSON to API clients from the same endpoint.