{
"type": "text",
"content": "This is body text with increased line height for readability.",
"style": {
"fontSize": 14,
"lineHeight": 1.5,
"color": "#555555"
}
}
Property Categories
Dimensions
Dimensions
Control the size of elements with width, height, and constraints
Spacing
Spacing
Margin and padding using flexible syntax
Visual
Visual
Colors, borders, and opacity
Flexbox
Flexbox
Flex container and child properties
Typography
Typography
Font properties for text elements
Dimension Properties
Dimension properties control the size of elements. They accept either pixel values (numbers) or percentage strings.Width & Height
Element width. Examples:
400- 400 pixels"50%"- 50% of parent width
Element height. Examples:
200- 200 pixels"100%"- 100% of parent height
Size Constraints
Minimum width constraint
Maximum width constraint
Minimum height constraint
Maximum height constraint
- Constrained Width
- Constrained Height
Dimension Type Implementation
Fromcrates/htvg-core/src/element.rs:45-64:
Spacing Properties
Spacing properties (margin and padding) use a flexible syntax supporting 1-4 values.Margin
Outer spacing around the element. Syntax:
- Single value:
20- All sides - Two values:
"10 20"- Vertical, Horizontal - Three values:
"10 20 30"- Top, Horizontal, Bottom - Four values:
"10 20 30 40"- Top, Right, Bottom, Left
- Uniform
- Vertical & Horizontal
- All Sides
Padding
Inner spacing inside the element. Uses the same syntax as margin.
Spacing Implementation
Fromcrates/htvg-core/src/element.rs:66-100:
Visual Properties
Colors
Background color. Supports:
- Hex:
"#fff","#ffffff","#ffffffaa"(with alpha) - RGB:
"rgb(255, 255, 255)" - RGBA:
"rgba(255, 255, 255, 0.5)" - Named:
"red","blue","green","black","white","transparent"
Border color (same format as backgroundColor)
Text color for Text elements
- Hex Colors
- RGB/RGBA
- Named Colors
Color Implementation
Fromcrates/htvg-core/src/element.rs:141-240:
Borders
Border thickness in pixels
Corner radius. Syntax:
- Single value:
8- All corners - Two values:
"8 4"- Top-left/bottom-right, top-right/bottom-left - Four values:
"8 8 0 0"- Top-left, top-right, bottom-right, bottom-left
- Uniform Radius
- Custom Corners
Opacity
Element opacity from 0 (fully transparent) to 1 (fully opaque)
Flexbox Properties
Flex properties control layout behavior for Flex containers and their children.Container Properties
These properties are available onflex elements:
Primary axis direction:
"row"- Left to right"column"- Top to bottom"row-reverse"- Right to left"column-reverse"- Bottom to top
Main axis alignment:
"flex-start"- Pack to start"flex-end"- Pack to end"center"- Center items"space-between"- Space between items"space-around"- Space around items"space-evenly"- Evenly distributed space
Cross axis alignment:
"flex-start"- Align to start"flex-end"- Align to end"center"- Center items"stretch"- Stretch to fill"baseline"- Align text baselines
Space between flex items in pixels
Wrapping behavior:
"nowrap"- Single line"wrap"- Multi-line, wrapping as needed
- Column Layout
- Centered
- Space Between
- Wrapping
Child Properties
These properties are available on Text and Image elements when inside a Flex container:Ability to grow. Value of
1 means the element will grow to fill available space.Ability to shrink. Value of
0 prevents shrinking.Flex Enums
Fromcrates/htvg-core/src/element.rs:256-304:
Typography Properties
These properties are specific to Text elements.Font family name
Font size in pixels
Font weight:
- Number: 100-900 (100, 200, 300, 400, 500, 600, 700, 800, 900)
- Keyword:
"normal"(400),"bold"(700)
Line height as a multiplier of font size
Text alignment:
"left"- Left-aligned"center"- Centered"right"- Right-aligned"justify"- Justified (stretched to fill)
Additional space between characters in pixels
Rendering mode:
"text"- Render as SVG<text>elements"vector"- Render as vector paths (planned feature)
- Heading
- Body Text
- Centered
Font Weight Implementation
Fromcrates/htvg-core/src/element.rs:333-367:
Image Properties
How the image fits within its bounds:
"contain"- Scale to fit, preserving aspect ratio"cover"- Scale to cover, preserving aspect ratio (may crop)"fill"- Stretch to fill exactly
- Contain
- Cover
Display Property
Display mode for Box/Flex elements:
"block"- Block display (default for Box)"flex"- Flex display (default for Flex)"none"- Hide element
Complete Style Type Definitions
Fromcrates/htvg-core/src/element.rs:373-478:
Related Topics
Element Types
Learn about Box, Flex, Text, and Image elements
Layout Engine
How Taffy computes layout with these properties