<?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 Gabrielle von Koss on Medium]]></title>
        <description><![CDATA[Stories by Gabrielle von Koss on Medium]]></description>
        <link>https://medium.com/@frontendium?source=rss-324ab3ed29ee------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*jKNfWg54QG5tHtl1u24LTw.png</url>
            <title>Stories by Gabrielle von Koss on Medium</title>
            <link>https://medium.com/@frontendium?source=rss-324ab3ed29ee------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 16 May 2026 22:57:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@frontendium/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[CSS | The Cascade: Specificity]]></title>
            <link>https://medium.com/@frontendium/css-the-cascade-specificity-7f4ad354e58c?source=rss-324ab3ed29ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f4ad354e58c</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[specificity]]></category>
            <dc:creator><![CDATA[Gabrielle von Koss]]></dc:creator>
            <pubDate>Wed, 13 Dec 2017 15:55:01 GMT</pubDate>
            <atom:updated>2017-12-14T12:20:36.593Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: Should you need it, there is a </em><a href="#d34d"><em>mini glossary</em></a><em> at the end of this article.</em></p><p>Specificity is a wonderfully powerful, wildly frustrating and weirdly mystical mechanism in the CSS-sphere. With simpler applications and pages that have few elements in the markup, declaring styling can be relatively straight forward. But as the number of elements, classes and ids begins to grow, when you begin including stylistic libraries (or maybe even start working with Sass and its &amp; syntax), specificity can begin to get slightly confusing.</p><p>For starters, specificity is applied to a <em>ruleset</em> through a <em>selector. </em>There is a wide range of selectors, which I’ll dive into more deeply another time, but for now we’ll be referring to three of them as we use them in CSS—namely an element (e.g. &lt;div&gt;&lt;/div&gt; ), a .some-class (defined in markup a class=&quot;some-class&quot;) and #some-id (defined in markup as id=&quot;some-id&quot;).</p><p>Specificity is frequently explained as a point system, where an element is worth 1, a .class worth 10, an #id worth 100<a href="#e46d">*</a>.</p><p>According to that point system, the weight of specificity is placed on selectors based on an ascending value:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/06bccc823b655c5acd3f32d28f8001d4/href">https://medium.com/media/06bccc823b655c5acd3f32d28f8001d4/href</a></iframe><p>Up to here, all well and good. This is a really useful way of understanding how specificity gets determined by your selectors. The higher the total of the selector combinations, the more specific your ruleset and that is how particular styling gets chosen over others. Theoretically, you could link together as many selectors as you can be bothered to type out (as long as they exist in your markup), in order to be precise about the styling you want to apply to a particular element, and to be certain that that <em>is</em> the style that will be applied.</p><p>But! This logic implies that if you have enough elements in a selector, that selector will trump the specificity of a selector that is just a single .class.</p><p>Let’s assume we have 11 nested &lt;div&gt;&lt;/div&gt;s in our markup, and we decided (for the sake of curiosity because I can’t think of a real life application of this) write the following CSS.</p><pre>div div div div div div div div div div div div {<br>  height: 100px;<br>  width: 100px;<br>  background: thistle;<br>}</pre><p>This will certainly apply those styles to that last div. But what if our last div had a class called .special-class, and our CSS file looked like this:</p><pre>.special-class {<br>  background: rebeccapurple;<br>}</pre><pre>div div div div div div div div div div div div {<br>  height: 100px;<br>  width: 100px;<br>  background: thistle;<br>}</pre><p>You’ve got 11 divs there, so if each div is worth 1 and .special-class is worth 10. According to the math in the table above, you would expect the specificity of the 11 divs to be greater than the single .special-class .</p><p>But, it isn’t.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*eAJtVP7EfHYcQwgBNu1crA.png" /><figcaption>Such suspicious</figcaption></figure><p>Run this code pen and see for yourself!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fgvonkoss%2Fembed%2Fpreview%2FppvRBL%3Fheight%3D600%26slug-hash%3DppvRBL%26default-tabs%3Dhtml%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io%26embed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fgvonkoss%2Fpen%2FppvRBL&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fm.cdpn.io%2Fscreenshot-coming-soon-small.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/43556c5001b95ade175c2176b566508e/href">https://medium.com/media/43556c5001b95ade175c2176b566508e/href</a></iframe><p>It turns out that specificity is determined by those points being <em>concatenated</em>. Basically, the total values are strung up sequentially, they aren’t added up. So if we drew our point-system-table differently, the running total would look more like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71c420daa83807efdc86c45b2ef2937a/href">https://medium.com/media/71c420daa83807efdc86c45b2ef2937a/href</a></iframe><p>So when we create a selector with 11 divs , our total specificity points are going to be [0,0,11]. And a single class is [0,10,0], which is still more than that (because of its position in the scorecard, if you will).</p><p>Concatenation used to have a sort of memory limit. When that was reached, it would ‘spill over’ and surpass the specificity of the technically more valuable selector. But that was at the point where the specificity points rose above 255, so our scorecard of an element-only selector would have to look like [0,0,256] for it to be greater than [0,1,0]. Currently, this still seems to be the case for the Firefox and Internet Explorer rendering engines, but that memory limit is significantly higher with Chrome, Safari and Opera.</p><p>Nonetheless, as more styles and components start popping up on your page, and your selectors start looking far less simple than the examples above, it’s quite helpful to understand what the specificity <em>specifics</em> (ha) are, and how they play into the cascade.</p><p>Go forth and style! 💪</p><p><em>*In this explanation, we’ve excluded inline styles and </em><em>!important, which have higher specificity. An inline style </em><em>&lt;div style=&quot;background: hotpink&quot;&gt;&lt;/div&gt; is generally valued at ‘1000’, but a declaration with the </em><em>!important attribute can be used to trump that. However, the ultimate override is an </em><em>!important</em><strong><em> inside </em></strong><em>an inline style, but that’s a bad idea. Let’s not ever do that. Let’s try and avoid </em><em>!important in general. </em><a href="https://medium.com/p/ffbd5ff79d73"><em>I’ve talked about importance, too</em></a><em>, if you want to know more. </em><a href="#2b66"><em>Back up </em>↑</a>.</p><ul><li><a href="https://specificity.keegan.st/">Keegan Street Specificity Calculator</a></li><li><a href="https://developer.mozilla.org/en-US/docs/Learn/CSS/Introduction_to_CSS/Cascade_and_inheritance">MDN Specificity Docs</a></li></ul><p><a href="#98c0">^</a><strong> Glossary</strong> (sort of):</p><blockquote>declaration</blockquote><p>property: value</p><blockquote>declaration block</blockquote><pre>{<br>  property: value;<br>  property: value;<br>}</pre><blockquote>ruleset</blockquote><pre>selector {<br>  property: value;<br>  property: value;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f4ad354e58c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS | The Cascade: Importance]]></title>
            <link>https://medium.com/@frontendium/css-the-cascade-importance-ffbd5ff79d73?source=rss-324ab3ed29ee------2</link>
            <guid isPermaLink="false">https://medium.com/p/ffbd5ff79d73</guid>
            <category><![CDATA[importance]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Gabrielle von Koss]]></dc:creator>
            <pubDate>Wed, 08 Nov 2017 15:35:33 GMT</pubDate>
            <atom:updated>2017-12-02T10:44:31.902Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Note: Should you need it, there is a mini glossary at the end of this article, </em><a href="#a712"><em>here</em></a><em>.</em></p><p>In the world of CSS, the cascade looks like so:</p><blockquote><em>Importance &gt; Specificity &gt; Source Order</em></blockquote><p>Importance essentially determines which declaration block the stylesheet will display. The basic hierarchy of importance is determined by the <em>selectors</em> we use in our rulesets. From most to least important (at a basic level), we have:</p><p>#id &gt; .class&gt;element</p><p>The value of each selector is predefined by its natural specificity which also establishes the level of importance that a given selector has. And that final importance outranks the given specificity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/0*Jsj6xpbLHQ4P2w-0." /></figure><p>Translation: specificity and importance — despite their respective places in the hierarchy of things — work hand in hand. As a ruleset becomes more specific (as the selector rises in specificity), it also becomes more important. In which case it is fair to wonder why they are even separate concepts.</p><p>Turns out, there’s more to this importance business than meets the eye!</p><p>Importance involves some manoeuvring on behalf of the browser. For starters, browsers (user-agents, if you please), have to conform to a minimum number of stylistic features, defined by the CSS specs¹. Examples of that are &lt;div&gt; tags, &lt;a&gt; tags, &lt;p&gt;tags, &amp;c.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/288/1*_4kAUzI_WkRtzJV-TDrQhA.png" /></figure><p>Meaning that at the base level, browsers have to be able to display that minimum amount of styling, in the <strong>default </strong>stylesheet. So a simple HTML file opened straight in the browser, will look much like the example we have here. Blue underline for links, bold for &lt;strong&gt; elements, italics for &lt;em&gt; elements, Times New Roman (or similar) as the font-family for the &lt;body&gt;, so on.</p><p>In addition to the default stylesheet, the document’s author (ahem, developer) has sent the browser a stylesheet, and the user of the browser may have ported in their own stylesheet, for any number of reasons (a primary one being accessibility).</p><p>So how does importance get decided when there is more than one stylesheet to contend with‽ And what if there are !important declarations in different stylesheets?</p><p>Well, it looks a little like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/626915092b2337ed7905a4b44343ba2f/href">https://medium.com/media/626915092b2337ed7905a4b44343ba2f/href</a></iframe><p>The browser will parse the stylesheets in the order shown, and then reevaluate the chosen styles based on the !important declaration it finds in those stylesheets, and a combination of all of that (plus the bits mentioned in previous paragraphs) make up the cascade’s importance.</p><p>As we can see, !important is a bit of an odd character. It’s not a selector, but it is assigned to a declaration. Very broadly put, !important makes the declaration it is assigned to override all others, regardless of specificity. This causes certain declarations to be broken out of the cascade’s natural flow, and may interfere with settings that a user may need to change. It can really complicate the debugging process. <strong>Let’s steer clear of it where possible.</strong></p><p>Observe its behaviour — along with some specificity action — in this li’l gif:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/1*AuSIlweTJc6ZBe9xODU4TQ.gif" /></figure><p>Powerful stuff. Remember to use sparingly (or not at all? 😬).</p><p>After importance and specificity have been settled, the source order comes into play. It describes the literal order that the code has been written in, so if you’ve got something like –</p><pre>div {<br>  background: papayawhip;<br>}</pre><pre>div {<br>  background: lemonchiffon;<br>}</pre><p>– the background colour of your div will be lemonchiffon, because the file containing your styles is read top to bottom, and applies them accordingly. Which means that, in addition to how you have chosen to specify your rulesets, the <em>order</em> in which each ruleset is written will also affect how its styles will be displayed.</p><p>There are many factors at play while the outcome of your styling is being processed, but the more you know about it, the better equipped you will be to handle increasingly complex stylesheets.</p><p>Go forth and style 💪</p><ul><li>¹ <a href="https://www.w3.org/TR/CSS21/conform.html#conformance">CSS 2.1 Conformance Specs</a></li></ul><p><a href="#98c0">^</a><strong> Glossary</strong> (sort of):</p><blockquote>declaration</blockquote><p>property: value</p><blockquote>declaration block</blockquote><pre>{<br>  property: value;<br>  property: value;<br>}</pre><blockquote>ruleset</blockquote><pre>selector {<br>  property: value;<br>  property: value;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ffbd5ff79d73" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>