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 |
fill_mask | No | auto | Fill width removed along the inside of the outline |
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 |
When both the fill and outline are translucent, the colors would normally become darker where they overlap. The rectangle prevents that overlap automatically.
Set fill_mask to a number when you want to control how much fill is removed along the inside of the outline. A larger value reveals more of the card background between the fill and outline:
Keep fill_mask: auto when the fill should meet the inside of the outline without a deliberate gap.
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.