Device Form Factor in LWC Salesforce

by Rijwan Mohmmed
0 comment

Hello folks, today we are going to discuss the Device Form Factor in LWC Salesforce. By using Form Factor in LWC we can configure components accordingly. Like, show different designs in mobile view and desktop view. By default, all LWC components are available for the desktop view but for the mobile view, we need to put the design attributes in the XML file with the supported type.

Also, check this: Field Set in Apex LWC Salesforce

Key Highlights :

  1. We can recognize the device and set the design accordingly.
  2. Form Factor necessary for mobile view salesforce view.
  3. We use import FORM_FACTOR from “@salesforce/client/formFactor”;


Code :

Here I create an LWC component with an LWC data table that is responsive according to the device.

formFactorLWC.HTML :

	<lightning-card title="Device Form Factor in LWC Salesforce">
		<div class="slds-var-m-around_medium">
			<b>You are viewing it from {deviceType} and Table below</b>
			<lightning-datatable key-field="id" data={data} columns={columns}


import { LightningElement } from "lwc";
import FORM_FACTOR from "@salesforce/client/formFactor";
const columns = [
    { label: 'Name', fieldName: 'name' },
    { label: 'Website', fieldName: 'website', type: 'url' },
    { label: 'Type', fieldName: 'type' }

export default class FormFactorLWC extends LightningElement {
    columns = columns;
    data = [
        { id: 1, name: 'Ankit', type: 'CS', website: '' },
        { id: 2, name: 'Rijwan', type: 'EC', website: '' },
        { id: 3, name: 'Himanshu', type: 'MEC', website: '' },

    connectedCallback() {

    handleFormFactor() {
        if (FORM_FACTOR === "Large") {
            this.deviceType = "Desktop/Laptop";
        } else if (FORM_FACTOR === "Medium") {
            this.deviceType = "Tablet";
        } else if (FORM_FACTOR === "Small") {
            this.deviceType = "Mobile";


<?xml version="1.0"?>
<LightningComponentBundle xmlns="">
        <targetConfig targets="lightning__RecordPage">
                <supportedFormFactor type="Small" />
				<supportedFormFactor type="Large" />

Output :


Reference :

  1. Form Factor

You may also like

Leave a Comment