CSS module scripts: `import` stylesheets like JavaScript modules

Windows

Windows
Microsoft and Google have collaborated to bring support for CSS module scripts to Chromium, and they will be available starting in Microsoft Edge and Chrome version 93. The new
Please, Log in or Register to view URLs content!
feature can be used to load CSS style sheets with import statements just like
Please, Log in or Register to view URLs content!
. The imported sheets are
Please, Log in or Register to view URLs content!
that can be directly applied to documents or
Please, Log in or Register to view URLs content!
like this:
import sheet from './styles.css' assert { type: 'css' };
document.adoptedStyleSheets = [sheet];
shadowRoot.adoptedStyleSheets = [sheet];
Loading a stylesheet without needing to create a style or link element can be more convenient and even
Please, Log in or Register to view URLs content!
than other ways of importing and applying CSS from JavaScript. CSS module scripts will be available starting in Microsoft Edge and Chrome version 93. Read more about the feature over at web.dev:
Please, Log in or Register to view URLs content!


Please, Log in or Register to view URLs content!
 

Users who are viewing this thread

Top