Skip to main content

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.py contains the HTML5 document and element primitives.
  • src/html5/elements.py contains generated classes for standard HTML5 tags.
  • src/html5/css.py contains CSS node classes for comments, declarations, rules, at-rules, keyframes, inline styles, and <style> generation.
  • src/html5/js.py contains JavaScript helpers for inline scripts, external scripts, Bootstrap 5, and Google Charts.
  • src/html5/writer.py contains a disk writer for rendered HTML and CSS outputs.
  • src/html5/version.py stores 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

html5cc-0.3.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

html5cc-0.3.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for html5cc-0.3.0.tar.gz
Algorithm Hash digest
SHA256 425c682930ebd29b91937d28b7b2e27d047cd3011b750e6e44875eae0c18ddf0
MD5 c0fa73f37a712a312d7d9c92d6fa36fc
BLAKE2b-256 048e95a558ddce0cd1f2cc86a1e774591d19423f013a6b29df96b052bcf1a07c

See more details on using hashes here.

Provenance

The following attestation bundles were made for html5cc-0.3.0.tar.gz:

Publisher: publish.yml on jasonmiller-cc/html5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for html5cc-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63e243a8f1df36803d4a46293735257379834e85da6cd02326096c28463cf784
MD5 15001e5393207c95ed94a21701014e45
BLAKE2b-256 75f7cea5986ff18767eb7aae9a6f1f471b64bc8c32c6c8700be3b3a688ae14e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for html5cc-0.3.0-py3-none-any.whl:

Publisher: publish.yml on jasonmiller-cc/html5

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.4.0

2 files

This release

0.3.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page