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

right, it was overlookedā€¦

Dont know why my Inspector background is so greyed, this is the default themeā€¦

this must be it then?

Iā€™m trying to change the padding-top of an auto-entities glance card and after trying many things Iā€™m a bit lost.

Hereā€™s my card:

  - type: custom:auto-entities
    card:
      type: glance
      show_state: true
      show_name: true
      show_icon: true
      state_color: false
    filter:
      include:
        - entity_id: sensor.afvalinfo_*
      exclude:
        - state: unknown
        - entity_id: sensor.afvalinfo_*_trash_type_today
        - entity_id: sensor.afvalinfo_*_trash_type_tomorrow
    sort:
      method: attribute
      attribute: days_until_collection_date
      numeric: true

Hereā€™s a screenshot from dev tools:

Changing padding-top in .entitites.no-header works in the browser but I canā€™t get it to work with style: or card_mod:
image

To answer myself, this works:

  - type: custom:auto-entities
    card:
      type: glance
      show_state: true
      show_name: true
      show_icon: true
      state_color: false
      card_mod:
        style: |
          ha-card .entities.no-header {
            padding-top: 9px;
          }
    filter:
      include:
        - entity_id: sensor.afvalinfo_*
      exclude:
        - state: unknown
        - entity_id: sensor.afvalinfo_*_trash_type_today
        - entity_id: sensor.afvalinfo_*_trash_type_tomorrow
    sort:
      method: attribute
      attribute: days_until_collection_date
      numeric: true
1 Like

what happens if you set it on the ha-card itself?


right, that is what I was trying to paste now :wink:
crossposted

1 Like

Yes. At least, is seams that the mod is still ingested at the right level. So I would wonder, if not only some !important would fix. Iā€™ll see after my update to 2025.1.

1 Like

Yeah, Please do.

Of course I did try to add the !important, but to no effect yet.

I sincerely hope we can get the simple mods back with a simple edit.
because right now, not even the main icon of the row is customized anymore

  - type: custom:multiple-entity-row
    entity: sensor.vijver_thermometer_temperature
    card_mod: !include /config/dashboard/card_mods/temp_color.yaml
    state_header: Temp
    name: Vijver

with the mod we set on entities before

theyā€™ve all changed, depending on whether they are standalone in an entities, under a fold, listed by auto-entities, listed by auto-entities in a fold, created via a decluttering-cardā€¦

Iā€™ve been able to catch a few using the entities card solution, but if you need individual mods, those are of no use obviously.

I am more than anxious to learn what you find

Yes, I can confirm that in the new version card mod is not added to the sub element under main entities cardā€¦

  • 2024.12.5 core


beta 2025

I am currently create a card for YT Music which is playing on my PC, but I canā€™t make the background transparent
Currently using following yaml

type: custom:button-card
entity: sensor.ytm_magic_pc
show_icon: false
show_name: false
layout: vertical
styles:
  card:
    - padding: 10px
    - border-radius: 10px
  grid:
    - grid-template-rows: auto auto 1fr
    - grid-template-columns: auto
custom_fields:
  thumbnail:
    card:
      type: picture
      image: |-
        [[[
          return entity.attributes.thumbnail[5].url
        ]]]
      aspect_ratio: 1/1
  info:
    card:
      type: vertical-stack
      cards:
        - type: markdown
          style: |
            ha-card {
              background: transparent !important;
            }
          content: |-
            <div style="text-align: center;">
              <span style="font-size: 1.2em; font-weight: bold;">šŸŽµ {{ states['sensor.ytm_magic_pc'].attributes.title }}</span><br>
              <span style="font-size: 1em; color: var(--secondary-text-color);">by {{ states['sensor.ytm_magic_pc'].attributes.author }}</span><br>
              <span style="font-size: 0.9em; color: var(--secondary-text-color);">Album: {{ states['sensor.ytm_magic_pc'].attributes.album }}</span><br>
            </div>
        - type: custom:timer-bar-card
          debug: false
          sync_issues: ignore
          active_state: "1"
          entities:
            - sensor.ytm_magic_pc
          duration:
            attribute: duration
            units: seconds
          remain_time:
            entity: sensor.ytm_magic_pc_remaining_time
            units: seconds
          layout: full_row
          text_width: 0px
custom_fields_order:
  - thumbnail
  - info

image

1st post ā†’ link at the bottom ā†’ mini-graph-card

1st post ā†’ link at the bottom ā†’ auto-entities

add thisā€¦

styles:
  card:
    - padding: 10px
    - border-radius: 10px
    - --card-background-color: transparent

I have a bad feeling about this (C) Obi-Wan

is it not possible to add a class to a mod-card ?

type: custom:mod-card
card_mod:
  class: applepie

Impossible currently.
Issue.

1 Like

I have forked the source repo and added the ha-card element to the source code, it seems that card-mod has been added as wellā€¦ i think someone can make a PR with this modificationā€¦

    render() {
        if (!this._hass || !this.config) return html``;
        if (!this.stateObj) return this.renderWarning();

        return html`
            <ha-card>
                <hui-generic-entity-row
                    .hass="${this._hass}"
                    .config="${this.config}"
                    .secondaryText="${this.renderSecondaryInfo()}"
                    .catchInteraction=${false}
                >
                    <div class="${this.config.column ? 'entities-column' : 'entities-row'}">
                        ${this.entities.map((entity) =>
                            this.renderEntity(entity.stateObj, entity)
                        )}${this.renderMainEntity()}
                    </div>
                </hui-generic-entity-row>
            </ha-card>
        `;
    }


You can try this source to see if the card mod will apply directly to the elementā€¦

test, it apply direct to the elementā€¦


the same way can use for custom foldā€¦

Donā€™t think that is is a generic solution to the new problem and a right way. This is still a row and not a card. And before there was no ha-card in this row either. The problem is mor in the generic row inside, I would think.

1 Like

Imho this is not a right thingā€¦
M-e-r is mainly a row which is supposed to be used inside Entities card.
That ā€œha-cardā€ element imho gives additional css properties to m-e-r, some of them may be not desired.
Although, when using m-e-r inside a decluttering-card, having own ā€œha-cardā€ makes styling a bit easier - we have to wrap m-e-r inside mod-card currently.

1 Like

Thanks that did the trick, but I do have white border lines, but using border-style: none wont remove themā€¦

this is var for border

--ha-card-border-width: 0;
1 Like

I have never used these custom cards before, I just thought it would work similar to adding a custom card to an entity card for example

type: entities
entities:
  - entity: sensor.outside_humidity
    type: custom:multiple-entity-row
    name: One entity
    secondary_info: last-changed
    entities:
      - sensor.outside_temperature
  - type: custom:mushroom-entity-card
    entity: person.anne_therese

Actually, it also adds a new custom element to the entities, where you can have a ha-cardā€¦ :man_shrugging: :man_shrugging: