{"id":8331,"date":"2026-01-21T17:34:17","date_gmt":"2026-01-21T22:34:17","guid":{"rendered":"https:\/\/frontendmasters.com\/blog\/?p=8331"},"modified":"2026-01-21T17:34:19","modified_gmt":"2026-01-21T22:34:19","slug":"firefox-goes-css-modules","status":"publish","type":"post","link":"https:\/\/frontendmasters.com\/blog\/firefox-goes-css-modules\/","title":{"rendered":"Firefox Goes CSS Modules"},"content":{"rendered":"\n<p><a href=\"https:\/\/www.firefox.com\/en-US\/firefox\/147.0\/releasenotes\/\">Firefox 147 just came out<\/a>, and the flagship developer feature is clearly anchor positioning support, bringing that &#8220;to the baseline&#8221; as we&#8217;re supposed to say these days. That rules, but I&#8217;m also very hyped about CSS module scripts. <a href=\"https:\/\/frontendmasters.com\/blog\/architecture-through-component-colocation\/\">Remember<\/a>, they are a way of <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/JavaScript\/Reference\/Statements\/import\/with\">importing a stylesheet in JavaScript<\/a>, that is, the only decent way of handling CSS in the Shadow DOM. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-code-table\"><mark class='shcb-loc'><span><span class=\"hljs-keyword\">import<\/span> sheet <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">'.\/styles.css'<\/span> <span class=\"hljs-keyword\">with<\/span> { <span class=\"hljs-attr\">type<\/span>: <span class=\"hljs-string\">'css'<\/span> };\n<\/span><\/mark><span class='shcb-loc'><span>\n<\/span><\/span><span class='shcb-loc'><span><span class=\"hljs-class\"><span class=\"hljs-keyword\">class<\/span> <span class=\"hljs-title\">MyComponent<\/span> <span class=\"hljs-keyword\">extends<\/span> <span class=\"hljs-title\">HTMLElement<\/span> <\/span>{\n<\/span><\/span><span class='shcb-loc'><span>  <span class=\"hljs-keyword\">constructor<\/span>() {\n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">super<\/span>(); \n<\/span><\/span><span class='shcb-loc'><span>    <span class=\"hljs-keyword\">const<\/span> shadowRoot = <span class=\"hljs-keyword\">this<\/span>.attachShadow({ <span class=\"hljs-attr\">mode<\/span>: <span class=\"hljs-string\">'open'<\/span> });\n<\/span><\/span><mark class='shcb-loc'><span>    shadowRoot.adoptedStyleSheets = &#91;sheet];\n<\/span><\/mark><span class='shcb-loc'><span>  }\n<\/span><\/span><span class='shcb-loc'><span>}\n<\/span><\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>For clarity, this is sometimes called &#8220;CSS Module Scripts&#8221; and the import syntax is called &#8220;Import Attributes&#8221;. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Firefox 147 just came out, and the flagship developer feature is clearly anchor positioning support, bringing that &#8220;to the baseline&#8221; as we&#8217;re supposed to say these days. That rules, but I&#8217;m also very hyped about CSS module scripts. Remember, they are a way of importing a stylesheet in JavaScript, that is, the only decent way [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8332,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[29],"tags":[358,3,36],"class_list":["post-8331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-the-beat","tag-import-attributes","tag-javascript","tag-web-components"],"acf":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/frontendmasters.com\/blog\/wp-content\/uploads\/2026\/01\/pexels-photo-9259922.jpeg?fit=1040%2C1300&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/comments?post=8331"}],"version-history":[{"count":1,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8331\/revisions"}],"predecessor-version":[{"id":8333,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/posts\/8331\/revisions\/8333"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media\/8332"}],"wp:attachment":[{"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/media?parent=8331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/categories?post=8331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frontendmasters.com\/blog\/wp-json\/wp\/v2\/tags?post=8331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}