How to add dynamic css inline class add/remove, toggle and zoom-up/zoom-out style based on button click in Salesforce Lightning Web Component (LWC) | How to use inline class for the animation CSS style to show/hide and Toggle container based on button click in Salesforce LWC (Lightning Web Componenet)


Hey guys, today in this post we are going to learn about How to use inline class for the animation CSS style to show/hide and Toggle container based on button click in Salesforce LWC (Lightning Web Componenet).

Style Components with Lightning Design System

Salesforce Lightning Design System (SLDS) is a CSS framework that provides a look and feel that’s consistent with Lightning Experience. Use SLDS styles to give your custom Lightning web components a UI that is consistent with Salesforce, without having to reverse-engineer our styles. And best of all, it just works with Lightning components running in Lightning Experience and in the Salesforce mobile application. To know more details about Salesforce Lightning Design System (SLDS), Click Here..

Files we used to add inline class in Salesforce LWC β†’

lwcInlineStyleCss.html LWc HTML File Template HTML file to create dynamic css inline class add/remove based on button click in Salesforce Lightning Web Component (LWC)
lwcInlineStyleCss.js LWC JavaScript File It’s javascript actions functions to control the animation CSS style show/hide & Toggle container in Salesforce LWC
lwcInlineStyleCss.js-meta.xml XML Meta File It is used to where this lightning web component file you want to display as lightning__AppPage, lightning__RecordPage, lightning__HomePage.
lwcInlineStyleCss.css Style CSS It is used to creaet animation CSS style and alignment of the container. Lightning Application It is used for call the component and preview on browser.



Final Output β†’

inline class css animation in lwc --



You can download file directly from github by Click Here.


Other related post that would you like to learn in Salesforce

  • Find the below steps β–Ύ


Create Lightning Web Component HTML β†’

Step 1:- Create Lightning Web Component : lwcInlineStyleCss.html

SFDX:Lightning Web Component >> New >> lwcInlineStyleCss.html

lwcInlineStyleCss.html [Lightning Web Component HTML]

  1.   <template>
  2. <lightning-card>
  3.         <div style="padding: 20px; overflow:hidden;">
  4.                 <h3 class="slds-text-heading_medium"><lightning-icon icon-name="custom:custom101" size="small"></lightning-icon> <strong style="color:#270086; font-size:13px; margin-right:5px;"> How to move container Left, Right, Left and Bottom in Lightning Web Component (LWC) </strong></h3>
  5. <br/><br/>
  7.         <div class="menuLeftSide">
  8.                 <div class="spanInlineOver">                
  9.                         <span onclick={fadeTopAction}>Top</span>
  10.                         <span onclick={fadeBottomAction}>Bottom</span>
  11.                         <span onclick={fadeLeftAction}>Left</span>
  12.                         <span onclick={fadeInAction}>Right</span>
  13.                         <span onclick={fadeRightAction}>Fade Slide Right</span>
  14.                         <span onclick={fadeLeftSlideAction}>Fade Slide Left</span>                       
  15.                         <span onclick={fadeZoomAction}>Zoom-Up</span>
  17.                 </div>
  18.         </div>
  20.         <div class="menuRightSide">
  21.                 <div class={customCss}> 
  22.                         <div class="slideBox"><a href="" title="" target="_blank" rel="noopener noreferrer">
  23.                                 <img class="logoImg" alt="" src="" title=""/>
  24.                         </a> <strong><a href="" target="_blank" rel="noopener noreferrer"></a> </strong> is the place where you can learn step-by-step about Blog, Salesforce Lightning Component, Lightning Web Component (LWC), Visualforce, Technical of Computer Application, Salesforce Plugin, JavaScript, Jquery, CSS, Computer & Accessories, Software Configuration, Customization, Development and much <strong><a href="" target="_blank" rel="noopener noreferrer">more…</a></strong> </div>
  25.                 </div>
  26.         </div>
  29. </div>
  30. <br/><br/>
  31.         <!--Start RelatedTopics Section-->
  32. <div style="border:1px #ddd solid; padding:10px; background:#eee; margin:40px 0;">
  34.             <p data-aura-rendered-by="435:0"><img src="" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:16px; font-style:italic; display:inline-block; margin-right:5px;">Don't forget to check out:-</span><a href="" target="_blank" rel="noopener noreferrer" style="text-decoration:none;" data-aura-rendered-by="440:0">An easy way to learn step-by-step online free Salesforce tutorial, To know more Click  <span style="color:#ff8000; font-size:18px;" data-aura-rendered-by="442:0">Here..</span></a></strong></p>
  36.             <br/><br/>
  37.             <p data-aura-rendered-by="435:0"><img src="" width="25" height="25" style="vertical-align:top; margin-right:10px;" data-aura-rendered-by="436:0"><strong data-aura-rendered-by="437:0"><span style="font-size:17px; font-style:italic; display:inline-block; margin-right:5px; color:rgb(255 128 0);">You May Also Like β†’</span> </strong></p>
  38.             <div style="display:block; overflow:hidden;"> 
  39.                 <div style="width: 50%; float:left; display:inline-block">
  40.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  41.                         <li><a href="" target="_blank" rel="noopener noreferrer">How to get selected checkbox value in lwc</a></li>
  42.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to display account related contacts based on AccountId in lwc</a></li>
  43.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to create lightning datatable row actions in lwc</a></li>
  44.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to use if and else condition in lwc</a></li>
  45.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to display selected radio button value in lwc</a></li>
  46.                     </ul>
  47.             </div>
  49.             <div style="width: 50%; float:left; display:inline-block">
  50.                     <ul style="list-style-type: square; font-size: 16px; margin: 0 0 0 54px; padding: 0;"> 
  51.                         <li><a href="" target="_blank" rel="noopener noreferrer">display account related contacts based on account name in lwc</a></li>
  52.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to insert a record of account Using apex class in LWC</a></li>
  53.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to get picklist values dynamically in lwc</a></li>
  54.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to edit/save row dynamically in lightning component</a></li>
  55.                         <li><a href="" target="_blank" rel="noopener noreferrer">how to create tree grid with expanded/collapsed section for the entire row in LWC</a></li>
  56.                     </ul>
  57.                 </div>
  58.                <div style="clear:both;"></div> 
  59.                <br/>
  60.                 <div class="youtubeIcon">
  61.                     <a href="" target="_blank" rel="noopener noreferrer"><img src="" width="25" height="25" style="vertical-align:top; margin-right:10px;"/> <strong>TechW3web:-</strong> To know more, Use this <span style="color: #ff8000; font-weight: bold;">Link</span> </a>
  62.                 </div>
  63.     </div>
  65. </div>
  67.   <!--End RelatedTopics Section-->
  68. </lightning-card>      
  70. </template>


Create Lightning Web Component JavaScript β†’

Step 2:- Create Lightning Web Component : lwcInlineStyleCss.js

βœͺ The Big Announcement: -
As per student's demands, I re-opened my eBook of "Salesforce Tutorial" Limited-time huge discount offer Absolutely 50% Off.
I am thinking to give you discount offer occasion of Gandhi Jayanti for a powerful "Salesforce admin course" where you can Understand from Basic Concepts to advanced label in Salesforce.
πŸ‘‰ So Don't MISS it... (Access Right Now)
πŸ‘‰ Get Huge Discount Offer 50%: - Get eBook

SFDX:Lightning Web Component >> New >> lwcInlineStyleCss.js

lwcInlineStyleCss.js [LWC JavaScript File]

  1.    import { LightningElement } from 'lwc';
  3. export default class LwcInlineStyleCss extends LightningElement {
  6.     customCss = 'regularContentBox';
  10.     fadeTopAction(){           
  12.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');
  13.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');
  14.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn');    
  15.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');  
  16.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');  
  17.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  18.         this.template.querySelector('.regularContentBox').classList.add('fadeTop');
  19.     }
  21.     fadeBottomAction(){ 
  23.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');        
  24.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');
  25.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn');    
  26.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');  
  27.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');  
  28.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  29.         this.template.querySelector('.regularContentBox').classList.add('fadeBottom');
  30.     }
  32.     fadeLeftAction(){ 
  33.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');
  34.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');        
  35.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn');    
  36.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');  
  37.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');  
  38.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  39.         this.template.querySelector('.regularContentBox').classList.add('fadeleft');
  40.     }   
  42.     fadeInAction(){             
  43.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');
  44.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');
  45.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');           
  46.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');  
  47.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');  
  48.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  49.         this.template.querySelector('.regularContentBox').classList.add('fadeIn');
  50.     }
  52.     fadeRightAction(){      
  53.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');
  54.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');
  55.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');
  56.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn'); 
  57.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');  
  58.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  59.         this.template.querySelector('.regularContentBox').classList.add('fadeRight');
  60.     }
  61.     fadeLeftSlideAction(){      
  62.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');
  63.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');
  64.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');
  65.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn');    
  66.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');           
  67.         this.template.querySelector('.regularContentBox').classList.remove('zoomFadeIn'); 
  68.         this.template.querySelector('.regularContentBox').classList.add('fadeLeftSlide');
  69.     }
  71.     fadeZoomAction(){            
  72.         this.template.querySelector('.regularContentBox').classList.remove('fadeTop');
  73.         this.template.querySelector('.regularContentBox').classList.remove('fadeBottom');
  74.         this.template.querySelector('.regularContentBox').classList.remove('fadeleft');
  75.         this.template.querySelector('.regularContentBox').classList.remove('fadeIn');    
  76.         this.template.querySelector('.regularContentBox').classList.remove('fadeRight');  
  77.         this.template.querySelector('.regularContentBox').classList.remove('fadeLeftSlide');                  
  78.         this.template.querySelector('.regularContentBox').classList.toggle('zoomFadeIn');
  79.     }
  81. }


Create Lightning Web Component Meta XML β†’

Step 3:- Create Lightning Web Component : lwcInlineStyleCss.js-meta.xml

SFDX:Lightning Web Component >> New >> lwcInlineStyleCss.js-meta.xml

lwcInlineStyleCss.js-meta.xml [LWC Meta Data XML]

  1.    <?xml version="1.0" encoding="UTF-8"?>
  2. <LightningComponentBundle xmlns="">
  3.     <apiVersion>45.0</apiVersion>
  4.     <isExposed>true</isExposed>
  5.     <targets> 
  6.         <target>lightning__AppPage</target>
  7.         <target>lightning__RecordPage</target>
  8.         <target>lightning__HomePage</target>
  9.     </targets>
  10. </LightningComponentBundle>


Create Component Style CSS β†’

Step 4:- Create Lightning Web Component : lwcInlineStyleCss.css

SFDX:Lightning Web Component >> New >> lwcInlineStyleCss.css

lwcInlineStyleCss.css [Style CSS]

  1.    .menuLeftSide{width: 20%; float: left; margin-right: 2%px;}
  2. .menuRightSide{width: 70%; float: left;}
  4. .spanInlineOver{font-size: 17px; color: #333; margin-bottom: 15px; width: 150px; }
  5. .spanInlineOver span{width: 150px; color: #fff; background-image: linear-gradient(180deg, #00759f, #00c5cf); border: 1px #ccc solid; padding: 5px 10px; min-width:100px; text-align:center; display:block; margin: 0 0 15px 0;}
  6. .spanInlineOver span:hover{text-decoration: none; color: #ffff00; cursor: pointer;}  
  7. .spanInlineOver{text-decoration: none; background-image: linear-gradient(#00726e, #fff); color: #fff;}  
  10. .regularContentBox{ position:relative; overflow: hidden;}
  12. .regularContentBox .slideBox{  background-color:#ddd;  border: 1px #ccc solid; width: 450px; height: 250px; font-size: 16px; padding: 15px;}
  14. .regularContentBox.fadeTop .slideBox{ position: absolute; -webkit-transform: translateY(-500px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative; }
  15. .regularContentBox.fadeBottom .slideBox{position: absolute; -webkit-transform: translateY(0px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}
  16. .regularContentBox.fadeleft .slideBox{position: absolute; -webkit-transform: translateX(-500px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}
  17. .regularContentBox.fadeIn .slideBox{position: absolute; -webkit-transform: translateX(0px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}
  18. .regularContentBox.fadeRight .slideBox{position: absolute; -webkit-transform: translateX(1500px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}
  19. .regularContentBox.fadeLeftSlide .slideBox{position: absolute; -webkit-transform: translateX(0px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}
  20. .regularContentBox.zoomFadeIn .slideBox{font-size:22px; width: 700px; height: 500px; position: absolute; -webkit-transform: translateY(0px);   -webkit-transition:all 0.2s linear; opacity:1;  position: relative;}


Create Lightning Application β†’

Step 5:- Create Lightning Application :

From Developer Console >> File >> New >> Lightning Application [Component Application File]

  1.    <aura:application extends="force:slds">
  2.   <c:lwcInlineStyleCss/>
  3. </aura:application>

inline class css animation in lwc --

Further post that would you like to learn in Salesforce



FAQ (Frequently Asked Questions)

Can we add class to template in LWC?

LWC framework doesn't allow computed expressions in html markup to change CSS Class in Lightning Web Component dynamically but there are ways to do so. ... You can create a style sheet in the CSS file, and it's automatically applied to the corresponding HTML file.

How do you add a class in lightning component?

We use $A. util. toggleClass to add or remove a CSS style on a component or element during runtime. To retrieve the class name on a component, use component.

What does this template querySelector () return?

The querySelector() method returns the first element that matches a specified CSS selector(s) in the document. Template: To access elements rendered by a component, use the template property.

Related Topics | You May Also Like


Hi, This is Vijay Kumar behind the admin and founder of I am a senior software developer and working in MNC company from more than 8 years. I am great fan of technology, configuration, customization & development. Apart of this, I love to write about Blogging in spare time, Working on Mobile & Web application development, Salesforce lightning, Salesforce LWC and Salesforce Integration development in full time. [Read full bio] | | The Sitemap where you can find all published post on

Leave a Comment