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.4.0.tar.gz (17.9 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.4.0-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file html5cc-0.4.0.tar.gz.

File metadata

  • Download URL: html5cc-0.4.0.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for html5cc-0.4.0.tar.gz
Algorithm Hash digest
SHA256 f16fe4a033ad7cea3a039897255d637a59279332ec55538808af57619ab1b292
MD5 645f1b2247426e768b7177897ea28200
BLAKE2b-256 71f9625c59e4e2949dff1eb1f2674981315183d39c43734a959e235276d939fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for html5cc-0.4.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.4.0-py3-none-any.whl.

File metadata

  • Download URL: html5cc-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 15.2 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23d5a6e1e2727e31e9a72dcb5bfab05bb915503446c46d807d760abf78f57a25
MD5 b9b1612aad5a402ac567d05bf835f1b1
BLAKE2b-256 313c29ee4a9d4028b29a127a4a8a8e38f4afeedb939644562a99206a76e8d81e

See more details on using hashes here.

Provenance

The following attestation bundles were made for html5cc-0.4.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

This release

0.4.0 This release

2 files

0.3.0

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