+0
Daily
18,037
stars
554
forks
210
watchers
54
prs
361
issues
0
releases
README
CSS Modules
A CSS Module is a CSS file where all class names and animation names are scoped locally by default. All URLs (url(...)) and @imports are in module request format (./xxx and ../xxx means relative, xxx and xxx/yyy means in modules folder, i.e. in node_modules).
CSS Modules compile to a low-level interchange format called ICSS (or Interoperable CSS) but are written like normal CSS files:
css
/ style.css /
.className {
color: green;
}
When importing a CSS Module from a JavaScript Module, it exports an object with all mappings from local names to global names.
js
import styles from './style.css';
element.innerHTML = '';
Table of Contents
- Get Started & Examples
- Naming
- Composition
- Local Scope
- History
- Pseudo Class Selectors
- Theming
Why CSS Modules?
- Local Scope Prevents Clashes: CSS Modules use local scope to avoid style conflicts across different project parts, allowing component-scoped styling.
- Clear Style Dependencies: Importing styles into their respective components clarifies which styles impact which areas, enhancing code readability and maintenance.
- Solves Global Scope Problems: CSS Modules prevent the common issue of styles in one file affecting the entire project by localizing styles to specific components.
- Boosts Reusability and Modularity: CSS Modules allow the same class names in different modules, promoting modular, reusable styling.Top issues
#187Future of CSS Modules47 comments · 2016-11-02#147Contextual Overrides / Theming Proposal43 comments · 2016-05-05#229Standardizing file extensions32 comments · 2017-04-23#193Optimizing css selector to properties relation25 comments · 2016-11-20#75best practices regarding media queries20 comments · 2015-10-22#264More insight on how :local and :global works in css modules19 comments · 2017-09-06#160Swappable themes using global17 comments · 2016-07-12#127Eliminating unused classes17 comments · 2016-03-22