lightning-card LWC

lightning-card LWC (Lightning Web Component)

lightning-card LWC (Lightning Web Component)

A lightning-card is used to apply a stylized container around a grouping of information. The information could be a single item or a group of items such as a related list.

Use the variant or class attributes to customize the styling.

A lightning-card contains a title, body, and footer. To style the card body, use the Lightning Design System helper classes.

When applying Lightning Design System classes or icons, check that they are available in the Lightning Design System release tied to your org. The latest Lightning Design System resources become available only when the new release is available in your org.

lightning-card LWC Example

We will create LWC component using lightning-card. We will get the following output

lightning-card LWC (Lightning Web Component)



        <h1 slot="title">Hello title</h1>
        <p class="slds-p-horizontal_small">This is body. You can have your content here</p>
        <div slot="actions">
            <lightning-button label="New" slot="actions"></lightning-button>
        <div slot="footer">
            <p>Contact Us SFDCPoint</p>


import { LightningElement } from 'lwc';
export default class LightningCardLWC extends LightningElement {}


<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="">

Now we can add this lwc component on home page.

  • Go to Home page
  • Click Setup (Gear Icon) and select Edit Page.
  • Under Custom Components, find your lightningCardLWC component and drag it on page.
  • Click Save and activate.

Usage Considerations

Icons are not available in Lightning Out, but they are available in Lightning Components for Visualforce and other experiences.

title is available as an attribute or a slot. Pass in the title as a slot if you want to pass in additional markup, such as making the title bold. Or use the title attribute if your title does not need extra formatting. Setting the title attribute overwrites the title slot.

There is one more practical example of using lightning-card, please refer to Lightning Spinner in LWC

For more details please refer to official link

For LWC lightning-card example please refer to this link

Permanent link to this article:

1 comment

    • rahul on September 19, 2020 at 10:31 pm
    • Reply


    I am getting this error while creating contact in lightning page, can u helo me

    This page has an error. You might just need to refresh it.
    Action failed: c:MyContactComp$controller$CreateNewContact [Cannot read property ‘setParams’ of undefined]
    Failing descriptor: {c:MyContactComp$controller$CreateNewContact}

    source code : Java script:

    CreateNewContact : function(component, event, helper) {
    var createContact = $A.get(“e.force:createRecord”);
    “entityApiName” : ‘Contact’,


Leave a Reply

Your email address will not be published.