There are a few different options:
- Share CSS styles among LWC components (Summer 20' update):
Create a component that contains a CSS file and configuration file.
>custom.css
>custom.js-meta.xml
Then import it in the component you want to use the CSS file in.
/** myComponent.css **/
@import 'c/custom';
/* Define other style rules for myComponent here */
https://releasenotes.docs.salesforce.com/en-us/summer20/release-notes/rn_lwc_css_share.htm
- LWC - You can do it like above with loadStyle:
import { loadStyle } from 'lightning/platformResourceLoader';
renderedCallback() {
Promise.all([
loadStyle(this, resourcePath + '/custom.css');
])
}
- Loading static CSS resource into a custom theme - works for both LWC and Aura. This is a nice solution if you are still using both types of Web Components.
For aura:
<ltng:require styles="{!join(',',
$Resource + '/styles/custom.css',
)}" />