+91 9216549878
we are committed to delivering innovative solutions that drive growth and add value to our clients. With a team of experienced professionals and a passion for excellence.

Follow us

LWC Grid Layouts_ Before and After

How to Remove Spacing Issues in LWC Grid Layouts

Images
Authored by
Inno Valley Works
Date Released
November 20, 2026
Comments
No Comments

Use case:

We have an LWC where we display the content dynamically in different columns. We usually use the slds-grid along with slds-size for each column, but the problem arises when the content is dynamic. Sometimes the size may be too small and in some cases, the size may be too large. To remove spacing issues, we need a solution by which the content takes only the required space.

Examples:

1.When the size is large:

remove-spacing-issues-in-lwc-01 How to Remove Spacing Issues in LWC Grid Layouts

Code:

<template>
   <div class="slds-box slds-theme_default">
       <div class="slds-text-title_bold slds-p-bottom_small">
           Example using slds size
       </div>
       <div class="slds-grid " title="Sample">
           <div class="slds-col slds-size_1-of-3">
               <span>This is a small sentence</span>
           </div>
           <div class="slds-col slds-size_1-of-3">
               <span>This is a small sentence</span>
           </div>
           <div class="slds-col slds-size_1-of-3">
               <span>This is a small sentence</span>
           </div>
       </div>
   </div>
</template>

2.When the size is too small:

remove-spacing-issues-in-lwc-02 How to Remove Spacing Issues in LWC Grid Layouts

Code:

<template>
   <div class="slds-box slds-theme_default">
       <div class="slds-text-title_bold slds-p-bottom_small">
           Example using slds size
       </div>
       <div class="slds-grid " title="Sample">
           <div class="slds-col slds-size_1-of-12">
               <span>This is a large sentence</span>
           </div>
           <div class="slds-col slds-size_1-of-12">
               <span>This is a large sentence</span>
           </div>
           <div class="slds-col slds-size_1-of-12">
               <span>This is a large sentence</span>
           </div>
       </div>
   </div>
</template>

Solution:

The alternative we have for this is to use slds-grow-none along with the column instead of slds-size. By using slds-grow-none, we let the column shrink to the width of the content inside of it.

remove-spacing-issues-in-lwc-03 How to Remove Spacing Issues in LWC Grid Layouts

Now we can see that the contents takes only the required space

Code:

<template>
   <div class="slds-box slds-theme_default">
       <div class="slds-text-title_bold slds-p-bottom_small">
           Example using slds grow none
       </div>
       <div class="slds-grid " title="Sample">
           <div class="slds-col slds-grow-none">
               <span>This is a small sentence</span>
           </div>
           <div class="slds-col slds-grow-none ">
               <span>Hai, this is a  large sentence</span>
           </div>
           <div class="slds-col slds-grow-none ">
               <span>Hello, this is a very large sentence</span>
           </div>
       </div>
   </div>
</template>

But yes, it looks a bit clumsy. Here comes our saviour gutters. Instead of giving separate padding for each column we could just use slds-gutters which would give equal space between columns that helps separate content.

Snapshots:

Desktop:

remove-spacing-issues-in-lwc-04 How to Remove Spacing Issues in LWC Grid Layouts

Mobile:

remove-spacing-issues-in-lwc-05 How to Remove Spacing Issues in LWC Grid Layouts

Code:

<template>
   <div class="slds-box slds-theme_default">
       <div class="slds-text-title_bold slds-p-bottom_small">
           Example using slds grow none
       </div>
       <div class="slds-grid slds-gutters_small" title="Sample">
           <div class="slds-col slds-grow-none">
               <span>This is a small sentence</span>
           </div>
           <div class="slds-col slds-grow-none ">
               <span>Hai, this is a  large sentence</span>
           </div>
           <div class="slds-col slds-grow-none ">
               <span>Hello, this is a very large sentence</span>
           </div>
       </div>
   </div>
</template>

Need help putting this into practice in your org? Our Salesforce custom development team can help you plan, build and support it.

Share:

Inno Valley Works delivers expert Salesforce consulting, implementation, and managed services to help businesses optimize processes, improve customer experiences, and drive digital growth.

Inno Valley Works LLC

1007 North Orange Street, 4th Floor, Suite 1382, Wilmington, DE 19801, USA.

Inno Valley Works (P) Ltd

No.25, AGT Business Park, Avinashi Road, Coimbatore 641014, India.

Inno Valley Works (P) Ltd

RMZ Millenia, Kodandarama Nagar, Perungudi, Chennai 600096, India.

INNO VALLEY WORKS L.L.C-FZ

Meydan Grandstand, 6th floor, Meydan Road, Nad Al Sheba, Dubai, U.A.E.