.less and .module.less files in browser extensions.
When Less is a good fit
- You are migrating an existing Less-based web codebase.
- You want variables and nesting with low migration cost.
- You need module-scoped styles while keeping Less conventions.
Template examples
new-less

Usage with an existing extension
Add Less to an existing extension with the steps below.Installation
Install the required dependencies:Example usage in an HTML file
In extension pages (popup/options/new tab), import Less through your script entry:In a content_script file
Less modules in browser extensions
Scope class names locally with Less modules, just like CSS Modules. This prevents global style conflicts by default, which matters in extensions because content scripts run inside a host page’s CSS scope.content-less-modules

Using Less modules in an existing extension
To enable Less modules, rename your.less files to include .module.less. This enables automatic local scoping of class names.
Example usage
After renaming your Less file, you can import it into your scripts:React/Preact example usage
To use Less modules in React or Preact, import your Less module and apply styles as you would in any component:Vue example usage
In Vue, prefer single-file component (SFC) styles withlang="less" and module:
Svelte example usage
In Svelte, import Less module mappings and apply classes:Behavior notes
- In extension page contexts,
.module.lessexports class maps as expected. - In content scripts, Extension.js emits styles as CSS assets and injects them as stylesheets into the page.
- If the
lesspackage is not installed, Extension.js warns and copies the raw Less source into the output CSS, so those surfaces render unstyled until you install it yourself.
About the less post-install warning
With some package managers, installing a project that uses Less can surface a
notice that build scripts for less were not run (pnpm prints
Ignored build scripts: less and asks you to approve them). This is expected
and safe to ignore. Extension.js compiles Less through its own bundler
pipeline, so it does not rely on Less’s optional post-install step (which only
sets up Playwright inside Less’s own repository and is a no-op for consumers).
Your .less and .module.less files build and hot-reload the same either way.
Scaffolded projects do not ship a pnpm.ignoredBuiltDependencies key, so a
pnpm install of a Less template shows the notice like any other project. npm and
yarn run the script by default and print nothing.
If you hit the notice, you have two equivalent ways to silence it:
- Skip it (recommended): add
pnpm.ignoredBuiltDependencies: ["less"]to yourpackage.json. This acknowledges the script without running the no-op. - Run it: run
pnpm approve-buildsand selectless, or addpnpm.onlyBuiltDependencies: ["less"]. Harmless, just unnecessary.
Next steps
- Learn more about CSS Modules.
- Configure PostCSS in your extension.

