šŸ”¹ Card-mod - Add css styles to any lovelace card

Hi, can I change state color ?

          - type: picture-elements
            image: /local/images/computer/synology_ds1515.png
            elements:
              - type: state-icon
                entity: sensor.nas_drive_1_status
                style:
                  top: 30%
                  left: 25%
                  '--paper-item-icon-color': var(--my-icon-color)
              - type: state-icon
                entity: sensor.nas_drive_2_status
                style:
                  top: 30%
                  left: 37%

I try this code but nothing:

          style: |
            ha-card {
              --my-icon-color: {% if is_state('sensor.nas_drive_1_status', 'normal') %} green {% else %} red {% endif %}
            }

You can just use state_filter for that without card_mod.

Thanks, but state_filter not set color.

What do you mean?

thanks all the same but i solved with this code using condition

          - type: picture-elements
            image: /local/images/computer/synology_ds1515.png
            elements:
            # Synology Drive 1 Status
              - type: conditional
                conditions:
                  - entity: sensor.nas_drive_1_status
                    state: "normal"
                elements:
                  - type: state-icon
                    entity: sensor.nas_drive_1_status
                    style:
                      top: 30%
                      left: 25%
                      "--paper-item-icon-color": greenyellow
              - type: conditional
                conditions:
                  - entity: sensor.nas_drive_1_status
                    state_not: "normal"
                elements:
                  - type: state-icon
                    entity: sensor.nas_drive_1_status
                    style:
                      top: 30%
                      left: 25%
                      "--paper-item-icon-color": red```

First post here. Having some trouble applying custom color to my icons on the simple-thermostat card using card-mod. I’m using the raw editor and I know card mod is installed correctly because I’m able to change colors on an entities card just fine. Below is what I have for the thermostat. I used inspector in Edge/Chrome to see where the color is coming from and I’m thinking it might be because it is inherited from shadow-root? I just don’t know why. I have no theme applied. I’ve tried a lot of different ways of changing the color including rgb(), typing it, or using the #hex. No matter what I do the auto color will not change from springgreen. I’m sure it’s something simple I am missing. Can anyone suggest a fix? heat_cool

- type: 'custom:simple-thermostat'
  entity: climate.thermostat
  sensors:
    - entity: sensor.thermostat_humidity
      name: Humidity
  control:
    hvac:
      heat:
        name: false
        icon: 'mdi:fire'
      cool:
        name: false
        icon: 'mdi:snowflake-variant'
      heat_cool:
        name: false
        icon: 'mdi:cached'
    style: |
      ha-card.mode-item.active.off {
        background: red;
      }
      ha-card.mode-item.active.heat_cool {
        background: #efbd07;
      }

I am not sure if I am getting your point.
You mentioned this code as ā€œnot workingā€:

style:
  element-card:
    $:
      another-thing:
        $: |

I am not sure what do you mean by ā€œelement-cardā€, but this code works:

type: entities
title: 'Common: color icon'
style:
  hui-text-entity-row:
    $:
      hui-generic-entity-row:
        $:
          state-badge:
            $:
              ha-icon:
                $: |
                  ha-svg-icon {
                    color: red;
                  }      
entities:
  - entity: sun.sun
  - entity: sun.sun

изображение

Try setting --heat_cool-color with !important to ha-card instead. You might need to use mod-card.

I guess the old syntax was fixed, too.

That worked! Thank you!

Well, at least using one more syntax gives us more flexibility!

just a thought, but would it all be possible have the overview posts separated into a Community Guide of sorts. No discussions there, those are done here, simply all posts like @Ildar_Gabdullin did for the various cards and stylings.

Right now, we need to go back and forth in this thread to find these (or save them locally, as I did…). I think it would be very beneficial to all of us to have them on display permanently.

With the separated/dedicated community guide, checking how to style a badge, or a font-size for Entities card would be a breeze.

4 Likes

I would appreciate guidance for suppressing the display of the entire toggle button in an Entities card.

I’ve tried enough things to confirm I don’t have a good grasp of the core concepts (i.e. seems straighforward in theory but not in practice). For example, I tried this but it doesn’t work:

type: entities
entities:
  - entity: input_boolean.test
show_header_toggle: false
style:
  ha-entity-toggle:
    $: |
      ha-switch {
        display: none !important;
      }

The toggle button is within a shadow-root and, based on my limitation understanding, that implies more complexity in how to define the item I wish to act on.

1 Like

The doc says:
ā€œI recommend using HACS to install and keep track of plugins.ā€
But this plug-in is nowhere to be found in HACS ?
Is a custom repository needed to install it ? If so, what’s the URL ?

Hi.
Thanks for all your work and help here!

I’ve searched for a few days but cant seem to figure out how it actually works.
I’ve also read that there might be problems with picture elemts cards, but there was a work around?

I have 2 icons, which actually should show a debug boolean state (removed to simplify) but I just want to change the color depending on on/off state and the only way to do it seems to be card-mod.

elements:
  - icon: 'mdi:android-debug-bridge'
    title: Debug
    type: icon
    style:
      '--mdc-icon-size': 40px
      color: 'rgba(255, 0, 0, 0.6)'
      background-color: 'rgba(3, 169, 244, 0.6)'
      border-radius: 50%
      top: 35%
      left: 40%
      padding: 10px 10px 10px 10px
  - icon: 'mdi:android-debug-bridge'
    title: Debug
    type: icon
    style: |
      hui-icon-element {
        color: blue;
      }
image: /
type: picture-elements

But I’m unable to make the second icon use any of the attributes of the first icon.
I’ve also tryed the debug method of my browser and found some elemts names but they modify colors of the entire page.

<hui-icon-element class="element" style="--mdc-icon-size:40px; color: rgba(255, 0, 0, 0.6); background-color: rgba(3, 169, 244, 0.6); border-radius: 50%; top: 35%; left: 40%; padding: 10px;"></hui-icon-element>

Any help apreciated

Uh, Maybe I can hepl here!

I just made it work:

In Hacs, under Frontend, press ā€œ+ EXPLORE & ADD REPOSITURIESā€ and search for card-mod. Think thats how I made it work!

1 Like

Found it :+1: Thank you!

2 Likes

Here all my posts which may be useful:


NOTE:
Do not forget to add a "card_mod:" keyword before "style:" (new in card-mod 3).
And also read this important note to create optimized code. In most examples here a code is NOT optimized - just to describe a DOM navigation.


Entity card
post
rotating icon (by @dolodobendan)
disabled tap_action


Entities card (including some special row elements - button, section, divider)
post
using standard vars for some domains

font-size for Entities card
post

Entities card with attributes
post

Slider entity inside Entities card
main post
popup baloon issue
hide the popup baloon

"hui-input-number-entity-row" - entity row for "input_number"
main post
How to make input_number rows look less different from other entity rows - part 1, part 2

input_select row
main post
How to make input_select rows look less different from other entity rows - part 1, part 2
How to add secondary_info: last-changed

input-text row
post
How to make input_text rows look less different from other entity rows - part 1, part 2

input_datetime row
part 1
part 2
How to make input_datetime rows look less different from other entity rows - part 1, part 2

Conditional row inside Entities card
post

Toggle row inside Entities card
colored checkbox
how to disable a toggle button
how to disable a toggle button - inside auto-entities
moving toggle to the left
super narrow version

Hiding checkboxes inside Entities card
for some entity row
for all entity rows

Animations for Entities card
post

ā€œChipā€ buttons
post
card-mod theme for chip buttons
changing styles for a particular button in a footer dependently on a state
changing an icon

Cover entity row
main post
disable a cover control conditionally
ā€œnarrowedā€ look

Light entity row
how to show lights with using only ā€œactiveā€ & ā€œinactiveā€ colors

How to manage a row’s height
decrease height
increase height

How to shift rows to the right
post

How to center weblinks & commands
post

ā€œEmpty slotā€ for Entities card
post

Circular progress indicator
post


Glance card
main post
changing margin
Allocate items in a compact manner
Place names below icons


entity-filter
style rows dynamically


Footer / Header
post


custom:multiple-entity-row
main post
displaying "last-changed" or any other labels for items
distribute items evenly
animated icons
dynamic icons
show values of 2 attributes in secondary-info


custom:fold-entity-row
main post
How to enable / disable a ā€œfold / unfoldā€ control for fold-entity-row
RTL fix for a section row


custom:template-entity-row
main post
t-e-r inside a conditional row


custom:numberbox-card
post


custom:multiline-text-input-card
post


custom:text-divider-row
post


Tile card
colored icon & background on hover
remove background from an icon
dynamically set icon
adding a button
custom icons for features
long states
input_select: one-line look


Heading
post
change icons


Thermostat
custom icons for features


Distribution card
customize a bar’s height


custom:bar-card
animation
2 text lines
displaying an image instead of an icon
centered title
hide the whole bar-card if all bars are hidden
replacing a value
adding a prefix
RTL fix for vertical bars


Gauge
disabled tap_action
colored needle
adding an additional label
ā€œmirroredā€ gauge


markdown
scrollbar
scrollbar for some text
markdown with images
markdown with a table: post 1, post 2, post 3
colorize only some text
external js for ā€œhrā€ element
styling an icon on hover (original idea of @Spartacus)
header


Picture Glance card
post
changing an icon by card-mod
distributing icons
changing a background image - post, also a config-template-card based way


Sensor card with a graph
post


History-graph card
styling
prevent clipping when using inside stack-in-card
added scrollbar
custom line colors
custom timeline colors
how to set a 0 lower bound for Y-axis
styling a tooltip
how to add an icon to a card’s title
how to set a height


statistics-graph card
post
grouping / aligning labels
custom line colors
replacing a label
how to set a 0 lower bound for Y-axis


custom:mini-graph-card
main post
animation - blinking name, resized & rotating icon
how to display an additional info on the card
how to display additional text items (prefixes & suffixes)
solid (non-semitransparent) fill
move a graph for the 2nd sensor to the bottom
how to set a color for the last bar
place 2 sensors’ states on the left side
displaying states as a part of the legend
displaying a UoM under the state
displaying a UoM before a state
displaying a state & extrema data on the same line
using card-mod to compare mini-graph-card & history-graph
non-elegant & unstable way to show labels for X-axis
fixing an issue with a card inside state-switch
imitating statistics card
how to nicely align legend’s elements
compact view when used in horizontal stack or grid
styling Y-axis labels’ background
how to change graph’s color dynamically
styling points


custom:apexcharts
RTL fix


Weather Card
post


Styling a card inside ā€˜custom:config-template-card’
post


Styling a card inside ā€˜custom:decluttering-card’ + passing a style as a variable
post 1
post 2


Badges (before 2024.8)
important - fix to restore a possibility to style badges after 2024.8
Important - how to style badges in card-mod 4.x
Badges: different styling
Badges: conditional show/hide
Badges: hidden name
Square badges
Dynamic icon
Show either an icon or a value
Manually added UoM
Replacing a state
Replacing a UoM
Gradient colors for a badge dependingly on a value (by @parautenbach)
Horizontal spacing between badges


Badges (2024.8)
badges themselves
badges themselves (mod-card) by @arganto
themes - one, two, three


custom:badge-card
post
after 2024.8


Picture Elements card
main post
conditional elements
rotated background image
ā€œselection areaā€
3 ways to change an element dynamically
on-hover effect for elements
example: show a charging process


Logbook card
main post
styling images by using external js-module
Logbook in a Panel mode
styling a scrollbar (style is unstable)


Media Player card
post


custom:mini-media-player
post


vertical-stack, horizontal-stack
main post
How to fix the ā€œmargin-topā€ problem for a hidden conditional card
Stack inside ā€œhui-elementā€ card
Removing internal borders & margins inside vertical-stack
Line-breaks in horizontal stack
How to add an icon to a card’s title
Adding tap-action for stack-in-card


grid
how to add an icon to a card’s title
customizing a grid in sections


custom:stack-in-card
main post
example of customizing a width in a horizontal stack
styling a header
how to add an icon to a card’s title
prevent clipping of a tooltip of history-graph card & a dropdown list of an input_select


See next part below →

215 Likes
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 1)
Changing the state color - how?
What's the best way to learn CSS for home assistant
Card Mod - Style Secondary Info Text
Lovelace: Multiple entity row
CSS styling with '|' in picture elements
Lovelace Card Mod w Conditional Color Formatting
Color of switch without feedback
Help a non-programmer out
🌻 Lovelace UI • Minimalist
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
Mushroom Cards Card Mod Styling/Config Guide
Change font and icon color of entities based on template
Blinking Gauge card
Mushroom-template-card icon/scripts
Can you get image for area in template?
Please help, banging head against wall!
Frontend install?
Card-mod Loading Delay in Home Assistant Companion App for iOS
Change colour of state-icon with numeric value
Change of entity icon color in heading card
Best approach to prefix mdi:icon to state-label?
Picture Element - State Badge Label removal
How to change font-size of entity card? I'm lost
How to change state color for template sensor
Gauge Card name: not updating?
Tile card, changing the icon colour depending on the sensor value
Changing the font size for temperature in the Weather Forecast card using card-mod
Custom Styling
Change Lovelace card background colour
Do all cards support transparent borders\background
Overlaying multiple cards
Mushroom Cards Card Mod Styling/Config Guide
Card mod: entity card type: section
Applying color to state-label depending on sensor value
How to disable this buttons from default area card?
Card layer level
Custom Card Mod - Change Icon & Colour on State
Mushroom Cards Card Mod Styling/Config Guide
Change Badge font size or badge size overall?
Just want to increase Font size on a Tile Card past 20px
Want to change the font size in a tile card
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
Sensor output in name:
Styling area card with custom CSS
Picture-elements card and card_mod
Manage dynamically a gauge colour range
Card Mod keyframe ping in markdown card
Card-mod selector syntax
šŸ”¹ Card-mod - Super-charge your themes!
Picture-elements card state-icon: trying to make a mdi:fan rotate on its axis, but can't be centered
Card-Mod - Grid/Button Cards
Dynamic colors
Default background of state-icon for specific domains
Need help with card_mod and input_datetime
šŸ”¹ Card-mod - Super-charge your themes!
Solutions for LPG tank monitoring
šŸ”¹ Auto-entities - Automatically fill cards with entities
Dynamic positions in picture-elements card
Change app header text color for one view
Any way to use lovelace-card-mod to change the base icon color but then when the entity is turned on, have the state icon color go to whatever the default "on" color is?
šŸ”¹ fold-entity-row - Hide away stuff in entities cards
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
Adjust the top panel width and icon size
Lovelace: Mini Media Player
Lovelace: Bar Card
Flip door sensor "closed" state color?
Card-mod usage in vertical-stack-in-card
Card_mod help: styling image of picture-elements
Help with new Garage Door Card
Automations Headache
Mushroom Cards Card Mod Styling/Config Guide
Mushroom Cards Card Mod Styling/Config Guide
A little theming help needed
Custom UI - icon color change
Custom:fold-entity-row without entity icon
How to change the mdi icon color based on the state of a sensor
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
Open spaces between cards in Dwains Dasboard
Can't edit my own post in Community Guides section
How to combine two code sections?
Browser mod Popup style
Card-mod with entity-filter card - does not apply styles when entites show up
šŸ”¹ Card-mod - Super-charge your themes!
Interface: How do you stretch an Entities Card?
Last_changed in picture-elements
How to customize the badges at the top of the page?
Card-mod font size
Lovelace: Swiper card
Last_changed in picture-elements
Dynamic badge label (text) colours
Change icon-color in badge depending on state
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
šŸ”¹ slider-entity-row - Add sliders to entities cards
Area card background removal
Mushroom Cards Card Mod Styling/Config Guide
Mushroom Cards - Build a beautiful dashboard easily šŸ„ (Part 2)
Lovelace: mini graph card
Basic Dashboard Templating with Mushroom Template card

Continuation of the prev. post:


custom:flex-table-card
main post
How to style a header
Styling a row dependently on an entity’s state/attribute (or any other entity)


Map card
styling markers
display values on a Map card
animated markers
how to hide private data
show small pics for source device_trackers


custom:map-card
colorize an icon dynamically
how to hide private data
adding an additional info like a speed
show small pics for source device_trackers


custom:windrose-card
font-size for some labels


custom:shutter-card
disable controls


custom:hui-element
post


custom:restriction-card
main post
custom background
fix for a restriction card inside a Grid with square cells


Button card
highlight on hover


custom:button-card
One of rare cases when card-mod is needed for custom:button-card
Using button-card variables in jinja card-mod code
Adapting for sections


custom:tabbed-card
post
change an icon


custom: fluid-level-background-card
post


auto-entities
list of posts with styles


Sticky cards
post


Additional small title for any card with a title
post


How to scale an iframe content
post
post


custom:sun-card, custom:horizon-card
post


minimalistic-area-card
increase icon size


Other stuff
About these examples
Important notes about navigation
About navigation
About navigation #2
Combining ā€œ$:ā€ styles and ā€œnot $:ā€ styles
Using variables (especially after 2022.12)
Card for testing colors for binary_sensor entities (icons, history) (may be useful after 2022.12)
Using "::before" , "::after" & "content"
How to change card-mod styles for dark & light modes
How to let HA to choose a default style
How to combine icons
Possible errors when using card-mod
Conditional styles for different clients
Issue with re-defining a variable
Adding a color outline to icons
Showing an old HA logo (pre 2023.10)
How to add an icon to a card’s title
User-defined config options - to be used inside card-mod
config.entity + mod-card
Using yaml-anchors
Using global macros, also check another example
How to re-use card-mod code
Meaning of these ā€œ{%ā€ & ā€œ{%-ā€ things for card-mod code
Zero values for CSS theme variables
Overlaying cards
Comments inside card-mod code


Themes
for beginners: where to put card-mod theme code?, also here
Create a custom theme based on a default theme
ā€œ-yamlā€ vs ā€œw/o -yamlā€: schema
Using classes
Dynamic background: one, two

not card-mod but useful:
adding CSS vars to every theme
adding CSS vars to the default theme
more-info is always wide
wide columns on Device page
use more available area in Dev tools → Templates

Badges:
before 2024.8
column layout
sticky
scrollable

ā€œSidebarā€ view:
how to set a fixed width for a right sidebar
moving a right sidebar to the left
allow to scroll ā€œmainā€ area w/o scrolling a sidebar

Header:
styling tabs
moving a header to the bottom
hiding a header
how to change a header’s icon size
badges in a header
hide a ā€œsearchā€ button (also - hide all buttons & menu)
vivid selected & hovered tabs
remove ā€œopacityā€ effect

Sidebar: styling a sidebar + adding badges to a sidebar


Old post

изображение

type: entities
entities:
  - entity: input_boolean.test_boolean
    name: 'Checkbox: hidden'
    style:
      hui-generic-entity-row:
        ha-entity-toggle:
          $: |
            ha-switch {
             display: none;
            }
9 Likes

Thank you! I think I now understand why the many things I have tried all failed to work.

If the Entities card contains multiple entities, is there a way to make the style apply to all of them? Or does it have to be repeated for each one separately?