Element Overview
Box
Block container element for simple layouts
Flex
Flexbox container with full CSS Flexbox support
Text
Text leaf element with automatic line wrapping
Image
Image element with intrinsic dimensions
Box Element
Thebox element is a basic block container. It’s the simplest container type, ideal for simple layouts without flex properties.
Schema
Example
- Basic Box
- With Children
Box Style Properties
Display mode:
"block", "flex", or "none"Width in pixels (number) or percentage (string like
"50%")Height in pixels (number) or percentage (string like
"50%")Minimum width constraint
Maximum width constraint
Minimum height constraint
Maximum height constraint
Margin spacing. Can be:
- Single number:
20(all sides) - Space-separated:
"10 20"(vertical horizontal) - Four values:
"10 20 30 40"(top right bottom left)
Padding spacing with same syntax as margin
Background color (hex, rgb, rgba, or named color)
Border width in pixels
Border color
Corner radius. Can be:
- Single number:
8(all corners) - Four values:
"8 8 0 0"(top-left top-right bottom-right bottom-left)
Opacity from 0 (transparent) to 1 (opaque)
Flex Element
Theflex element is a flexbox container supporting full CSS Flexbox layout. It’s the most powerful container type for complex layouts.
Schema
Example
- Column Layout
- Centered Content
- Badge Row
Flex Style Properties
Flex elements inherit all Box style properties, plus additional flex-specific properties:Flex direction:
"row", "column", "row-reverse", "column-reverse"Main axis alignment:
"flex-start"- Align to start"flex-end"- Align to end"center"- Center items"space-between"- Space between items"space-around"- Space around items"space-evenly"- Even spacing
Cross axis alignment:
"flex-start"- Align to start"flex-end"- Align to end"center"- Center items"stretch"- Stretch to fill"baseline"- Align baselines
Gap between flex items in pixels
Wrapping behavior:
"nowrap" or "wrap"All dimension properties (
width, height, margin, padding, backgroundColor, borderWidth, borderColor, borderRadius, opacity) work the same as in Box elements.Text Element
Thetext element is a leaf element for rendering text with automatic line wrapping and proper text shaping via Parley.
Schema
Example
- Basic Text
- Paragraph
- Centered
Text Style Properties
Font family name
Font size in pixels
Font weight: number (100-900) or keyword (
"normal" = 400, "bold" = 700)Line height as a multiplier of font size
Text alignment:
"left", "center", "right", "justify"Text color (hex, rgb, rgba, or named)
Letter spacing in pixels
Rendering mode:
"text"- Render as SVG<text>element"vector"- Render as vector paths (future feature)
Flex grow factor when inside a flex container
Flex shrink factor when inside a flex container
Image Element
Theimage element renders images with intrinsic dimensions. Images must provide width and height.
Schema
Example
- Basic Image
- Rounded Image
- Constrained
Image Style Properties
Override intrinsic width
Override intrinsic height
Minimum width constraint
Maximum width constraint
Minimum height constraint
Maximum height constraint
Margin spacing (same syntax as Box)
Image fit mode:
"contain"- Scale to fit, preserving aspect ratio"cover"- Scale to cover, preserving aspect ratio"fill"- Stretch to fill
Corner radius for clipping
Image opacity (0-1)
Flex grow factor when inside a flex container
Flex shrink factor when inside a flex container
The
src field accepts both data URIs (data:image/png;base64,...) and external URLs. For self-contained SVG output, use data URIs.Type Definitions
The complete type definitions are available in the source code atcrates/htvg-core/src/element.rs. Here’s the core enum:
Related Topics
Style Properties
Complete style property reference
Layout Engine
How Taffy computes layout