# CSS Modules

CSS Modules is a CSS format and technique that locally scopes class and animation names, compiles to ICSS, and exports style mappings for JavaScript modules.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Improving site performance by shipping more CSS

DevFeed: [Improving site performance by shipping more CSS](<https://devfeed.tech/articles/improving-site-performance-by-shipping-more-css-60169.md>)

Original publisher: [Read original article](<https://github.blog/engineering/architecture-optimization/improving-site-performance-by-shipping-more-css/>)

Author: Josh Black

Published: 2026-09-25T15:00:00Z

Content type: article

Language: en

Sources: [GitHub Blog](<https://devfeed.tech/sources/github-engineering.md>), [GitHub Engineering](<https://devfeed.tech/sources/github.md>)

Topics: [CSS](<https://devfeed.tech/topics/css.md>), [CSS Modules](<https://devfeed.tech/topics/css-modules.md>), [GitHub](<https://devfeed.tech/topics/github.md>), [Design system](<https://devfeed.tech/topics/design-system.md>), [Server-side rendering](<https://devfeed.tech/topics/server-side-rendering.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [migration](<https://devfeed.tech/topics/migration.md>)

Tags: [architecture-optimization](<https://devfeed.tech/tags/architecture-optimization.md>), [automation](<https://devfeed.tech/tags/automation.md>), [css](<https://devfeed.tech/tags/css.md>), [css-in-js](<https://devfeed.tech/tags/css-in-js.md>), [design-system](<https://devfeed.tech/tags/design-system.md>), [design-systems](<https://devfeed.tech/tags/design-systems.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [github](<https://devfeed.tech/tags/github.md>), [js](<https://devfeed.tech/tags/js.md>), [migration](<https://devfeed.tech/tags/migration.md>), [performance](<https://devfeed.tech/tags/performance.md>), [performance-engineering](<https://devfeed.tech/tags/performance-engineering.md>), [primer](<https://devfeed.tech/tags/primer.md>), [scripting](<https://devfeed.tech/tags/scripting.md>), [server-side-rendering](<https://devfeed.tech/tags/server-side-rendering.md>), [software-engineer](<https://devfeed.tech/tags/software-engineer.md>), [user-experience](<https://devfeed.tech/tags/user-experience.md>)

### AI overview

GitHub's Primer team migrated components from CSS-in-JS to CSS Modules to address client-side style initialization, server-side rendering costs, and growing style-update overhead. CSS Modules preserved local class-name scoping while eliminating client and server runtime behavior by shipping stylesheets with the page HTML.

### Source excerpt

How we fully migrated github.com away from CSS-in-JS. The post Improving site performance by shipping more CSS appeared first on The GitHub Blog.

## Keep it contained!

DevFeed: [Keep it contained!](<https://devfeed.tech/articles/keep-it-contained-24565.md>)

Original publisher: [Read original article](<https://medium.com/bleeding-edge/enforcing-an-aspect-ratio-on-an-html-element-in-react-and-css-27a13241c3d4?source=rss----d8ebe85cdc0f---4>)

Author: Jesse Pinho

Published: 2018-11-15T16:15:40Z

Content type: tutorial

Language: en

Sources: [Bleeding Edge - Medium](<https://devfeed.tech/sources/bleeding-edge-medium.md>)

Topics: [CSS Modules](<https://devfeed.tech/topics/css-modules.md>), [Single-page application (SPA)](<https://devfeed.tech/topics/spa.md>), [Tutorial](<https://devfeed.tech/topics/tutorial.md>)

Tags: [aspect](<https://devfeed.tech/tags/aspect.md>), [css](<https://devfeed.tech/tags/css.md>), [css-in-js](<https://devfeed.tech/tags/css-in-js.md>), [react](<https://devfeed.tech/tags/react.md>)

### AI overview

The excerpt shows how to keep a responsive element at a fixed aspect ratio using the fact that percentage vertical padding is calculated from the containing block's width. For 16:9, set width to 100%, height to 0, and padding-bottom to 56.25%. Because the resulting container has zero height, embedded content will overflow or disappear if sized to 100% directly. The example fixes this with a relatively positioned outer container and an absolutely positioned inner wrapper, then sizes the iframe to 100%. A React component using styled-components packages the wrappers and accepts a width-to-height `ratio` prop, inverting it to calculate the padding percentage.

### Source excerpt

Enforcing an aspect ratio on an HTML element in React and CSSIllustration by Marta Pucci Frequently, it's necessary to set an aspect ratio on an element (like a <div> element), so that it will maintain its shape while scaling to any size. For example, you may be displaying a YouTube video in an iframe, and you want to make sure it shows up in 16:9. This is relatively simple to accomplish due to a CSS quirk. Per w3.org, when you set the CSS padding for a box: The percentage is calculated with respect to the width of the generated box's containing block, even for 'padding-top' and 'padding-bottom'. That is, if you have a 200 pixel-wide element and you set its padding-bottom to 50%, the bottom padding will be 100 pixels--regardless of the element's height!¹ We can take advantage of this fact to set an aspect ratio for an element, even as the window scales to any size. All we have to do is divide the height of our aspect ratio by its width, and then use that as the percentage for padding-bottom. For example, to enforce a 16:9 aspect ratio for an element, divide 9 by 16, which is 0.5625. Then, set the padding-bottom to 56.25%. Note that you also have to set the height to 0 to ensure that the padding constitutes the entirety of the element. Here's a full CSS class for a 16:9 container: .aspect-ratio--16x9 { width: 100%; height: 0; padding-bottom: 56.25%; }Working out the quirks One issue you might face here is that, while the 16:9 container takes up the right amount of space on the page, its height is set to 0. While this will work fine for displaying a background image cropped to a specific aspect ratio, it doesn't handle actual content well. Take the YouTube iframe from earlier: if you put an iframe into this container, it won't actually fit into the aspect ratio you've specified. By default, YouTube's embed code includes width and height attributes on the video player iframe, so it will stick out of your container element if it's too big. Meanwhile, if you style it with

## Setting up CSS Modules with React and Webpack

DevFeed: [Setting up CSS Modules with React and Webpack](<https://devfeed.tech/articles/setting-up-css-modules-with-react-and-webpack-52462.md>)

Original publisher: [Read original article](<http://www.jackfranklin.co.uk/blog/css-modules-webpack-react/>)

Published: 2016-07-18T00:00:00Z

Content type: tutorial

Language: en

Sources: [Jack Franklin](<https://devfeed.tech/sources/jack-franklin.md>)

Topics: [CSS Modules](<https://devfeed.tech/topics/css-modules.md>), [Webpack](<https://devfeed.tech/topics/webpack.md>), [React](<https://devfeed.tech/topics/react.md>), [CSS](<https://devfeed.tech/topics/css.md>), [Web Development](<https://devfeed.tech/topics/web-development.md>)

Tags: [css](<https://devfeed.tech/tags/css.md>), [modules](<https://devfeed.tech/tags/modules.md>), [react](<https://devfeed.tech/tags/react.md>), [webpack](<https://devfeed.tech/tags/webpack.md>)

### AI overview

CSS Modules scope component styles by transforming class names into unique names, which can reduce accidental clashes. The excerpt shows importing a component's CSS as a JavaScript module and enabling this with Webpack's `style-loader` and `css-loader`, with `modules: true` and a configurable `localIdentName`. In development, `style-loader` injects styles into the page, and the excerpt notes that the dev server updates them without a hard refresh. For production, `extract-text-webpack-plugin` extracts CSS into a stylesheet while retaining the CSS Modules transform. The article also presents `webpack-combine-loaders` as a way to group loader configuration, and notes that CSS loader settings are duplicated between development and production.

### Source excerpt

One of the biggest problems that developers face with CSS is that CSS is global. Each CSS class gets exposed globally and it's very easy to inadvertently break a piece of your site when editing or adding CSS for a new feature. In an era where many developers are building websites as components with a framework such as React, CSS is an even bigger problem. CSS Modules allow us to write scoped CSS, just like a variable in JavaScript or any other programming language. We can write CSS for a component and be certain that it won't leak into other components. You can also have confidence that adding a new component to your application won't interfere with any other components on the system. CSS Modules are a fantastic idea and play particularly nicely with React, but at the time of writing there isn't a good resource for getting started and setting up React, CSS Modules and Webpack to build everything correctly. In this article I'll show you how I took a React application and added CSS modules, which Webpack plugins I used for this, and an example of CSS modules in action. If you'd like to get this running yourself you'll find all the code available on GitHub. We'll also look at how we can generate a production bundle.css file which has all our CSS together and fully minified. The goal What we're aiming for is to be able to write CSS on a per component basis. That is, for each component we have a corresponding component.css file that will define the CSS for that component. For a component App.js, we also have app.css: .app p { color: blue; } And then in the component we can import this CSS file, as if it was a JavaScript module: import styles from './app.css'; Finally, we can reference the class name in our CSS file: <div className={styles.app}> <p>This text will be blue</p> </div> None of this works out of the box, but we'll use Webpack with a couple of additional loaders to get this working. The beauty is that the actual class name in the generated CSS file won't be .ap