html5
Small Python helpers for building HTML5 documents, CSS, and JavaScript assets from Python.
Documentation is published on GitHub Pages at jasonmiller-cc.github.io/html5.
The package ships with HTML5 element classes, CSS node classes, JavaScript helpers, CDN helpers for Bootstrap 5 and Tailwind, optimized Google Fonts helpers, a disk writer, and semantic version metadata.
Installation
html5cc is published to PyPI.
The import name is still html5.
pip install html5cc
requirements.txt
html5cc==0.3.0
pyproject.toml (uv)
[project]
dependencies = ["html5cc>=0.3.0"]
See the Installation docs for Poetry and other options.
Example
from html5 import (
CSSDeclaration,
CSSKeyframe,
CSSStyleSheet,
Div,
H1,
HtmlDocument,
Img,
MarkupWriter,
bootstrap5_bundle_script,
bootstrap5_stylesheet,
google_charts_loader,
google_charts_package_loader,
google_fonts_assets,
inline_style,
tailwind_script,
)
styles = CSSStyleSheet()
styles.add_comment("base styles")
styles.add_import("reset.css")
styles.add_rule("body", margin="0", font_family="system-ui")
styles.add_rule("h1", color="#1f2937")
styles.add_media("screen and (min-width: 40rem)", CSSDeclaration("color", "black"))
styles.add_keyframes("fade", CSSKeyframe("from", ("opacity", 0)), CSSKeyframe("to", ("opacity", 1)))
doc = (
HtmlDocument(title="Hello HTML5")
.add_head(*google_fonts_assets("Inter"))
.add_head(bootstrap5_stylesheet())
.add_head(tailwind_script())
.add_head(bootstrap5_bundle_script())
.add_head(google_charts_loader())
.add_body(Div(H1("Hello, world!"), Img(src="hero.png", style=inline_style(("border_radius", "8px")))))
)
print(doc.render())
chart_loader = google_charts_package_loader(["corechart", "table"], callback="drawChart")
writer = MarkupWriter()
writer.write_html("dist/index.html", doc)
writer.write_css("dist/site.css", styles)
writer.write_html("dist/charts.html", HtmlDocument(title="Charts").add_head(chart_loader))
JavaScript Helpers
Use javascript_link() and javascript_script() for arbitrary script tags and inline code. The library also exposes bootstrap5_bundle_script() and Google Charts helpers so you can wire up common browser libraries without hand-building script tags.
Asset Helpers
Tailwind is injected with the official Play CDN script because that is the fastest supported browser-side setup for this library. Bootstrap 5 is injected as a CSS stylesheet from jsDelivr. Google Fonts are emitted as a preconnect pair plus a CSS2 stylesheet link so browsers can establish connections early and only download the fonts you ask for.
Common Tailwind class families that pair well with the helpers:
- Layout:
container,mx-auto,flex,grid,gap-*,items-center,justify-between - Spacing:
p-*,px-*,py-*,m-*,space-x-*,space-y-* - Typography:
text-*,font-*,leading-*,tracking-* - Surface:
bg-*,text-*,border-*,rounded-*,shadow-* - Responsive prefixes:
sm:,md:,lg:,xl:,2xl:
Common Bootstrap 5 class families that pair well with the helpers:
- Layout and grid:
container,container-fluid,row,col,g-*,row-cols-* - Spacing and display:
m-*,p-*,d-flex,d-grid,gap-*,justify-content-*,align-items-* - Typography:
lead,fw-bold,fst-italic,text-muted,text-center,text-nowrap - Components:
btn,btn-primary,card,badge,alert,navbar,modal - Responsive prefixes:
sm,md,lg,xl,xxl
Google Fonts examples:
google_fonts_assets("Inter")google_fonts_assets("Inter", "Open Sans")google_fonts_assets("Roboto", weights=(400, 700), text="Hello world")
Layout
src/html5/document.pycontains the HTML5 document and element primitives.src/html5/elements.pycontains generated classes for standard HTML5 tags.src/html5/css.pycontains CSS node classes for comments, declarations, rules, at-rules, keyframes, inline styles, and<style>generation.src/html5/js.pycontains JavaScript helpers for inline scripts, external scripts, Bootstrap 5, and Google Charts.src/html5/writer.pycontains a disk writer for rendered HTML and CSS outputs.src/html5/version.pystores the semantic version string used by packaging.
Versioning
This project uses semantic versioning. The current package version is 0.3.0, and the release history is documented in CHANGELOG.md.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file html5cc-0.3.0.tar.gz.
File metadata
- Download URL: html5cc-0.3.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
425c682930ebd29b91937d28b7b2e27d047cd3011b750e6e44875eae0c18ddf0
|
|
| MD5 |
c0fa73f37a712a312d7d9c92d6fa36fc
|
|
| BLAKE2b-256 |
048e95a558ddce0cd1f2cc86a1e774591d19423f013a6b29df96b052bcf1a07c
|
Provenance
The following attestation bundles were made for html5cc-0.3.0.tar.gz:
Publisher:
publish.yml on jasonmiller-cc/html5
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
html5cc-0.3.0.tar.gz -
Subject digest:
425c682930ebd29b91937d28b7b2e27d047cd3011b750e6e44875eae0c18ddf0 - Sigstore transparency entry: 2733227066
- Sigstore integration time:
-
Permalink:
jasonmiller-cc/html5@ca34e3670e212e14979fb2063d57310dce048a28 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/jasonmiller-cc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca34e3670e212e14979fb2063d57310dce048a28 -
Trigger Event:
push
-
Statement type:
File details
Details for the file html5cc-0.3.0-py3-none-any.whl.
File metadata
- Download URL: html5cc-0.3.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63e243a8f1df36803d4a46293735257379834e85da6cd02326096c28463cf784
|
|
| MD5 |
15001e5393207c95ed94a21701014e45
|
|
| BLAKE2b-256 |
75f7cea5986ff18767eb7aae9a6f1f471b64bc8c32c6c8700be3b3a688ae14e2
|
Provenance
The following attestation bundles were made for html5cc-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on jasonmiller-cc/html5
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
html5cc-0.3.0-py3-none-any.whl -
Subject digest:
63e243a8f1df36803d4a46293735257379834e85da6cd02326096c28463cf784 - Sigstore transparency entry: 2733227149
- Sigstore integration time:
-
Permalink:
jasonmiller-cc/html5@ca34e3670e212e14979fb2063d57310dce048a28 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/jasonmiller-cc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ca34e3670e212e14979fb2063d57310dce048a28 -
Trigger Event:
push
-
Statement type: