Simple HTML Generation https://minihtml.trendels.name/
1# minihtml - Simple HTML Generation
2
3[](https://pypi.org/project/minihtml/)
4
5minihtml is a library to generate HTML documents from Python. It aims to
6provide an API that allows you to define the structure of an HTML document in a
7succinct and natural way.
8
9By building up nested HTML elements using context managers, you can combine
10HTML generation with control flow statements in a way that is easy to read and
11does not obscure the structure of the resulting HTML document.
12
13## Installation
14
15Install the `minihtml` package from PyPI:
16
17 pip install minihtml
18
19or
20
21 uv add minihtml
22
23## Example
24
25A basic "hello, world" example:
26
27~~~python
28>>> from minihtml.tags import html, head, title, body, div, p, a, img, ul, li
29>>> links = [("Home", "/"), ("About Me", "/about"), ("Projects", "/projects")]
30>>> with html(lang="en") as elem:
31... with head:
32... title("hello, world!")
33... with body, div["#content main"]:
34... p("Welcome to ", a(href="https://example.com/")("my website"))
35... img(src="hello.png", alt="hello")
36... with ul:
37... for title, url in links:
38... li(a(href=url)(title))
39...
40<...>
41>>> print(elem)
42<html lang="en">
43 <head>
44 <title>hello, world!</title>
45 </head>
46 <body>
47 <div id="content" class="main">
48 <p>Welcome to <a href="https://example.com/">my website</a></p>
49 <img src="hello.png" alt="hello">
50 <ul>
51 <li><a href="/">Home</a></li>
52 <li><a href="/about">About Me</a></li>
53 <li><a href="/projects">Projects</a></li>
54 </ul>
55 </div>
56 </body>
57</html>
58
59~~~
60
61## Links
62
63- [Documentation](https://minihtml.trendels.name/)
64- [Changelog](https://github.com/trendels/minihtml/blob/main/Changelog.md)
65- [PyPI project page](https://pypi.org/project/minihtml/)
66
67## License
68
69Minihtml is released under the MIT license. See [LICENSE](LICENSE) for more information.
70