py2html skips external stylesheets and CSS classes by default: every element carries its visual properties as aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nishad12323/py2html/llms.txt
Use this file to discover all available pages before exploring further.
style="…" attribute built at render time. You set colours, borders, spacing, and layout through plain Python keyword arguments — no CSS string concatenation required. The rendering pipeline in getHTML() inspects each tag’s dictionary, assembles all non-empty style values into a single CSS string, and writes it directly onto the element’s opening tag.
Universal Style Parameters
The following parameters are available onButton, Label, Text, Heading, Link, Frame, and CustomTag unless otherwise noted.
| Parameter | CSS property | Default (Button / Label) | Notes |
|---|---|---|---|
fg | color | #00a651 / #000 | Any valid CSS colour value |
bg | background | #deffee / #fff | Accepts colours, gradients, and transparent |
bd | border | "none" | Full CSS border shorthand, e.g. "1px solid #ccc" |
bdradius | border-radius | "50px" | Alias: bdr inside the tag dict |
padx | padding (x-axis) | 15 | Integer pixels; combined with pady as padding: {pady}px {padx}px |
pady | padding (y-axis) | 15 | See padx note above |
py2html stores
padx and pady as a tuple (padx, pady) in the tag dict. The CSS output is padding: {pady}px {padx}px; — vertical first, then horizontal, matching the CSS shorthand convention.Colour Example
Frame-Only Style Parameters
Frame maps to a <div> and supports several layout-specific parameters that other elements do not have.
| Parameter | CSS property | Default | Notes |
|---|---|---|---|
width | width | "auto" | Any valid CSS width, e.g. "320px", "100%" |
height | height | "auto" | Any valid CSS height |
marginx | margin (x) | 0 | Combined with marginy as margin: marginy marginx |
marginy | margin (y) | 0 | See marginx note |
content_manager | display | "block" | "block", "inline", "flex", "grid", etc. |
position | position | "static" | "static", "relative", "absolute", "fixed", "sticky" |
offset | top / left / right / bottom | {"top":"0px","left":"0px","right":"auto","bottom":"auto"} | Only meaningful when position is non-static |
Flex Layout with flex_config
When content_manager="flex" is set on a Frame, the flex_config dict is expanded into individual CSS flex properties. Pass only the keys you want to change — the defaults fill in the rest.
flex_config key | CSS property | Default |
|---|---|---|
"align-items" | align-items | "flex-start" |
"justify-content" | justify-content | "flex-start" |
"flex-direction" | flex-direction | "row" |
"flex-wrap" | flex-wrap | "nowrap" |
"gap" | gap | "0px" |
Link-Only Style Parameter
Link adds one extra parameter not shared by other elements:
| Parameter | CSS property | Default |
|---|---|---|
text_decor | text-decoration | "underline" |
Positioned Overlay with offset
Use position="absolute" (or "fixed") together with the offset dict to place a Frame at an exact position. offset accepts the keys top, left, right, and bottom as CSS length strings.
How Styles Are Assembled in getHTML()
When rendering, getHTML() reads each tag dictionary and builds a style_parts list by checking each style key in order:
style='…' on the opening tag. If no style keys are set, no style attribute is added at all.
Custom HTML Attributes with CustomTag
CustomTag lets you emit any HTML tag and pass arbitrary keyword arguments as HTML attributes alongside the standard style parameters. Extra kwargs are collected into an attrs dict and serialised as key="value" pairs (with values HTML-escaped).
Python does not allow hyphens in keyword argument names. HTML attributes like
data-section must be written as underscores (data_section) and will appear in the rendered HTML with underscores unless you post-process the output.