Skip to main content
Extension.js supports CSS modules with zero configuration for module-style filenames (for example, styles.module.css). It routes them through the Rspack CSS pipeline. Class names stay locally scoped to the component that imported them.

When CSS modules are a good fit

  • You need local class scoping without adopting a full CSS-in-JS stack.
  • You share components across popup/options/new-tab surfaces.
  • You want predictable style ownership in larger extension codebases.

Template examples

content-css-modules

content-css-modules template screenshot Add locally scoped styles to content-script UI with minimal setup.
Repository: extension-js/examples/content-css-modules

Usage with an existing extension

To use CSS modules, name files with a module suffix:
  • *.module.css
  • *.module.scss
  • *.module.sass
  • *.module.less
Use the related language pages for Sass and Less setup requirements.

Usage example

After renaming your stylesheet, import and use it in your component:

How it works

Extension.js enables Rspack CSS support and handles module imports through the CSS module pipeline:
  • Default import style maps (import styles from "./x.module.css")
  • Rspack generates scoped class names through its CSS module pipeline
  • Module class exports work directly in JS/TS/TSX files
In extension page contexts (for example, popup/options/new tab), module imports produce unique, scoped class names as expected.

Content script note

Content scripts get the same treatment as extension pages. Rspack generates scoped class names, exports them to your JavaScript, and Extension.js registers the emitted stylesheet in the manifest content_scripts[].css entry, and in web_accessible_resources so it can also be injected into a shadow root. Import the class names you need and apply them:
See the content-css-modules template above for a working example.

React/Preact example usage

For React or Preact, you can import and use the CSS module in the component like this:

Vue example usage

In Vue, you can use module classes from single-file component (SFC) styles:

Svelte example usage

In Svelte, import module mappings and apply class names:

Best practices

  • Keep module styles close to components (Component.module.css) for easier ownership.
  • Use :global(...) sparingly and only for intentional global overrides.
  • Prefer module styles for extension pages and framework components where class mapping is explicit.

Next steps

Video walkthrough