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

I think you mean this? Showing the generic section of the mod is applied, and the detailed per entity section is not:

full code is this

HA card
type: entities
card_mod:
  style:
    hui-sensor-entity-row:
      $: |
        hui-generic-entity-row {
          height: 25px;
          padding: 0px 16px;
          border-radius: var(--ha-card-border-radius);
          border: 1px groove var(--primary-color);
        }
    .: |
      .card-content {
        background:
          {% set dark = is_state('binary_sensor.donker_thema','on') %}
          {% if not dark %} var(--ha-color)
          {% endif %};
      }
      ha-card {
        color: white;
        --card-mod-icon-color: white;
        --mdc-icon-size: 20px;
        font-weight: bold;
      }
entities:
  - type: custom:hui-element
    card_type: vertical-stack # required because hui-element does not support visibility
    cards:
      - visibility:
          - condition: state
            entity: binary_sensor.donker_thema
            state: 'on'
        image: /local/home-assistant/home-assistant-wordmark-color-on-dark.png
        <<: &picture
          type: picture
          entity: device_tracker.ha_main
          card_mod:
            style: |
              ha-card {
                box-shadow: none;
                background:
                {% set dark = is_state('binary_sensor.donker_thema','on') %}
                {% if not dark %} var(--ha-color)
                {% endif %};
              }
          tap_action:
            action: more-info
          hold_action:
            action: navigate
            navigation_path: /config/system
      - visibility:
          - condition: state
            entity: binary_sensor.donker_thema
            state: 'off'
        image: /local/home-assistant/home-assistant-wordmark-monochrome-on-dark.png
        <<: *picture

  - entity: sensor.last_boot
    format: datetime
    card_mod:
      style: |
        hui-generic-entity-row {
          border: none !important;
        }
  - entity: sensor.processor_use
    name: Cpu
    card_mod: &perc
      style: |
        hui-generic-entity-row {
          background:
            {% set perc = states(config.entity)|float(0) %}
            /*{% set rest = 100 - perc %}*/
            {% if perc >= 59 %} {% set bar = '255,0,0' %}
            {% elif perc >= 44 %} {% set bar = '128,0 0' %}
            {% elif perc >= 24 %} {% set bar = '255,165,0' %}
            {% elif perc >= 9 %} {% set bar = '0,100,0' %}
            {% else %} {% set bar = '0,128,0' %}
            {% endif %}
            /*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{perc}}%);*/
            linear-gradient(to right, rgb({{bar}},0.9) 0%, rgb({{bar}},0.6) {{perc}}%,
                                      rgba({{bar}},0.3){{perc}}%, rgba({{bar}},0.1) 100%);
        }

  - entity: sensor.processor_temperature
    name: Temp
    card_mod:
      style: |
        hui-generic-entity-row {
          background:
            {% set temp = states(config.entity)|float(0) %}
            /*{% set rest = 100 - temp %}*/
            {% if temp >= 85 %} {% set bar = '255,0,0' %}
            {% elif temp >= 75 %} {% set bar = '128,0,0' %}
            {% elif temp >= 65 %} {% set bar = '255,99,71' %}
            {% elif temp >= 55 %} {% set bar = '255,69,0' %}
            {% elif temp >= 45 %} {% set bar = '255,140,0' %}
            {% elif temp >= 35 %} {% set bar = '255,165,0' %}
            {% else %} {% set bar = '0,128,0' %}
            {% endif %}
            /*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{temp}}%);*/
            linear-gradient(to right, rgba({{bar}},0.9) 0%, rgba({{bar}},0.9) {{temp}}%,
                                      rgba({{bar}},0.6){{temp}}%, rgba({{bar}},0.2) 100%);
        }

  - entity: sensor.memory_use_percent
    name: Memory
    card_mod:
      style: |
        hui-generic-entity-row {
          background:
            {% set perc = states(config.entity)|float(0) %}
            /*{% set rest = 100 - perc %}*/
            {% if perc >= 85 %} {% set bar = '255,0,0' %}
            {% elif perc >= 75 %} {% set bar = '128,0,0' %}
            {% elif perc >= 60 %} {% set bar = '255,165,0' %}
            {% elif perc >= 50 %} {% set bar = '165,42,42' %}
            {% else %} {% set bar = '0,128,0' %}
            {% endif %}
            /*linear-gradient(to left,ivory {{rest}}%, {{bar}} {{perc}}%);*/
            linear-gradient(to right, rgba({{bar}},0.9) 0%, rgb({{bar}},0.9) {{perc}}%,
                                      rgba({{bar}},0.6){{perc}}%, rgba({{bar}},0.2) 100%);
        }

  - entity: sensor.disk_use_percent_home
    name: Disk
    card_mod: *perc

  - entity: sensor.swap_use_percent
    name: Swap
    card_mod:
      style: |
        hui-generic-entity-row {
          background:
            {% set swap = states(config.entity)|float(0) %}
            /*{% set rest = 1000 - swap %}*/
            /*{% set factor = 0.06 %}*/
            {% if swap >= 768 %} {% set bar = '255,0,0' %}
            {% elif swap >= 640 %} {% set bar = '255,215,0' %}
            {% else %} {% set bar = '50,205,50' %}
            {% endif %}
            /*linear-gradient(to left,ivory {{rest*factor}}%, {{bar}} {{swap*factor}}%);*/
            linear-gradient(to right, rgba({{bar}},0.9) 0%, rgba({{bar}},0.9) {{swap}}%,
                                      rgba({{bar}},0.1){{swap}}%, rgba({{bar}},0.1) 100%);
        }

current result (all is applied except the background color):

Something like this?

test:
  card-mod-theme: test
  background: url("{{ states('sensor.unsplash_background') }}")

like this

feest-background:
  card-mod-theme: feest-background
  card-mod-view: |
    {% set feest = is_state('binary_sensor.feest_alerts','on') %}
    hui-view {
      {% if feest %} background: repeat url('/local/images/balloons.png') fixed;
      {% endif %}
    }

or a template in that background

seizoen-background:
  card-mod-theme: seizoen-background
  card-mod-view: |
    hui-view {
      {% set seizoen = states('sensor.season_astronomical') %}
      background: repeat url('/local/season/{{seizoen}}_2.png') fixed;
    }

but please move this to the card-mod theme thread if you want to pursue

No, do not have this option.

Merry Christmas everyone! I need a bit of help :slight_smile:

Iā€™m trying to create a custom theme and use the card mod to style the .primary span inside a ha-tile-info component thatā€™s inside the ha-card component.

I can achieve this by editing the tile card directly and add the following:

type: tile
entity: switch.bedroom1_switch1_btn1
card_mod:
  style:
    ha-tile-info$: |
      .info .primary {
        color: red;
      }

How can achieve the same thing inside a theme? I tried creating a custom theme and adding the card-mod-card styles as shown bellow but itā€™s not working.

frontend:
  themes:
    custom:
      card-mod-theme: custom

      card-mod-card: |
        ha-card {
          ha-tile-info$: |
            .info .primary {
              color: red;
            }
        }

Please ask in card-mod-theme thread.

thanks. i reposted there

Good morning, Iā€™m trying to make a glance card with a larger font than standard. As others posted, when the font gets too large, the overflow setting cuts off the text. Also as mentioned here, I can manually deselect overflow: hidden in the inspector, but adding overflow: visible to the card has no effect. I also tried increasing the card size, but that doesnā€™t change the size at all in HA.

The previous overflow questions had no solution. Has anyone figured a way around this? Is there a better card (such as custom button card) that would work here? I want a large, color-coded temperature to let us know if itā€™s time to add wood to our outdoor wood boiler. Code and screenshot below:

show_name: false
show_icon: false
show_state: true
type: glance
entities:
  - entity: sensor.heatmor_temperature
    card_mod:
      style: |
        :host {
          color:
            {% if states(config.entity) | int <= 110 %} 
              blue
            {% elif states(config.entity) | int <= 120 %}
              yellow
            {% elif states(config.entity) | int >= 110 %}
              red
            {% endif %}
            ;
        }
title: HeatMor
card_mod:
  style: |
    ha-card {
    font-size: 3em;
    cardHeight: 900px; # no effect
    overflow: visible; # or overflow: visible !important, no effect
    }

image

Because cardHeight is not css propertyā€¦ :sweat_smile:}
use line-height: 100%;

Hello and Merry Christmas!

Is there any way to move the Temp Value lower???

I use line-height: 100%;

but I still want to move it a bit down

What exactly do you mean? Do you mean the state or the whole ha-card? Does line-height work for you?

sameā€¦
use

ine-height: 100%;

That did the trick, thank you! Now I need to go add wood since itā€™s in the yellow!
image

Another CSS selector questionā€¦

Iā€™m trying to make the grid width in the built-in grid card smaller. Iā€™ve narrowed down this value:

grid-template-columns: repeat(var(--grid-card-column-count,2),minmax(0,0.5fr)) !important;

As being what I need to set. The DOM navigation here seems simple, but I cannot get it to work.

div ID ā€œrootā€ is what I want, as you can see here:

Assuming that hui-grid-card is the base, the following code should work:

card_mod:
  style:
    hui-grid-card $: |
      #root {
        grid-template-columns: repeat(var(--grid-card-column-count,2),minmax(0,0.2fr)) !important;
        }

But it doesnā€™t. Iā€™ve tried .:, and just going for #root, and several other variations. It seems that it has to be either hui-grid-card, or #root. What else would the selector be?

[sneaky edit: Also happy holidays everyone :christmas_tree: , I swear I have a lifeā€¦this is what I do for fun. :smiley: ]

Maybe read the documentation first? :slight_smile:

1 Like

Congratulations on noticing something I missed. After a long time trying a bunch of different solutions and reading different threads for hours, itā€™s reassuring to be reminded that Iā€™m actually a moron who just needed to ā€œread the documentation firstā€.

But in a roundabout way, youā€™ve answered my question, so thank you for responding and helping.

Nobody said that you are a moron, that was your own conclusion. And yes, users must read Docs.

gettting back to the 2025.1 changes in the card mods, I can confirm that setting a generic background here:

type: entities
card_mod:
  style:
    hui-sensor-entity-row:
      $: |
        hui-generic-entity-row {
          height: 25px;
          padding: 0px 16px;
          border-radius: var(--ha-card-border-radius);
          border: 1px groove var(--primary-color);
          background: green;
        }

does work (albeit for all generic-entity-rowā€™s of course)

still figuring out why a mod on the individual row does notā€¦

and its getting worse:

          - entity: script.intercom_text_message
            name: Speel bericht
            card_mod:
              style: |
                :host {
                  --card-mod-icon-color:
                    {% set state = states(config.entity) %}
                    {{'var(--alert-color)' if state == 'on' else 'var(--success-color)'}};
                  --card-mod-icon:
                    mdi:{{'stop' if state == 'on' else 'play'}};
                }

has completely lost itā€™s functionalityā€¦ many more. like this:

          - entity: input_text.message
            name: Bericht
            card_mod:
              style:
                hui-generic-entity-row $: |
                  state-badge {
                    display: none;
                  }

o dear. weā€™re in for a surprise next weekā€¦

all we know is they ā€˜changed some attributesā€™ ā€¦

opened this issue in card_mod

cold this be relatedā€¦? Update hui-generic-entity-row.ts Ā· dhoeben/frontend@6e810d4 Ā· GitHub

But I really think you didnā€™t read the documentation, maybe you just copied the first example from the repoā€¦ then you modified the style according to yourself, regardless of how card_mod works. The creator of the plugin didnā€™t write the readme just for funā€¦ so, RTMFā€¦ :pray: