A cross-platform Swift package to render any Swift type as HTML.
PointFreeHTML enables any Swift type to be rendered as HTML through a simple protocol conformance. Other libraries use it to render their types to HTML.
- Universal HTML Protocol: Any Swift type can be rendered as HTML by conforming to the 
HTMLprotocol - Performance Focused: Efficient rendering with HTMLPrinter printing to bytes (
ContiguousArray<UInt8>) or string - Declarative Syntax: SwiftUI-like syntax with 
@HTMLBuilderresult builder - Type Safety: Compile-time checking prevents malformed HTML
 - Composable Components: Build complex UIs from reusable components
 - Minimal Dependencies: Core library has minimal external dependencies
 
import PointFreeHTML
struct Greeting: HTML {
    let name: String
    var body: some HTML {
        tag("h1") { "Hello, \(name)!" }
    }
}
let greeting = Greeting(name: "World")
let htmlString: String = try String(greeting)
let htmlBytes: ContiguousArray<UInt8> = greeting.render()HTML and HTMLDocument can render to bytes (ContiguousArray<UInt8>) via the .render() method, or to a string by passing it to String.init(_ html: some HTML, encoding: String.Encoding = .utf8) throws.
For comprehensive examples of building HTML elements and components, see swift-html, which provides a complete developer experience built on top of PointFreeHTML.
See swift-html-css-pointfree for an example of how third-party libraries can integrate PointFreeHTML as their rendering engine.
PointFreeHTML integrates seamlessly with the broader Swift web development ecosystem:
swift-html builds on PointFreeHTML to provide domain-accurate HTML and CSS integration and additional convenience APIs:
import HTML // This imports swift-html which includes PointFreeHTML
struct StyledComponent: HTML {
    var body: some HTML {
        tag("div") {
            tag("a") { "Styled Heading" }
                .attribute("href", "#")
                .inlineStyle("color", "blue")
                .inlineStyle("font-size", "24px")
                .inlineStyle("margin-bottom", "16px")
        }
    }
}PointFreeHTML works with Swift server frameworks like Vapor:
import Vapor
import PointFreeHTML
app.get("hello", ":name") { req -> String in
    let name = req.parameters.get("name") ?? "World"
    struct Greeting: HTML {
        let name: String
        var body: some HTML {
            tag("h1") { "Hello, \(name)!" }
        }
    }
    return try String(Greeting(name: name))
}Add PointFreeHTML to your Package.swift:
dependencies: [
    .package(url: "https://github.com/coenttb/pointfree-html", branch: "main")
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "PointFreeHTML", package: "pointfree-html")
        ]
    )
]Add the package dependency in Xcode:
- File → Add Package Dependencies
 - Enter: 
https://github.com/coenttb/pointfree-html 
PointFreeHTML includes support for snapshot testing:
import PointFreeHTMLTestSupport
@Test
func testMyComponent() {
    let component = Greeting(name: "Coen ten Thije Boonkkamp")
    assertInlineSnapshot(of: component, as: .html) {
        """
        <h1>Hello, Coen ten Thije Boonkkamp!</h1> 
        """
    }
}PointFreeHTML powers production applications:
- coenttb.com: Personal website built entirely with PointFreeHTML
 - coenttb-com-server: Open-source backend demonstrating full-stack Swift
 
- coenttb-blog: A Swift package for blog functionality with HTML generation.
 - coenttb-web: A Swift package with tools for web development building on swift-web.
 - pointfree-html-to-pdf: A Swift package integrating pointfree-html with swift-html-to-pdf.
 - pointfree-html-translating: A Swift package integrating pointfree-html with swift-translating.
 - swift-html: The Swift library for domain-accurate and type-safe HTML & CSS.
 - swift-html-css-pointfree: A Swift package integrating swift-html-types and swift-css-types with pointfree-html.
 - swift-html-prism: A Swift package integrating PrismJS with swift-html.
 - swift-web-foundation: A Swift package with tools to simplify web development.
 
- pointfreeco/swift-dependencies: A dependency management library for controlling dependencies in Swift.
 - pointfreeco/swift-snapshot-testing: Delightful snapshot testing for Swift.
 - apple/swift-collections: Commonly used data structures for Swift.
 
PointFreeHTML is part of a comprehensive Swift web development ecosystem:
- swift-html: Type-safe HTML & CSS DSL built on PointFreeHTML -** use this for examples and full developer experience**
 - swift-html-css-pointfree: Integration layer combining PointFreeHTML with CSS types - use this as example for third-party library integration
 - swift-html-types: Complete Swift domain model of HTML elements and attributes
 - swift-css-types: Complete Swift domain model of CSS properties and types
 
- coenttb-html: Extensions for HTML, Markdown, Email, and PDF generation
 - pointfree-html-to-pdf: Convert HTML to PDF on iOS and macOS
 
- swift-web: Modular web development tools
 - coenttb-web: Feature collection for Swift servers
 - coenttb-server: Modern Swift server framework
 - coenttb-server-vapor: Vapor integration
 
- swift-languages: Cross-platform translation library
 
Comprehensive documentation is available at the Swift Package Index.
This project builds upon the foundational work by Point-Free (Brandon Williams and Stephen Celis). PointFreeHTML is a fork and adaptation of their original swift-html library.
Contributions are welcome! Please feel free to:
- Open issues for bugs or feature requests
 - Submit pull requests
 - Improve documentation
 - Share your projects built with PointFreeHTML
 
- Issues: GitHub Issues
 - Newsletter: Subscribe
 - Social: Follow @coenttb
 - Professional: LinkedIn
 
PointFreeHTML is licensed under the MIT License. See LICENSE for details.