DYNAMIC CSS IN LIGHTNING WEB COMPONENT
This post explains how to create CSS in lightning web components and also how to use the dynamic CSS in web components using the getter property
Let’s see an example. I have created a Lightning web component named dynamic style. It has a div and a checkbox. Our aim is to change the CSS class of div whenever the checkbox is checked.
dynamicStyle.html
Javascript
CSS: The same name as an LWC component and add .css in the file name for this example: dynamicStyle.css
The onchange handler is defined in the dynamicStyle.js file of the component. It is updating the value of the checkbox to a property defined. Along with it, the js file also has a getter to compute dynamically the CSS class of the div block defined in HTML.