elementary-swift / elementary
A modern and efficient HTML rendering library - inspired by SwiftUI, built for the web.
AI Architecture Analysis
This repository is indexed by RepoMind. By analyzing elementary-swift/elementary in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.
Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.
Repository Overview (README excerpt)
Crawler viewElementary: HTML Templating in Pure Swift **A modern and efficient HTML rendering library - inspired by SwiftUI, built for the web.** > [!IMPORTANT] > > This repo 📦 moved 📦 to its new home at ** **. > Please update your URLs to avoid trouble - and reach out if anything breaks! > [!NOTE] > > For running Swift apps in the browser, check out **ElementaryUI**. > > > > Examples | Motivation | Discussion Use it Add the dependency to Integration with Hummingbird Integration with Vapor Play with it Check out the Hummingbird + Tailwind example app. For a demo of ElementaryHTMX, see this Hummingbird + HTMX Demo. For a Vapor example, see the Vapor + HTMX Demo. Lightweight and fast Elementary renders straight to text, optimized for serving generated HTML from a Hummingbird or Vapor server app. Any type conforming to can be rendered individually, ideal for testing or for sending fragments with htmx. The default rendering mechanism produces chunks of HTML for efficient response streaming, so the browser can start loading a page while the server is still producing the rest of it. Swift concurrency is used to handle back pressure, so you your memory footprint stays low even for large pages. Alternatively, you can simply collect the rendered HTML in a string. Elementary has zero dependencies (not even Foundation) and does not use runtime reflection or existential containers (there is not a single in the code base). By design, it does not come with a layout engine, reactive state tracking, or built-in CSS styling: it just renders HTML. Clean and composable Structure your HTML with a SwiftUI-inspired composition API. First class attribute handling Elementary utilizes Swift's powerful generics to provide an attribute system that knows what goes where. Every element knows which Tag it is for. As in HTML, attributes go right after the "opening tag". Attributes can also be altered by using the modifier syntax, this allows for easy handling of conditional attributes. By exposing the tag type of , attributes will fall through and be applied correctly. As a sensible default, _class_ and _style_ attributes are merged (with a blank space or semicolon respectively). All other attributes are overwritten by default. Seamless async support Elementary supports Swift Concurrency in HTML content. Simply something inside your HTML, while the first bytes are already flying towards the browser. By using the element, any can be efficiently rendered straight to HTML. Enviroment values Elementary utilizes s to provide a light-weight environment system. Contributing The list of built-in attributes is far from complete, but adding them is really simple (and can be done in external packages as well). Feel free to open a PR with additional attributes that are missing from the model. Thank you to everyone supporting this open‑source project financially. Please consider joining them by sponsoring ElementaryUI . Motivation and other packages Plot, HTMLKit, and Swim are all excellent packages for doing a similar thing. My main motivation for Elementary was to create an experience like these (Swift Forums post for more context), but • stay true to HTML tag names and conventions (including the choice of lowercase types) • avoid allocating an intermedate structure and go straight to streaming HTML • using generics to stay away from allocating a ton of lists of existential s • have a list of attributes go before the content block • provide _attribute fallthrough_ and merging • zero dependencies on other packages Tokamak is an awesome project and very inspiring. It can produce HTML, but it's main focus is on a very different beast. Check it out! swift-html and swift-dom will produce HTML nicely, but they use a different syntax for composing HTML elements. --- *SwiftUI is a trademark of Apple Inc. This project is not affiliated with or connected to Apple in any way.*