{"id":345756,"date":"2021-08-02T11:28:28","date_gmt":"2021-08-02T18:28:28","guid":{"rendered":"https:\/\/css-tricks.com\/?p=345756"},"modified":"2021-08-19T09:19:51","modified_gmt":"2021-08-19T16:19:51","slug":"css-modules-the-native-ones","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/css-modules-the-native-ones\/","title":{"rendered":"CSS Modules (The Native Ones)"},"content":{"rendered":"\n

They are actually called “CSS Module Scripts” and are a native browser feature, as opposed to the popular open-source project<\/a> that essentially does scoped styles by creating unique class name identifiers in both HTML and CSS. <\/p>\n\n\n\n

Native CSS Modules are a part of ES Modules (a lot like JSON modules<\/a> we recently covered):<\/p>\n\n\n\n

\/\/ Regular ES Modules\nimport React from \"https:\/\/cdn.skypack.dev\/react@17.0.1\";\n\n\/\/ Newfangled JSON Modules\nimport configData from '.\/config-data.json' assert { type: 'json' };\n\n\/\/ Newfangled CSS Modules\nimport styleSheet from \".\/styles.css\" assert { type: \"css\" };<\/code><\/pre>\n\n\n\n\n\n\n\n

I first saw this from Justin’s tweet:<\/p>\n\n\n\n

\n

JS and CSS modules with no build in sight!

With upcoming CSS modules, we'll soon have:

\u2705 JS modules
\u2705 Bare specifiers
\u2705 CSS modules
\u2705 Components
\u2705 Scoped styles

all built into the platform, no builds required, usable with `python -m SimpleHTTPServer 8000` \ud83d\ude0e
pic.twitter.com\/Q9zw1Pn1pF<\/a><\/p>— Justin Fagnani (@justinfagnani) June 11, 2021<\/a><\/blockquote>