Styling Components with CSS Modules

Learn to use CSS modules to style the components of the web page.

CSS modules are a mechanism for scoping CSS class names. The scoping happens as a build step rather than in the browser. In fact, CSS modules are already available in our app because Create React App has configured them in webpack.

Styling Header and App components

We are going to update the styles on the Header and App components to CSS modules in the following steps:

  1. Rename Header.css to Header.module.css and App.css to App.module.css. Create React App is configured to treat files ending with module.css as CSS modules.

  2. Open App.tsx and change the App.css import statement to the following:

Get hands-on with 1200+ tech skills courses.