<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rashelle Kosiborod on Medium]]></title>
        <description><![CDATA[Stories by Rashelle Kosiborod on Medium]]></description>
        <link>https://medium.com/@rashellek?source=rss-ec1fafbde2b2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pks7ICcQ54SzMhVre2zl0Q.jpeg</url>
            <title>Stories by Rashelle Kosiborod on Medium</title>
            <link>https://medium.com/@rashellek?source=rss-ec1fafbde2b2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 04:28:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rashellek/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Stylable vs. CSS Modules]]></title>
            <link>https://medium.com/@rashellek/stylable-vs-css-modules-ba6b0169c66d?source=rss-ec1fafbde2b2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6b0169c66d</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[styled-components]]></category>
            <category><![CDATA[css-modules]]></category>
            <category><![CDATA[stylable]]></category>
            <dc:creator><![CDATA[Rashelle Kosiborod]]></dc:creator>
            <pubDate>Tue, 14 Aug 2018 09:26:03 GMT</pubDate>
            <atom:updated>2018-08-21T07:10:55.550Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*nlpGf4qDCCm7XPS_7q-UZA.png" /></figure><p>It seems that the debate over whether to use a <em>CSS preprocessor</em> has been discussed many times before. That conversation has largely turned from whether or not preprocessing is a good idea to which tool is best. If you work as a Front-End developer, you’ve probably heard of Sass, Less, and CSS modules and may have tried to implement them in your apps. But what do you know about <a href="https://stylable.io/">Stylable</a>?</p><p>Working as a FrontEnd developer, I find myself having a hard time writing and maintaining CSS across large projects that contain many reusable components. One of the challenges I routinely encounter is with style composition: reusing and overriding styles within a specific scope.</p><p>Using CSS Modules, I was able to prevent leaks and clashes, but I was having a hard time styling internal parts of the UI. To deal with this issue, we at Wix developed <strong>Stylable. </strong>It’s an open source library that scopes styles to components to prevent style leaks and clashes with other styles. Stylable exposes an internal API giving developers powerful capabilities.</p><p>Let’s compare the basic usage of both CSS Modules and Stylable, look at the problems they aim to solve, and explore the differences between their approaches.</p><h4>A story about a Stylable button component</h4><p>I created a Stylable button component using the <a href="https://stylable.io/docs/getting-started/install-configure">Stylable boilerplate</a>, and another button component using CSS Modules. I wanted to use a simple example to compare how Stylable enables styling components versus how CSS Modules does it. The examples given here are written with React, but you could use any other library.</p><p>* Every Stylable stylesheet has a reserved class called root that matches the root node of the component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MaIjc9UeT8U7PD3Y8FxKQA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*drJhxBVtA9LtlPad8rOIZw.png" /><figcaption>Check out the style import and the root class as it’s used in Stylable.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*xQWqtVq7YNGJCIghAMglEA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*9zLlFbMuDg0SSRjJBY2YrA.png" /><figcaption>I used the same basic CSS for both.</figcaption></figure><p>Next, I render the MyBtn component within a container component, which in my project is called App. The container component App has its own stylesheet app.st.css.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/374/1*zDhyMCuFdn2m1sPkgsZPjw.png" /></figure><h3>Composing</h3><p>I prefer to style my button a bit differently when it’s in the scope of the component container App. Remember I don’t want to change the original CSS because I’m going to reuse my button in other places.</p><p>Let the styling begin.</p><h4><strong>CSS Modules</strong></h4><p>When composing in CSS Modules, I use quite a straight forward approach to override the style of the component. I use <strong>composes</strong> and supply the selector to compose, and the path from where it comes.</p><p>Notice that I had to change the MyBtn component to accept the appBtn class name it gets from the container (as props). Turns out that’s not so scalable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*h32TL2_5G2myNIwuxWc6Ng.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*GFIa82DcJub55wTdSarMLg.png" /></figure><h4><strong>Stylable</strong></h4><p>Creating a Stylable button exposes an API that can be used by its parent components. Lets use this API for composing; think of an import function for React components, but in CSS.</p><p>To enable external styling, it’s recommended to pass the props className and data-*. This makes the component more “stylable”, and it’s easier to use the <a href="https://stylable.io/docs/references/root">‘root’ helper</a> Stylable provides.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cMDgB8Vogj4aNE-rZYd88A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZW9ZLWyz27fO-H1n6Am_MQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*2dB2nqVouDAh3eio4b0l1Q.png" /></figure><p>I import the style file with -st-from using a default name for future usage. Then, I am able to override it later using-st-extend.</p><h3>Customizing internal elements</h3><h4>CSS Modules</h4><p>Let’s try something a bit more complex. I want to change the button’s label in the App scope but face some complications using CSS Modules. It couldn’t find and style the internal part of the button component, the label of the button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EGVYZ19DfLypf607XvNcoQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/876/1*-8n31r2VTUybEq_G2ssKMw.png" /></figure><p>Because label is rendered within the MyBtn component, I cannot target it from the App stylesheet in a specific way. What I could do is bypass it and create this selector that catches the element:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*rxpIvkdITL7oNZ4H6EMXXA.png" /></figure><p>This is a bad practice because it forces me to understand and control the tree structure. It causes voodoo CSS in the future,<strong> but</strong> it does work for the label. However, after adding an icon to my label, some unwanted behavior occurred.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ELL1dvMSs1c-MxZ2NDRSNA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*1o9z42HbnrVA_0xqQsC3rQ.png" /><figcaption>The icon was affected by the CSS rule-set I created.</figcaption></figure><p>If you don’t want to place your style globally, then you have a problem. CSS Modules does not support complex composing, especially when rendering components or UI chunks from a library. To do that you have to write hacky CSS , like I did here.</p><h4>Stylable</h4><p>Stylable solves this issue. Remember how the MyBtn component’s Stylable API was already exposed using -st-default? This enables me to target the internal parts of the component that I imported. In this case, its label.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/872/1*_J-D_-319CQ1C7kRl2bxLA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*d9mdbyqWpFVukCFPCXcY5Q.png" /><figcaption>:: Targets only the label element without affecting the icon next to the label.</figcaption></figure><h3>Choosing Stylable</h3><p>We talked about some of the common scenarios we face when writing CSS, especially in big apps. Demonstrating how we approach these issues has shown some of the powerful ways that <a href="https://stylable.io/">Stylable</a> simplifies component styling.</p><p>If you are already familiar with the concepts of styling components, your learning curve to get familiar with Stylable is going to be pretty easy. You need to understand the importance of writing reusable, highly performant, styled components so you can utilize the many benefits you get from Stylable.</p><p>Although we covered how you can style components and override styles from the outside, we didn’t get a chance to dig into a lot of other features Stylable has to offer. These include style <a href="https://stylable.io/docs/references/pseudo-classes">states</a>, <a href="https://stylable.io/docs/references/mixins">mixins</a>, <a href="https://stylable.io/docs/references/pseudo-elements">pseudo selectors</a>, <a href="https://stylable.io/docs/references/variables">variables</a>, the list goes on. There’s a lot of ground to cover. Keep in mind that Stylable is a new library with a new agenda: to make working in CSS and compatible with a component world.</p><p>Checkout the <a href="https://stylable.io/">Stylable</a> docs and the <a href="https://github.com/wix/potato-bruce">Mr. Potato Bruce project</a> from GitHub. It’s a <a href="https://potatobruce.io/">demo application</a> showcasing the features and typed style API.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6b0169c66d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>