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

Letā€™s reset. After looking at your code, it appears some of it appears to have no effect on the card.

The code I provided first pinpointed the hour and minute fields, but we can target a level above with the same results.

Test out this version and let me know what needs adjusted or what you feel is missing.

type: entities
entities:
  - entity: input_datetime.test
    card_mod:
      style:
        ha-time-input $ ha-base-time-input $: |
          ha-textfield:nth-of-type(1) {
            width: 30px;
            }
          ha-textfield:nth-of-type(2) {
            width: 25px;
               }
        ha-date-input:
          $:
            ha-textfield $: |
              .mdc-text-field__input {
                align-self:center;
               }
        hui-generic-entity-row $: |
          state-badge {
           display: none;
           }
        hui-generic-entity-row ha-date-input $:
          ha-textfield $: |
            span#label {
             display: none;
             } 
        .: |
          :host {
            --mdc-text-field-fill-color: transparent;
            --mdc-select-fill-color: transparent;
            --mdc-text-field-idle-line-color: transparent;
            --mdc-text-field-hover-line-color: transparent;
            --mdc-select-idle-line-color: transparent;
            --mdc-select-hover-line-color: transparent;
            --mdc-theme-primary: transparent;
          }

Away from PC these days, will check in a week hopefully.

@LiQuid_cOOled No, itā€™s not workingā€¦ Iā€™ll try to make some changes in your code to see if I can fix somethingā€¦?
Thatā€™s what I get (I changed the color and the position of the previous cards, but they should be the same as beforeā€¦


The point I explained before is that the code is also used by other cards, this is why it has some code which is not used by this cardā€¦
Many thanks!

Got it. Now it works. Awesome.
I didnā€™t expect I have to use this ā€˜specialā€™ method.
Thank you very much for ur fast reply and hint!

Hello geniuses,
I once again need some help.

I have found these awesome animations and have implemented them succesfullyā€¦well oke fair enough the guide was so good I just to copy paste it and tweak a few simple things. So hats of to Mr Lopez

So I want the animation to activate when the power measured by the smart plug is >0

The smart plug is always on. So the on/off variable used usually in these cards is useless.

How do I change the on to a value of the sensor.

For testing purposes I have now typed in =0 since the washing machine is not running. When all works well I will change that to > 0.

Can someone help me please?

type: custom:mushroom-template-card
icon: mdi:washing-machine
icon_color: |-
  {{ 'grey' if (states("switch.wasmachine_smart_plug") == 'off') else
     'white' if (states("switch.wasmachine_smart_plug") == 'on') else
     '#FFC107' if (states(entity) == 'unavailable')
  }}
primary: "{{states(\"sensor.wasmachine_smart_plug_power\") | round(0)}} W"
entity: sensor.wasmachine_smart_plug_power
card_mod:
  style: |
    ha-state-icon {
      {% if is_state(config.entity, '=0') %}
        animation: shake 400ms ease-in-out infinite, drum 2s ease infinite;
        transform-origin: 50% 110%;
      {% else %}

      {% endif %}
    }
    @keyframes shake {
      0%, 100% { transform: translate(0, 0) rotate(0); }
      20%  { transform: translate(0.4px, -0.4px) rotate(-4deg); }
      40%  { transform: translate(-0.4px, 0.4px) rotate(4deg); }
      60%  { transform: translate(0.4px, 0.4px) rotate(-4deg); }
      80%  { transform: translate(-0.4px, -0.4px) rotate(4deg); }
    }
    @keyframes drum {
      50%  { clip-path: polygon(0 0, 0 100%, 35% 100%, 34% 68%, 60% 41%, 71% 56%, 65% 74%, 47% 79%, 32% 69%, 35% 100%, 100% 100%, 100% 0); }
    }

The end result should be that when the power shown is higher than zero the washing machine should shake like crazy. And then stop when the value is back to zero.

To help you guys out a little I have split the code to the bit where the problem is, specifically the if is state statement is where the help is needed.

card_mod:
  style: |
    ha-state-icon {
      {% if is_state(config.entity, '=0') %}
        animation: shake 400ms ease-in-out infinite, drum 2s ease infinite;
        transform-origin: 50% 110%;
      {% else %}

      {% endif %}
    }

@LiQuid_cOOled I was finally able to integrate your code in mine to solve some issues by adding the following line:

                ha-time-input $ ha-base-time-input $ ha-textfield $: |
                  .mdc-text-field {
                    height: 20px !important;
                  }

And at the end of your code I had to take out the following line, which had a strange effect on the menu list:

--mdc-theme-primary: transparent;

I donā€™t know if there is a better way to simplify the first part of the code to define the height of the text field, but the code works:

                ha-time-input $ ha-base-time-input $ ha-textfield $: |
                  .mdc-text-field {
                    height: 20px !important;
                  }

Many thanks!

1 Like

check if is numberā€¦

    ha-state-icon {
      {% set state = states(config.entity) %}
      {% if is_number(state) and state | float > 0 %}
        animation: shake 400ms ease-in-out infinite, drum 2s ease infinite;
        transform-origin: 50% 110%;
      {% endif %}
    }

Thank you so much. That did the trick.

Strangely enough when I wanted to test it and changed the > to = it did not work. But when I added another = to either the > or the = it worked.

ha-state-icon {
      {% set state = states(config.entity) %}
      {% if is_number(state) and state | float == 0 %}
        animation: shake 400ms ease-in-out infinite, drum 2s ease infinite;
        transform-origin: 50% 110%;
      {% endif %}
    }

For people wanting to steal the code, change the == 0 to a value you prefer with either > or < added.

@VietNgoc thank you so much, I can continue with the dashboard now. You are indeed a genius.

==
Compares two objects for equality.

!=
Compares two objects for inequality.

>
true if the left hand side is greater than the right hand side.

>=
true if the left hand side is greater or equal to the right hand side.

<
true if the left hand side is lower than the right hand side.

<=
true if the left hand side is lower or equal to the right hand side.


https://jinja.palletsprojects.com/en/stable/templates/#comparisons

1 Like

Hi there,

With the last update (2025.3) the following code stopped working:

    card_mod:
      style:
        ha-tile-icon$: |
          .shape { 
            border-radius: 15px !important;
            height: 50px !important;
            width: 50px !important;       
          } 

This changed the background round shape size:

You can see in the image that the shape is now too small for the icon.
I believe that this could be something that was deprecated.

Thanks.

Also The Background on tile card icon i canā€™t get rid of anymoreā€¦
(saw and looked for many solutions etc postsā€¦)
after last few updates the code below is not working anymoreā€¦

          style: |
            ha-card {
            border: none !important;
            }
            ha-tile-icon$: 
            .shape::before { 
            background-color: unset !important;
            }
            .shape {
            --mdc-icon-size: 20px;
            margin-top: -8px!important;
            }

it can be posted alotā€¦but im not sure about itā€¦
some help would be appreciatedā€¦
greetzā€¦T

basically we are having the same issueā€¦ after upgrading HA Core.

I have reinstalled the card-mod several times and I still have the same problem. The only way I got it working again was to do the HA restore to old version

@flakas @tadies Use this as an example.

type: tile
entity: fan.bedroom_fan
icon: mdi:fan
name: Example
hide_state: true
features_position: bottom
vertical: false
card_mod:
  style: |
    ha-card {
     --tile-color: dodgerblue !important;
               }
    ha-state-icon {
      color: orange !important;
               }

Remove icon background --tile-color: none !important;

Increase icon size with --mdc-icon-size: 50px important;

    ha-state-icon {
      color: orange !important;
      --mdc-icon-size: 50px important;
               }

2 Likes

Can you add your code or some context? Not just a picā€¦

Are you still on an older HA version

I just put the image with the code you gave.
Iā€™m currently on the latest version and thatā€™s why itā€™s not working.

Thank You LiQuid_cOOled!
Keep rocking sir!

Does anyone have any ideas to help me?

Yes, I know, my problem is the background shape (round) size (and even form, with borde-radius). Do you know the new syntax?
Thanks.

@pmgsrosa My post wasnā€™t in reply to your post.

Test this example out

type: tile
entity: sensor.home_assistant_supervisor_cpu_percent
features_position: bottom
vertical: false
card_mod:
  style: 
    ha-tile-icon $: |
      div.container {
      background: lightblue;
      height: 65px ;
      width: 65px;
      border-radius: 100%;
        }