card
card groups related content and actions in a structured card surface.
XML Element |
|
|---|---|
Java Class |
|
Basics
The example combines card attributes and slots to present related information and actions:
<card id="card" width="30em"
themeNames="cover-media elevated outlined"
title="msg://card.title" subtitle="msg://card.subtitle">
<media>
<image resource="icons/jmix-background.png"/>
</media>
<headerPrefix>
<avatar image="icons/jmix-icon.png"/>
</headerPrefix>
<content>
<p text="msg://card.content.text"/>
</content>
<footer>
<button id="visitSiteButton" text="msg://visitSiteButton.text" icon="EXTERNAL_LINK" themeNames="primary"
iconAfterText="true"/>
<button id="learnMoreButton" text="msg://learnMoreButton.text" icon="QUESTION"
iconAfterText="true"/>
</footer>
</card>
Title and Subtitle
The title identifies the card, while the subtitle adds secondary text below it. Define them with the title and subtitle attributes or with nested elements of the same names. A nested element takes precedence over the corresponding attribute.
Neither value is rendered when a custom header is present.
Card with the title and subtitle attributes:
<card width="20em"
themeNames="elevated"
title="msg://card.title"
subtitle="msg://card.subtitle">
<content>
<p text="msg://card.content.text"/>
</content>
</card>
Card with nested title and subtitle elements:
<card width="20em"
themeNames="elevated">
<title>
<div>
<h2 text="msg://card.title"/>
<div text="msg://card.subtitle"
classNames="uppercase text-xs text-secondary"/>
</div>
</title>
<content>
<p text="msg://card.content.text"/>
</content>
</card>
<card width="20em"
title="msg://card.title"
themeNames="elevated">
<subtitle>
<div text="msg://card.subtitle"/>
</subtitle>
<content>
<p text="msg://card.content.text"/>
</content>
</card>
Custom Card Header
Use header to replace the predefined title and subtitle area with custom content. The headerPrefix and headerSuffix slots place components before and after that content.
<layout classNames="card-header">
<card id="card" width="30em"
themeNames="cover-media elevated outlined">
<headerPrefix>
<avatar image="icons/jmix-icon.png"/>
</headerPrefix>
<header>
<flexLayout flexDirection="COLUMN_REVERSE" classNames="header">
<h2 text="Jmix"/>
<div text="Modern Dev platform" classNames="subtitle"/>
</flexLayout>
</header>
<headerSuffix>
<span text="Fullstack" themeNames="badge success"/>
</headerSuffix>
</card>
</layout>
The headerSuffix slot commonly contains a status indicator or action.
Card Media
Specifies a visual component, such as an image, avatar, or icon, to be displayed as the card’s media.
To control how the media content is sized, apply the stretch-media or cover-media theme variants using the themeNames attribute.
<card width="20em"
themeNames="elevated, stretch-media"
title="msg://card.title"
subtitle="msg://card.subtitle">
<media>
<image resource="icons/headphones.png"/>
</media>
<content>
<p text="msg://card.content.text"/>
</content>
</card>
Card Content
Contains the main content of the card. This slot can hold any number of elements, providing flexibility for rich and complex layouts.
<card width="20em"
title="msg://card.title"
subtitle="msg://card.subtitle"
themeNames="outlined" titleHeadingLevel="4">
<content>
<p text="msg://card.content.text"/>
<vbox spacing="false" padding="false">
<p text="Color:"/>
<radioButtonGroup id="colorRBtn"
themeNames="vertical"/>
</vbox>
</content>
</card>
Card Footer
Defines the footer area of the card. This slot supports multiple elements, enabling flexible layouts for actions, status indicators, and supplementary information.
The footer follows the main content and stays at the bottom when the card has extra height.
<card width="20em"
themeNames="elevated"
title="msg://card.title"
subtitle="msg://card.subtitle" titleHeadingLevel="1">
<content>
<p text="msg://card.content.text"/>
</content>
<footer>
<span text=" Delivery: 1-2 days"
themeNames="badge, success"/>
<button id="buyButton"
text="Buy Now"
icon="vaadin:clock"
iconAfterText="true"/>
</footer>
</card>
Theme Variants
Use the themeNames attribute to set a component theme.
| Variant | Description | Supported By |
|---|---|---|
|
Applies a border around the card. |
Aura, Lumo |
|
Adds a shadow effect to create elevation. |
Aura, Lumo |
|
Arranges the card content horizontally. |
Aura, Lumo |
|
Scales the media content to fill its container. |
Aura, Lumo |
|
Crops the media content to cover its container. |
Aura, Lumo |
Attributes
Common attributes serve the same purpose for all components.
The following attributes are specific to card:
| Name | Description | Default |
|---|---|---|
Sets secondary text with predefined styling. See Title and Subtitle. |
— |
|
Sets the title text with predefined styling. See Title and Subtitle. |
— |
|
Sets the |
|
Handlers
| Name | Description |
|---|---|
Fires when the card is attached to the UI. |
|
Fires when the card is detached from the UI. |
Elements
A card can contain the title, subtitle, header, headerPrefix, headerSuffix, media, content, and footer elements described above.