Scoped Styles with CSS Modules
CSS Modules is the name for an approach where individual CSS files are linked to specific JavaScript files and the components defined in those files. This link is established by transforming CSS class names, such that every JavaScript file receives its own, unique CSS class names. This transformation is performed automatically as part of the code build workflow. Therefore, a given project setup must support CSS Modules by performing the described CSS class name transformation. Projects created via create-react-app
support CSS Modules by default.
CSS Modules are enabled and used by naming CSS files in a very specific and clearly defined way: <anything>.module.css
. <anything>
is any value of your choosing, but the .module
part in front of the file extension is required as it signals (to the project build workflow) that this CSS file should be transformed according to the CSS Modules approach.
Therefore, CSS files named like this must be...