No comments yet

Design attributes in Lightning Web Components

In this post we will talk about how to create design attribute in lightning web components. We know how to create Design Attribute in lightning component. For Design Attribute we used to create <design:attribute tag in design file. But for Lightning web components we need to define the design attribute in Component Configuration File (XML) with<targetConfigs> tag. The component author need to defines the property in the component’s JavaScript class using the @api decorator.

What is Design Attributes in Lightning Web Components

We can use Design Attribute to make lightning web components attribute available to System Admin to edit Lightning App Builder or Community. So we can expose the component attribute in Lightning App Builder using design Attribute.

Design attributes in Lightning Web Components

Example of design attribute in Lightning web component

Here is example of design attribute in LWC.


    <lightning-card title={strTitle} icon-name="custom:custom14">
            <p>  Hello , {firstName} </p>
            <template if:true={showImage}>
                <img src={imgUrl} width="200" height="200"/>


import { LightningElement, api } from 'lwc';
export default class MyComponent extends LightningElement {
    @api firstName ='Amit';
    @api strTitle ='Welcome in Salesforce';
    @api showImage =false;
    @api imgUrl ='';


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


        <targetConfig targets="lightning__HomePage,lightning__RecordPage">
            <property name="strTitle" type="String" default="Welcome in Salesforce" label="Enter the title"/>
            <property name="showImage" type="Boolean" default="true" label="Show Image ?"/>
            <property name="imgUrl" type="String" default="" label="Enter Image URL"/>

Define the design Attribute in <property tag under <TargetConfig tag.

Demo of Design Attributes in LWC


Design attributes in Lightning Web Components allows you to build reusable and dynamic components. To set the design attributes in Lightning Web Component, we have to work on configuration file or component.js-meta.xml file.

Post a comment