Cards apply a container around a related grouping of information.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline
A lightning-card groups related information in a stylized container. The information can be a single item or a group of items such as a related list.
A lightning-card can contain a title, body, actions, and a footer. The title, actions, and footer are optional. You can also provide an icon in the header in front of the title.
Use the actions slot to pass content such as lightning-button-icon or lightning-button to perform an action when clicked. An action menu is shown on the top corner of the card opposite the title.
Here’s an example that passes in the title, actions, and footer as slots, and includes an icon.
1<template>2 <lightning-card variant="narrow" icon-name="standard:opportunity">3 <h1 slot="title">This is a title</h1>4 <h1>This is the body</h1>5 <div slot="actions">6 <lightning-button-icon7 icon-name="utility:down"8 ></lightning-button-icon>9 </div>10 <div slot="footer">11 <h6>This is the footer</h6>12 </div>13 </lightning-card>14</template>
title is available as an attribute or a slot. Pass in the title as a slot if you want to pass in markup, such as making the title bold.
Use the title attribute if your title doesn’t need extra formatting. Setting the title attribute overwrites the title slot. For more information, see Use Slots as Placeholders.
Design
lightning-card implements the cards blueprint in the Salesforce Lightning Design System (SLDS). The cards adapt to SLDS 1 or SLDS 2 styling based on the org’s theme or the container app that you use.
The card footer is optional and can contain an action to link to another page.
If using the card footer, we recommend using a View All link that takes a user to the object list view.
This example adds the View All link to the footer slot,
specifying the slds-card__footer-action class on the <a> tag. This class makes the footer’s click
target span the entire width of the card so you can click anywhere in the footer. The class isn’t required.
For a View All link, set the href value of the tag to a URL to take the user to the object list view.
To navigate to records, list views, and objects in Lightning Experience, Experience Builder sites, and the Salesforce mobile app, use the navigation service, lightning/navigation. For more information, see Basic Navigation.
Card with Illustration
A card can present an illustration in the card body when there’s no data to show. To maintain a consistent experience, use the lightning-illustration component.
1<lightning-card title="Tasks" icon-name="standard:task">2 <lightning-empty-state illustration-name="noresults:unknown" title="No new tasks">3 <p slot="description">Nothing needs your attention right now. Check back later.4 </p>5 </lightning-empty-state>6 </lightning-card>
Card with Loading Indicator
When you expect content to load with a noticeable delay, a loading indicator is helpful to notify a user of the delay. Use the lightning-spinner component to show a spinner on the card before the content loads.
A card is useful for showing a list of related records or contacts. By placing a lightning-datatable component inside the card, you can present tabular information within a card.
A card can show records by using tiles. To nest record data in a tile, use the lightning-tile component. Within a tile, show an icon by using the media slot. To make your content responsive, consider using the [lightning-layout component] and the SLDS grid system.
A nested card groups data within an object, such as account details with sections for contact info and recent activity.
1<lightning-card title="Outer Card Header" icon-name="standard:account">2 <lightning-button label="New" slot="actions"></lightning-button>3 <lightning-card title="Card Header" icon-name="standard:contact">4 <p class="slds-var-m-around_medium">This is a nested card with no styling (default)</p>5 </lightning-card>6 <p slot="footer">View All</p>7 </lightning-card>
Component Styling
Use a combination of icons and utility classes to customize the card style.
Icons
lightning-card displays an SLDS icon if you pass an icon name with the icon-name attribute. The icon is rendered using lightning-icon.
When applying SLDS classes or icons, check that they are available in the SLDS release tied to your org. The latest SLDS resources become available only when the new release is available in your org.
Component styling hooks provide CSS custom properties that use the --slds-c-* prefix and they change styling for specific elements or properties of a component. Component styling hooks are supported for SLDS 1 only. See the SLDS 1 component blueprints for available component styling hooks.
The headingLevel changes the 'aria-level' attribute value of <h2> tag in the markup for the card's title element. It can take values of (1, 2, 3, 4, 5, 6)
string | number
2
hide-header
Hides the header chunk of the card when set to `true`. Requires you to set the `label` attribute to supplement a non-rendered header. If `label` isn't set, you get a `console.warn` error.
boolean
icon-name
The Lightning Design System name of the icon. Specify the name in the format 'utility:down' where 'utility' is the category, and 'down' is the specific icon to be displayed. The icon is displayed in the header before the title.
string
label
Assistive label for the card header. Only shown if `hideHeader` attribute is set to `true`.
string
title
The title can include text, and is displayed in the header. To include additional markup or another component, use the title slot.
string
variant
The variant changes the appearance of the card. Accepted variants include base or narrow. This value defaults to base.
string
base
Slots
Name
Description
actions
Placeholder for actionable components, such as lightning-button or lightning-button-menu. Actions are displayed on the top corner of the card after the title.
default
Placeholder for your content in the card body.
footer
Placeholder for the card footer, which is displayed at the bottom of the card and is usually optional. For example, the footer can display a "View All" link to navigate to a list view.
title
Placeholder for the card title, which can be represented by a header or h1 element. The title is displayed at the top of the card, after the icon. Alternatively, use the title attribute if you don't need to pass in extra markup in your title.