FastHTML is a Python web framework for building interactive server-rendered web applications where Python functions return HTML partials, using HTMX to update the page without writing JavaScript.
What is FastHTML?
FastHTML is a next-generation Python web framework developed by AnswerDotAI, designed to map its functionality 1:1 to HTML and HTTP while using Python code as the only input. It produces live web applications in a local browser when you run a short script, with a minimal app consisting of an import, a decorated route function, and a serve() call. The framework relies on fastcore.xml.FT for HTML generation, and on HTMX to handle interactive element swapping in the browser, so you never need to write JavaScript for common interactions. Because apps are plain Python, you can leverage the full Python ecosystem alongside the framework.
Key Features
- Minimal app footprint — A Hello World app is three lines:
from fasthtml.common import *, afast_app()call, and a route decorated with@rt('/')returningDiv(P('Hello World!')), then served withserve(). - HTMX-powered interactivity — The
hx_get="/change"attribute makes the server respond with an HTML partial that replaces the original element in the page, giving dynamic behavior without custom JavaScript. - Python-native HTML components — HTML elements are created by calling functions like
Div(...),P(...), and the framework's functionality maps directly to HTML and HTTP. - LLM-friendly context file — A
llms-ctx.txtauto-generated file is provided so AI assistants can learn FastHTML; the page gives its URL for use in Claude Projects and Cursor. - Idiomatic full-app examples — The repo includes
adv_app.py, a heavily commented example covering custom authentication, JS library connections, and database use. - Gallery of components — The FastHTML Gallery provides minimal examples like chat bubbles, click-to-edit, and infinite scroll to copy from.
Who is it for?
- Python developers who want to build web apps without learning a separate frontend stack or templating language; they can write everything in Python.
- Teams prototyping quickly that need a way to turn a few functions into a working server-rendered app with minimal boilerplate.
- AI-assisted developers who want to generate or modify FastHTML code using assistants like Claude or Cursor, since the project ships an LLM context file specifically for that purpose.
- Hypermedia enthusiasts who prefer the HTML-over-the-wire pattern over building JSON APIs and SPAs; FastHTML is designed around HTMX and HTML partials.
What can you do with FastHTML?
- Click-to-edit interfaces — Add a route that returns a new P or other element and use
hx_geton the original to replace it in place, without full page reloads. - Full applications with auth and databases — Follow the heavily commented
adv_app.pyto see how to integrate custom authentication, JS libraries, and a database into one FastHTML app. - Reusable interactive components — Borrow patterns from the FastHTML Gallery to create chat bubbles, infinite scroll, or edit-in-place controls.
- Markdown rendering — Use community tutorials like Isaac Flath's custom FastHTML tags for Markdown rendering to render rich content in your app.
How does FastHTML work?
Create a file named main.py and run it with python main.py; the framework prints a URL (defaulting to http://localhost:5001) to visit in the browser. Adding a second route that returns an HTML partial and attaching an HTMX attribute like hx_get to an existing element causes that partial to replace the element on click. The framework then serves HTML partials from Python functions, encapsulating the HTTP request–response cycle behind function calls.
FAQ
How do I install FastHTML?
Install the Python library with pip install python-fasthtml. After installation, create a Python file with the minimal app code and run it with python main.py.
Why do AI assistants need a special context file?
FastHTML is newer than most LLMs, so assistants like ChatGPT, Claude, and Copilot don't have reliable knowledge of it. The project provides /llms-ctx.txt which you can load into your AI tool to give it accurate FastHTML syntax and patterns.
What does hx_get do?
It's an HTMX attribute that makes an element fetch a URL and insert the response into the page. In the example, Div(P('Hello World!'), hx_get="/change") causes the P element to be replaced by the response from the /change route when clicked.
Where can I find more examples?
Start with the official documentation at fastht.ml/docs, the heavily commented adv_app.py in the GitHub repo, and the FastHTML Gallery at gallery.fastht.ml for minimal component examples.
Does FastHTML have any documentation gaps?
The project notes that not all features and patterns are documented yet, so you may need to study source code notebooks and examples in the repo to learn the full capabilities.








