Styling custom:tabbed-card
The card is documented here.
Some basic styling may be done by the card’s options, some - by card-mod.
Note (11.04.23): some stylings stopped working after 2023.4. Try this workaround to fix:
instead of:
card_mod:
style:
tabbed-card $: |
...... {
use this:
card_mod:
style:
tabbed-card:
$: |
...... {
Colored labels & icons (w/o conditions):
code
- type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
styles:
'--mdc-theme-primary': red
'--mdc-tab-text-label-color-default': red
'--mdc-tab-color-default': red
- card:
<<: *ref_card
attributes:
label: label 2
styles:
'--mdc-theme-primary': orange
'--mdc-tab-text-label-color-default': orange
'--mdc-tab-color-default': orange
- card:
<<: *ref_card
attributes:
label: label 2
styles:
'--mdc-theme-primary': green
'--mdc-tab-text-label-color-default': green
'--mdc-tab-color-default': green
Colored labels & icons (conditions may be added):
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(2) ha-icon $: |
ha-svg-icon {
color: orange;
}
mwc-tab:nth-child(2) $: |
.mdc-tab__text-label {
color: red !important;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Using standard theme variables for labels & icons:
code
type: custom:tabbed-card
styles:
'--mdc-theme-primary': unset
'--mdc-tab-text-label-color-default': var(--secondary-text-color)
'--mdc-tab-color-default': var(--paper-item-icon-color)
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Hilight icons on hover:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab:hover {
--mdc-theme-primary: red;
--mdc-tab-color-default: red;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-1-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-2-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-3-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-4-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-5-circle
Change an underline’s color:
code
- type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$:
mwc-tab-indicator $: |
.mdc-tab-indicator__content--underline {
border-color: red !important;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Colored tab’s background:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(1) $: |
.mdc-tab {
background: red !important;
}
mwc-tab:nth-child(2) $: |
.mdc-tab {
background: yellow !important;
}
mwc-tab:nth-child(3) $: |
.mdc-tab {
background: lightgreen !important;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<:: *ref_card
attributes:
label: label 3
Hilight an active tab’s background:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$: |
.mdc-tab {
background: yellow !important;
}
.mdc-tab--active {
background: lightgreen !important;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Tabs with background images:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab {
background-size: 100% 100%;
}
mwc-tab:nth-child(1) {
background-image: url("/local/images/test/9colors.jpg");
}
mwc-tab:nth-child(2) {
background-image: url("/local/images/test/blue_low_2.jpg");
}
mwc-tab:nth-child(3) {
background-image: url("/local/images/test/6colors.jpg");
}
card:
type: custom:tabbed-card
tabs:
- card: &ref_card
type: entities
entities:
- sun.sun
- card: *ref_card
- card: *ref_card
With inner padding:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$: |
.mdc-tab {
background-size: 100% 100% !important;
}
mwc-tab:nth-child(1) $: |
.mdc-tab {
background-image: url("/local/images/test/9colors.jpg") !important;
}
mwc-tab:nth-child(2) $: |
.mdc-tab {
background-image: url("/local/images/test/blue_low_2.jpg") !important;
}
mwc-tab:nth-child(3) $: |
.mdc-tab {
background-image: url("/local/images/test/6colors.jpg") !important;
}
.: |
mwc-tab {
padding: 4px;
}
card:
type: custom:tabbed-card
tabs:
- card: &ref_card
type: entities
entities:
- sun.sun
- card: *ref_card
- card: *ref_card
Align icons vertically with labels:
Not needed since v.0.4
Currently (v0.3.1) icons are misaligned; hopefully this will be fixed in the next revision (issue 1, issue 2).
The example contains 2 cards - styled (aligned) & default (misaligned).
code
type: vertical-stack
cards:
- type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab: |
ha-icon {
display: inline-flex;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: *ref_card
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
Narrow tabs w/o labels:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$: |
.mdc-tab {
min-width: var(--mdc-icon-size) !important;
}
.: |
tabbed-card {
--mdc-tab-horizontal-padding: 0px;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-1-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-2-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-3-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-4-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-5-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-6-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-7-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-8-circle
- card:
type: entities
entities:
- sun.sun
attributes:
icon: mdi:numeric-9-circle
Labels “caps lock off”:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$: |
.mdc-tab__text-label {
text-transform: none;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: Label 1
- card:
<<: *ref_card
attributes:
label: Label 2
- card:
<<: *ref_card
attributes:
label: Label 3
Labels: font-size, text wrapping:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(2) $: |
.mdc-tab__text-label {
font-size: 10px;
white-space: pre;
}
mwc-tab:
$: |
.mdc-tab__text-label {
text-transform: none;
}
.: |
mwc-tab ha-icon {
display: inline-flex;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: Label 1
- card:
<<: *ref_card
attributes:
label: |-
Some
long long label
!!!
- card:
<<: *ref_card
attributes:
label: Label 3
Hidden tab:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab:nth-of-type(2) {
display: none;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Disabled tab:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab:nth-of-type(2) {
pointer-events: none;
--mdc-tab-text-label-color-default: var(--disabled-color);
--mdc-tab-color-default: var(--disabled-color);
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
“Vivid” tabs:
These changes are also discussed here & here.
Below a variant for the HA 2023.2.3 default theme (border-radius: 12px
, borders, no shadows); this may be also rewritten to the “old pre 2022.11 style” (shadows, no borders).
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab {
background: var(--ha-card-background, var(--card-background-color, white) );
border-color: var(--ha-card-border-color, var(--divider-color, #e0e0e0) );
border-width: 1px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
border-style: solid;
overflow: hidden;
}
section article > * {
--ha-card-border-radius: 0px 0px 12px 12px;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Tabs on the bottom:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$:
mwc-tab-indicator $: |
.mdc-tab-indicator__content--underline {
align-self: flex-start !important;
}
.: |
tabbed-card {
display: flex;
flex-direction: column-reverse;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Same + “vivid” tabs:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$:
mwc-tab-indicator $: |
.mdc-tab-indicator__content--underline {
align-self: flex-start !important;
}
.: |
mwc-tab {
background: var(--ha-card-background, var(--card-background-color, white) );
border-color: var(--ha-card-border-color, var(--divider-color, #e0e0e0) );
border-width: 1px;
border-bottom-left-radius: 12px;
border-bottom-right-radius: 12px;
border-style: solid;
overflow: hidden;
}
section article > * {
--ha-card-border-radius: 12px 12px 0px 0px;
}
.: |
tabbed-card {
display: flex;
flex-direction: column-reverse;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
<<: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: label 1
- card:
<<: *ref_card
attributes:
label: label 2
- card:
<<: *ref_card
attributes:
label: label 3
Sticky “vivid” tabs:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $: |
mwc-tab-bar {
position: sticky;
position: -webkit-sticky;
top: 0; /*var(--header-height); */
display: block;
z-index: 999;
}
mwc-tab {
background: var(--ha-card-background, var(--card-background-color, white) );
border-color: var(--ha-card-border-color, var(--divider-color, #e0e0e0) );
border-width: 1px;
border-top-left-radius: 12px;
border-top-right-radius: 12px;
border-style: solid;
overflow: hidden;
}
section article > * {
--ha-card-border-radius: 0px 0px 12px 12px;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
type: entities
entities:
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
attributes:
label: label 1
- card:
type: entity
entity: sun.sun
attributes:
label: label 2
- card:
type: entity
entity: sun.sun
attributes:
label: label 3
Sticky “vivid” bottom tabs:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:
$:
mwc-tab-indicator $: |
.mdc-tab-indicator__content--underline {
align-self: flex-start !important;
}
.: |
mwc-tab-bar {
position: sticky;
position: -webkit-sticky;
bottom: 4px;
display: block;
z-index: 999;
}
mwc-tab {
background: var(--ha-card-background, var(--card-background-color, white) );
border-color: var(--ha-card-border-color, var(--divider-color, #e0e0e0) );
border-width: 1px;
border-bottom-left-radius: 12px;
border-bottom-right-radius: 12px;
border-style: solid;
overflow: hidden;
}
section article > * {
--ha-card-border-radius: 12px 12px 0px 0px;
}
.: |
tabbed-card {
display: flex;
flex-direction: column-reverse;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card:
type: entities
entities:
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
- sun.sun
attributes:
label: label 1
- card:
type: entity
entity: sun.sun
attributes:
label: label 2
- card:
type: entity
entity: sun.sun
attributes:
label: label 3
Additional info in tabs:
How to replace a tab’s name with some text:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(2) $: |
.mdc-tab__text-label {
font-size: 0px;
}
.mdc-tab__text-label:after {
content: "New info";
font-size: initial;
text-transform: none;
display: block;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: Label 1
- card: *ref_card
attributes:
label: dummy
- card: *ref_card
attributes:
label: Label 3
How to add a templated text for 2 or more tabs:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(n+2):
$: |
.mdc-tab__text-label {
font-size: 0px;
}
.mdc-tab__text-label:after {
font-size: 10px;
text-transform: none;
display: block;
}
mwc-tab:nth-child(2) $: |
.mdc-tab__text-label:after {
content: "Zone: {{states('zone.home')}}";
}
mwc-tab:nth-child(3) $: |
.mdc-tab__text-label:after {
content: "{{states('sun.sun')}}";
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: Label 1
- &ref_tab
card:
<<: *ref_card
attributes:
label: dummy
- *ref_tab
How to add a multiline text:
code
type: custom:mod-card
card_mod:
style:
tabbed-card $:
mwc-tab:nth-child(2) $: |
.mdc-tab__text-label {
font-size: 0px;
}
.mdc-tab__text-label:after {
content: "New info\A New info";
font-size: 8px;
text-transform: none;
white-space: pre;
display: block;
}
card:
type: custom:tabbed-card
attributes:
icon: mdi:circle
tabs:
- card: &ref_card
type: entities
entities:
- sun.sun
attributes:
label: Label 1
- card: *ref_card
attributes:
label: dummy
- card: *ref_card
attributes:
label: Label 3
Adding images instead of icons:
Removing “on hover” effect:
Tested in HA 2023.2.2, Chrome + Win10, iOS Companion app (iOS 15.7.3).
more examples