Framework

aihtml · Web pages written in Erlang functions

Pages are assembled from prefabricated functions and served as complete static HTML, enhanced in the browser by Stimulus controllers and styled with Tailwind CSS. A button click is answered directly by an Erlang function: each event is one stateless request, and the response is the DOM operation to apply.

Rendering rides on BeamAI Render: escaping and safe-marking match Jinja templates, so rendered fragments drop straight into Jinja templates. Frontend assets are prebuilt and shipped with the release — users need no Node.js.

Pages in Erlang, clicks answered in Erlang

Erlang: a button and its click handler
ah_button(<<"Delete">>, Id, [borderless],
          [on(click, {?MODULE, delete, #{id => Id}})])

action(delete, #{id := Id}, _Event, Ctx) ->
    ok = todo_db:delete(Id),
    aihtml_action:remove(Ctx, {id, [<<"todo-">>, integer_to_binary(Id)]}).

Features

What it can do

  • Functions are pages

    ah_* builder functions and the equivalent record syntax assemble pages; aihtml:render/1 returns iodata, and a page is just what an ordinary HTTP handler outputs.

  • Stateless interaction

    Clicks and inputs are single POSTs handled by Erlang functions that return DOM operations (replace, morph, remove, set attributes…). The server keeps no session — any node can serve any request. Interactions that don't need the server are written with on_client as local operations that run in the browser without a request; tabs, expanders, and progress bars also update themselves from data-ah-value attributes.

  • Server push

    Pages subscribe to topics and the server pushes the same DOM operations over SSE; one EventSource per page, signed topics, and automatic backfill from the data layer after reconnect.

  • 112 components, four theme axes

    Components and themes ported from sigil: DataGrid, Calendar, NodeGraph, charts, a Markdown editor and more — 111 components plus a server-rendered markdown_view. Appearance, color, typography, and shape combine freely across four axes.

  • SEO-friendly

    Page metadata (description, canonical, hreflang, Open Graph, JSON-LD) is written server-side; charts carry hidden data tables; pagination and calendar navigation are real <a href> links, so every state has its own URL.

  • Internationalization

    Component copy lives in per-language JSON files with English and Chinese built in; date formats, AM/PM, and the first day of the week follow the language.

Specifications

Technical specifications

RuntimeErlang/OTP 27+ (uses OTP's built-in json module), rebar3
Modulesaihtml (core), aihtml_cowboy (optional cowboy endpoint), aihtml_example (demo site)
FrontendStimulus 3 + Tailwind CSS v4, strictly typed TypeScript bundled by Vite, no jQuery; prebuilt with the release
ServersThe core does not depend on cowboy; any other server just implements the action and push endpoints
LicenseApache License 2.0

FAQ

You might be wondering

Do I have to write JavaScript?

Usually not. Pages and interactions are written in Erlang; component behavior in the browser comes from the library's Stimulus controllers. Frontend assets are prebuilt, so no Node.js is needed.

Must I use cowboy?

No. The core doesn't depend on cowboy; aihtml_cowboy is just a ready-made endpoint. Any other HTTP server works if it implements the action and push endpoints.

Relationship with BeamAI Render?

aihtml's escaping and safe-marking come from BeamAI Render and match Jinja templates, so fragments rendered by aihtml drop straight into Jinja templates.

What is the license?

Apache License 2.0, fine for commercial projects.

Open source

Apache 2.0 open source

The engine, tests, benchmarks, and design docs are all in the repository — read them, change them, file issues.

Related framework

BeamAI Render · Template and Markdown rendering for Erlang

Mustache and Jinja2 templates compile to Erlang modules at build time — rendering is one function call — plus a Markdown engine ported from markdig with 30 extensions. Zero dependencies.