CSS styling¶
The Flexible Horseshoe Card uses SVG and CSS for most of its visual elements. You can style both the card container and individual layout items through their styles sections.
There are two main levels of styling:
- card-level styles, which affect the card container;
- item-level styles, which affect individual elements such as states, names, icons, circles, lines, and horseshoes.
This lets you keep the default appearance or create a custom design that matches the rest of your Home Assistant dashboard.
Card-level styles¶
Add a styles section to the card configuration to control the appearance of the card container. Typical uses include backgrounds, borders, shadows, padding, and other CSS properties that apply to the complete card.
For example, you can set the card background:
You can also use a background image:
Use card-level styles when the complete card needs a specific visual treatment, independent of the elements inside it.
Item-level styles¶
Most layout items also support their own styles section. These properties apply only to that specific item.
For example, you can style a state value like this:
A horizontal line can use stroke-related properties:
A circle can combine fill and stroke properties:
Item-level styling gives you precise control over the appearance of individual text elements, icons, lines, circles, and horseshoe components.
CSS and SVG properties¶
Many card elements are rendered as SVG. As a result, SVG presentation properties are commonly used alongside standard CSS.
| Property | Used for | Example |
|---|---|---|
fill | Text, icons, and filled shapes | fill: var(--primary-text-color) |
stroke | Lines and shape outlines | stroke: var(--divider-color) |
stroke-width | Line or outline thickness | stroke-width: 2 |
opacity | Overall transparency | opacity: 0.7 |
fill-opacity | Fill transparency | fill-opacity: 0.5 |
stroke-opacity | Stroke transparency | stroke-opacity: 0.5 |
font-size | Text size | font-size: 1.4em |
font-weight | Text weight | font-weight: bold |
text-anchor | SVG text alignment | text-anchor: middle |
stroke-linecap | Shape of line endings | stroke-linecap: round |
Not every property applies to every element. Use stroke for lines and outlines, while fill is generally more appropriate for text, icons, and solid shapes.
Home Assistant theme variables¶
Styles can use Home Assistant theme variables, allowing the card to follow the active theme automatically.
Theme variables are usually preferable to hardcoded colors, especially on dashboards that support both light and dark mode.
Dynamic styles with JavaScript templates¶
Use JavaScript templates when a style needs to change dynamically.
For example, the color of a state can depend on its current value:
Use regular CSS for fixed styling. Add a JavaScript template only when the result depends on an entity state, attribute, or another runtime value.
For more information, see the templating documentation.
Reusing styles¶
Larger cards often repeat the same style definitions. Store shared styles in constants and insert them with ref() instead of duplicating the same YAML.
This reduces repetition and makes future style changes easier to apply consistently.
For more information, see the reuse documentation.
Practical tips¶
Start with Home Assistant theme variables whenever possible. They help the card remain consistent with the active dashboard theme.
Use em for text sizes when the typography should scale naturally with the card.
For lines and outlines, use properties such as stroke, stroke-width, and stroke-linecap. For text, icons, and solid shapes, use fill.
Apply card-level styles to the overall container and item-level styles to individual elements.
Use JavaScript templates only when a style must respond to dynamic data.