Rectangle¶
A rectangle adds a four-sided visual element anywhere on the card. Use it as a background, border, panel, highlight, or other visual element.
Rectangles can have a fixed size or automatically fit around a state, name, or area.
Basic configuration¶
Add rectangles under layout.rectangles:
xpos and ypos position the center of the rectangle. width and height define its size.
radius rounds the corners.
For more about the card coordinate system, see Positioning and sizing.
Configuration options¶
| Field | Required | Default | Description |
|---|---|---|---|
xpos | Fixed | Horizontal position of the rectangle center | |
ypos | Fixed | Vertical position of the rectangle center | |
width | Fixed | Rectangle width | |
height | Fixed | Rectangle height | |
fit.section | Fit | Referenced section: states, names, or areas | |
fit.item_id | Fit | id of the item to fit around | |
fit.padding.x | No | 1.5 | Horizontal padding around the fitted item |
fit.padding.y | No | 0.5 | Vertical padding around the fitted item |
radius | No | 0 | Corner radius |
entity_index | No | Not set | Entity used by state-dependent features |
styles | No | Default rectangle style | SVG and CSS styling |
color_stops | No | Not set | Colors the rectangle from its entity value |
Use either fixed xpos, ypos, width, and height, or fit.
Fit around another item¶
A rectangle can automatically follow the position and rendered size of a state, name, or area.
This is useful for backgrounds, borders, and highlights around text whose size can change because of formatting, fonts, values, or language.
The referenced item needs an id:
Add extra space around the fitted item with padding:
A fitted rectangle gets its position, width, and height from the referenced item, so fixed xpos, ypos, width, and height are not needed.
Fill and outline¶
Rectangles are SVG elements and can use standard SVG styling:
Common properties include:
| Property | Use |
|---|---|
fill | Inside color |
stroke | Outline color |
stroke-width | Outline width |
opacity | Opacity of the complete rectangle |
fill-opacity | Opacity of the fill |
stroke-opacity | Opacity of the outline |
See Styling for the complete styling guide.
Color from an entity¶
Connect a rectangle to an entity with entity_index when its color should respond to the entity state:
Use colorstop for distinct color ranges or colorstopgradient for blended colors.
See Color stops for configuring ranges, gradients, palettes, and interpolation.