<?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 Mariano Miguel on Medium]]></title>
        <description><![CDATA[Stories by Mariano Miguel on Medium]]></description>
        <link>https://medium.com/@marianojmiguel?source=rss-eec132d5a67b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5Z2EZD0_DX972jTqG2XuDg.jpeg</url>
            <title>Stories by Mariano Miguel on Medium</title>
            <link>https://medium.com/@marianojmiguel?source=rss-eec132d5a67b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 22:04:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@marianojmiguel/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[Fluid Typography with SASS / CSS Variables]]></title>
            <link>https://medium.com/mariano-css/front-end-quick-tip-fluid-typography-with-sass-css-variables-56665a35ce50?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/56665a35ce50</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-design]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[typography]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Sun, 18 Dec 2016 22:00:48 GMT</pubDate>
            <atom:updated>2018-03-23T20:37:01.882Z</atom:updated>
            <content:encoded><![CDATA[<p>About 9 days ago, <a href="http://clagnut.com/">Richard Rutter</a> wrote about a <a href="https://24ways.org/2016/responsive-display-text/#fn:2">technique to create fluid typography in CSS using calc()</a>. I liked the approach for its simplicity vs <a href="https://www.smashingmagazine.com/2016/05/fluid-typography/">other approaches</a> I had seen before.</p><p>Richard proposes a simple, hybrid method that uses both rems and viewport units to calculate font sizes. For example:</p><pre>h2 {<br>    font-size: calc(0.5rem + 2.5vmin);<br>}</pre><p>So, assuming a rem base of 16px, for a 320px wide screen, the font-size will be:</p><pre>(0.5 × 16) + (320 × 0.025) = 8 + 8 = 16px</pre><p>For a 768 px wide screen, the font-size will compute to 27px:</p><pre>(0.5 × 16) + (768 × 0.025) = 8 + 19 = 27px</pre><h3>Reversing the approach</h3><p>The first thing I wanted to do was to reverse this approach, creating a function where I could provide a desired font size at a particular breakpoint (in this case a desktop breakpoint), and then let calc() handle the rest.</p><p>I’m awful at math, but thankfully this turned out to be pretty easy.</p><p>Let’s say I want my h1 to be 48px when the viewport is 1200px wide.</p><p>Using Richard’s formula, we know that:</p><pre>(0.5 × 16) + (1200 × $ratio) = 48</pre><pre>8 + (1200 x $ratio) = 48</pre><p>All we have to do now is figure out that growth ratio:</p><pre>8 + (1200 x $ratio) = 48</pre><pre>(1200 x $ratio) = 48 - 8</pre><pre>(1200 x $ratio) = 40</pre><pre>$ratio = 40 / 1200</pre><pre>$ratio = 0.03333</pre><p>Putting it all together, that means:</p><pre>(0.5 × 16) + (1200 × 0.03333) = 8 + 39.99 = 47.99px</pre><p>The next step for me was to replace vmin units with vw units, as I found them to be more reliable for what I needed. The end result is:</p><pre>h1 {<br>  font-size: calc(0.5rem + 3.3vw);<br>}</pre><p>Eventually, I also decided that using 0.5rem as a base gave me very small font sizes in narrow screens, so I ended bumping that up to 1rem .</p><h3>Shut up and give me the mixin</h3><p>I put together both a SCSS and a CSS variables version. They could probably be improved in a couple ways, but they are good enough examples of what you can achieve. You can grab them from CodePen:</p><ul><li><a href="https://codepen.io/marianojmiguel/pen/vybGZq">Simple Fluid Typography: SCSS version</a></li><li><a href="http://codepen.io/marianojmiguel/pen/mOvPMb?editors=1100">Simple Fluid Typography: CSS variables version</a></li></ul><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56665a35ce50" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/front-end-quick-tip-fluid-typography-with-sass-css-variables-56665a35ce50">Fluid Typography with SASS / CSS Variables</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Enforcing Accessible States in CSS]]></title>
            <link>https://medium.com/mariano-css/enforcing-accessible-states-in-css-d8142789b99e?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8142789b99e</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[web-design]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Mon, 12 Dec 2016 13:57:13 GMT</pubDate>
            <atom:updated>2018-03-23T20:51:28.061Z</atom:updated>
            <content:encoded><![CDATA[<p>Historically, I’ve been a fan of using state classes, prefixed with a namespace like .is- or.has- . And I’ve seen a lot of developers go this route as well.</p><p>However, the more I work with state classes the more I realize they often incur in a rather pernicious form of code redundancy.</p><p>To understand this, let’s take a look at an obvious example of redundancy in code:</p><pre>&lt;!-- Hey! Just so you know, this button is disabled. Also, this comment is unnecessary, stating the obvious and adding another thing to be maintained w/ no benefits --&gt;</pre><pre>&lt;button class=&quot;c-button&quot; disabled&gt;Hello&lt;/button&gt;</pre><p>Now take this example:</p><pre>&lt;button class=&quot;c-button is-disabled&quot; disabled&gt;Hello&lt;/button&gt;</pre><p>Both of these examples are cases of redundancy, only #2 is much more subtle. Here’s why:</p><p>You’ll still need the disabled attribute to properly indicate your button’s state to assistive technology. So, in this case, .is-disabled is redundant and introduces an extra step in our code (we have to toggle both the attribute and the class) without any added benefits.</p><p>What I’m proposing is that we use ARIA states and HTML5 state attributes as styling hooks for our UI States. This is not new or revolutionary, and has been with us for a long time:</p><pre>.c-input {<br>  color: black;<br>}</pre><pre>.c-input[aria-invalid=&quot;true&quot;] {<br>  color: red;<br>}</pre><p>Using the attribute as a styling hook won’t do any harm in terms of specificity since attribute selectors (e.g: [disabled] or [aria-disabled]) carry the same specificity as a normal class.</p><p>However, there’s a lot to win from this approach, namely:</p><ul><li>Less code to maintain: an attribute + a class vs just an attribute.</li><li>Enforced accessibility: the state and the styles that communicate that state become tightly coupled, preventing developers from overlooking and forgetting about a11y.</li></ul><p>Yes, this will probably cause a few headaches, but I’m willing to take that trade-off for the sake of keeping the UI accessible.</p><h3>Here’s a small list of ARIA States to get you started</h3><p>Taken from Steve Faulkner’s post <a href="https://www.paciellogroup.com/blog/2010/04/html5-and-the-myth-of-wai-aria-redundance/">“HTML5 and the myth of WAI-ARIA redundance”</a>:</p><ul><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-busy">aria-busy:</a> Indicates whether an element, and its subtree, are currently being updated.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-checked">aria-checked:</a> Indicates the current “checked” state of checkboxes, radio buttons, and other widgets. Also see aria-pressed and aria-selected.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-disabled">aria-disabled:</a> Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. Also see aria-hidden and aria-readonly.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-expanded">aria-expanded:</a> Indicates whether an expandable/collapsible group of elements is currently expanded or collapsed.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-grabbed">aria-grabbed:</a> Indicates an element’s “grabbed” state in a drag-and-drop operation.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-hidden">aria-hidden:</a> Indicates that the element is not visible or perceivable to any user. Also see aria-disabled.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-invalid">aria-invalid:</a> Indicates the entered value does not conform to the format expected by the application.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-pressed">aria-pressed:</a> Indicates the current “pressed” state of toggle buttons. Also see aria-checked and aria-selected.</li><li><a href="http://www.w3.org/WAI/PF/aria/states_and_properties#aria-selected">aria-selected:</a> Indicates the current “selected” state of various widgets. Also see aria-checked and aria-pressed.</li></ul><h3>Final thoughts: Best practices vs “best practices”</h3><p>It’s never the fault of the methodology, but of the developers. Just because you could do something in a certain way (e.g: Making a &lt;div&gt;look and work like a button), doesn’t mean you should.</p><p>However, I think there is a distinction to be made between best practices that make for better collaboration and more maintainable code, versus “best practices” that are there just to allow developers to get away with doing a half-assed job.</p><p>The web calls for a more sensible approach.</p><p>I believe this to be one of those cases where the reward of a more accessible UI is much bigger than the trade-offs. Even if it means forcing developers to learn about accessibility in order to collaborate. Because they should do that at some point anyway.</p><h3>Further reading</h3><ul><li><a href="http://smashingmagazine.com/2016/11/css-inheritance-cascade-global-scope-new-old-worst-best-friends/">CSS Inheritance, The Cascade And Global Scope: Your New Old Worst Best Friends - Smashing Magazine</a></li><li><a href="https://benfrain.com/dealing-with-state-in-ecss-web-applications-using-aria/">Dealing with state in ECSS web applications using ARIA</a></li><li><a href="https://www.paciellogroup.com/blog/2010/04/html5-and-the-myth-of-wai-aria-redundance/">HTML5 and the myth of WAI-ARIA redundance</a></li></ul><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8142789b99e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/enforcing-accessible-states-in-css-d8142789b99e">Enforcing Accessible States in CSS</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stateful Theming with CSS Custom Properties]]></title>
            <link>https://medium.com/mariano-css/stateful-theming-css-custom-properties-3b30b40669d9?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3b30b40669d9</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Tue, 22 Nov 2016 15:18:02 GMT</pubDate>
            <atom:updated>2017-07-04T22:39:14.761Z</atom:updated>
            <content:encoded><![CDATA[<p>For about a month I’ve been working on a client project that requires the use of different UI themes over different contexts.</p><p>After considering a couple <a href="https://speakerdeck.com/csswizardry/4half-methods-for-theming-in-s-css">methods for theming</a>, I decided the best approach was <strong>stateful theming</strong>.</p><h3>Stateful wha?</h3><p>As the name implies, stateful theming means styling certain aspects of the UI based on a given state or condition. For example:</p><pre>.t-red .title {<br>  color: red;<br>}</pre><p>Where the usual way of going about it would be to add your theme class to your <em>&lt;body&gt;</em>:</p><pre>&lt;body class=&quot;t-red&quot;&gt;<br>    &lt;h1 class=&quot;title&quot;&gt;A title&lt;/h1&gt;<br>&lt;/body&gt;</pre><p>However, this method also allows you to have multiple co-existing themes along different contexts:</p><pre>&lt;body&gt;<br>    &lt;section id=&quot;post-1&quot; class=&quot;t-red&quot;&gt;<br>      &lt;h1 class=&quot;title&quot;&gt;Red title&lt;/h1&gt;<br>    &lt;/section&gt;<br>    <br>    &lt;section id=&quot;post-2&quot; class=&quot;t-blue&quot;&gt;<br>      &lt;h1 class=&quot;title&quot;&gt;Blue title&lt;/h1&gt;<br>    &lt;/section&gt;<br>&lt;/body&gt;</pre><p>And while it’s not a particularly common case, this was exactly what I needed.</p><h3>The Sassy Way</h3><p>My initial approach involved SCSS, making use of the handy <a href="https://css-tricks.com/the-sass-ampersand/">ampersand</a> and <a href="http://thesassway.com/news/sass-3-3-released">maps</a>. To give you an example, the code for buttons would look something like this:</p><pre>.c-btn--primary {<br>  <br>  .t-red &amp; {<br>    background-color: map-get($theme-red, primary);<br>  }<br>  <br>  .t-blue &amp; {<br>    background-color: map-get($theme-blue, primary);<br>  }<br>}</pre><pre>.c-btn--secondary {<br>  <br>  .t-red &amp; {<br>    background-color: map-get($theme-red, secondary);<br>  }<br>  <br>  .t-blue &amp; {<br>    background-color: map-get($theme-blue, secondary);<br>  }<br>}</pre><p>This approach seems to be fine if you have one or two additional themes apart from your default one. But in this case, I had five different color schemes. Every time I introduced a new themeable component, I had to manually add styles for each and every possible theme. And every time I wanted to create a new theme, I had to go through every variant of every themeable component, add a new theme class, and style it. Ugh.</p><h3>Utility Classes</h3><p>Stateful utility classes seemed like a decent solution to this problem. Instead of having to go one by one, I now had a couple utility classes that kept track of the current theme for each common property:</p><pre>.u-color-primary {</pre><pre>  .t-red &amp; {<br>    color: map-get($theme-red, primary);<br>  }<br>  <br>  .t-blue &amp; {<br>    color: map-get($theme-blue, primary);<br>  }<br>}</pre><p>This would eventually allow me to programmatically generate those utility classes with SASS, cutting down the time and effort required to introduce new themes significantly.</p><h3>Custom properties to the rescue</h3><p>But then I stumbled upon <a href="http://csswizardry.com/2016/10/pragmatic-practical-progressive-theming-with-custom-properties/">Harry’s article on theming with custom properties</a>. And while I’m not necessarily following his approach, the article opened my eyes to the possibilities.</p><p>The main advantage of CSS Custom Properties over pre-processor variables is that <strong>they are available at runtime</strong>. That means you can change their values and see those changes reflected instantly on your site. CSS Custom Properties can also be declared multiple times and cascade, which is where the magic happens:</p><pre>// Default theme<br>:root {<br>  --primary: #000;<br>  --secondary: #666;<br>}</pre><pre>// Blue theme<br>.t-blue {<br>  --primary: blue;<br>  --secondary: deepskyblue;<br>}</pre><pre>// Red theme<br>.t-red {<br>  --primary: red;<br>  --secondary: lightcoral;<br>}</pre><p>Here, we have a default theme (defined in :root), and two additional UI themes, prefixed with the <em>.t-</em> namespace. If any of the values defined in a theme class is invalid, it will automatically fallback to the <em>:root</em> value.</p><p>Our markup will look exactly the same as before example, but our CSS will now become much cleaner:</p><pre>.c-btn--primary {<br>  background-color: #000; // Fallback for unsupported browsers<br>  background-color: --var(primary);<br>}</pre><pre>.c-btn--secondary {<br>  background-color: #333; // Fallback for unsupported browsers<br>  background-color: --var(secondary);<br>}</pre><p>With this approach, introducing new themes is now as simple as adding a new theme class and changing some values. Yay!</p><p>Although it’s cleaner, you don’t need to use :root to provide a fallback theme, as the <em>var()</em> function has support for specifying fallback values as well:</p><pre>.c-btn--primary {<br>  background-color: #000; // Fallback for unsupported browsers<br>  background-color: --var(primary, #000); // var() with fallback<br>}</pre><p>Whichever way you prefer, you should use a pre-processor to avoid repetition when providing fallback values.</p><p>Using the <em>:root</em> approach and SASS, you could so something like:</p><pre>// Default Theme<br>$theme-default: (<br>  --primary: blue,<br>  --secondary: green,<br>);</pre><pre>// Programmatically generate fallback :root variables from the default theme<br>:root {<br>  @each $name, $value in $theme-default {<br>     #{$name}: #{$value};<br>  }<br>}</pre><pre>// Mixin<br>// 1. Grab the fallback value from the default theme<br>@mixin var($property, $variable) {<br>  #{$property}: map-get($theme-default, $variable); // [1]<br>  #{$property}: var($variable);<br>}</pre><pre>// Usage example<br>body {<br>  @include var(color, --secondary);<br>}</pre><h3>Final words</h3><p>While CSS Custom Properties make tedious tasks like theming a bit easier, I will have to agree with <a href="http://csswizardry.net/">Harry</a> in that theming should be avoided unless there’s a real case for it, as it will increase code complexity, maintenance overhead and testing times.</p><p>At the time of writing this article, CSS Custom Properties have <a href="http://caniuse.com/#feat=css-variables">67.21% global support</a>. We also provide fallback to a default theme for browsers that don’t support them, so unless it’s vital for you to provide theming for IE11, Edge 14 or Opera Mini, Custom Properties are probably the way to go.</p><p>If you want to learn more about CSS Custom Properties, don’t miss <a href="https://www.youtube.com/watch?v=2an6-WVPuJU">Lea’s awesome presentation at CSSConf</a>.</p><figure><a href="http://mariano.io/signup"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PQMVDicdhfnC2LSh2UTStg.jpeg" /></a></figure><h3>If these tips helped you, please let others know by clicking on that little heart below — thanks!</h3><p><strong>I’m also available for </strong><a href="http://mariano.io/#work"><strong>front-end development &amp; CSS consulting</strong></a><strong> work.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3b30b40669d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/stateful-theming-css-custom-properties-3b30b40669d9">Stateful Theming with CSS Custom Properties</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stop Concatenating Your CSS/JS]]></title>
            <link>https://medium.com/mariano-css/stop-concatenating-your-css-js-a9b44bf259cc?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9b44bf259cc</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[http2]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Tue, 01 Nov 2016 19:01:10 GMT</pubDate>
            <atom:updated>2018-03-23T20:46:30.827Z</atom:updated>
            <content:encoded><![CDATA[<h4>Remember when concatenating all your CSS and Javascript files into one was a best practice? Not anymore</h4><h3>Concatenation is dangerous</h3><p>Merging all your Javascript files into one may save browser requests, but it also means that a single error in one of your scripts will screw up everything.</p><p>Even if your Javascript is technically free of errors, old browsers like IE8 lack support for otherwise normal javascript such as function.prototype.bind(), get and set keywords, etc.</p><p>TL;DR: Eventually, stuff will fail. Concatenation will just make things fail harder.</p><h3>Concatenation is bad for caching</h3><p>You bundle all your Javascript (could also be CSS) and push to production. Your bundle.js file gets cached by both your CDN and your user’s browsers. Nice!</p><p>But now you need to fix something. As usual, you work on your code, and re-bundle all your scripts. Then you push.</p><p>Since your bundle.js is actually a new file (fingerprinted with a new MD5 hash), the cache is invalidated.</p><p>Every time you concatenate your files into a single bundle, you force users to re-download the entire bundle every time you make a change no matter how tiny.</p><p>By including smaller files separately, you allow browsers to cache those Javascript and CSS bits that don’t get updated frequently, giving you higher cache hit ratios and improved performance.</p><h3>Say hello to HTTP/2</h3><p>Concatenating your files used to serve the purpose of reducing HTTP requests. Under HTTP/1, downloading one big file will (almost always) be faster than performing many requests to download multiple smaller files.</p><p>This is not the case with HTTP/2, where requests are very cheap. This is mainly because of the protocol’s ability to re-use connections, compress headers and multiplex.</p><h3>But… not so fast</h3><p>While caching improves with multiple files, compression usually gets worse. Because of how compression algorithms work, they usually do much better on large, monolithic files than smaller ones. That means you are now serving bigger files.</p><p>This needs to be tested on a case by case basis. If you are serving hundreds of multiple files, you may want to bundle them in smaller chunks. For a couple dozen, it probably won’t be worth the hassle.</p><h3>Can I Use HTTP/2 today?</h3><p>At the time of writing this article, HTTP/2 has <a href="http://caniuse.com/#feat=http2">over 77% global support</a>. It’s also backwards compatible, so the short answer is yes, you can get started with HTTP/2 today.</p><p><a href="https://aws.amazon.com/about-aws/whats-new/2016/09/amazon-cloudfront-now-supports-http2/">Amazon Cloudfront</a> supports HTTP/2 since September 8th and there are tutorials for <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-with-http-2-support-on-ubuntu-16-04">DigitalOcean</a> as well.</p><p><strong>So what about those browsers that don’t support HTTP/2?</strong></p><p>Slow is always better than broken. And HTTP/2 is not a magic bullet either. You still want to take advantage of other web performance techniques out there. For example: some browsers that don’t support HTTP/2 do have support for other “modern” features like resource hints.</p><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9b44bf259cc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/stop-concatenating-your-css-js-a9b44bf259cc">Stop Concatenating Your CSS/JS</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Should your site work without JS?]]></title>
            <link>https://medium.com/mariano-css/why-javascript-as-a-dependency-is-fucking-fine-ea851e2b57b2?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea851e2b57b2</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Mon, 17 Oct 2016 23:53:23 GMT</pubDate>
            <atom:updated>2018-03-23T20:54:19.499Z</atom:updated>
            <content:encoded><![CDATA[<h4>Why Javascript as a dependency is just fine</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9_zMr51fbZRtYatnsxlRAg.jpeg" /></figure><p>A couple days ago my Twitter feed lit on fire with a debate around Progressive Enhancement and, specifically, whether websites should work without JS or not.</p><p>Today, I’d like to share with you a couple thoughts &amp; ideas on the subject that have been around my mind for a while.</p><p><strong>TL;DR: Javascript as a dependency is fine, and sometimes dropping support for non-JS users is a worthy trade-off.</strong></p><h3>What is Progressive Enhancement?</h3><blockquote>“Progressive enhancement means that everyone can access the basic content and functionality of a page in any browser, and those without certain browser features may receive a reduced but still functional experience”</blockquote><blockquote><strong>Lighthouse</strong></blockquote><p>A progressively enhanced website starts with a baseline of content and functionality, and then increases the richness and complexity of the user experience based on browser capabilities.</p><p>This approach is still relevant and useful today. I’m not here to convince you otherwise.</p><p>However, many developers seem to take this to the extreme of saying “any website should work without JS” (including complex web applications like Facebook). While many others seem to think we should drop Progressive Enhancement altogether and ignore those cases where Javascript fails and users are welcomed with nothing but a blank screen.</p><p>Turns out it’s not as simple as a binary choice.</p><h3>Remember who you’re building for</h3><p>I’m quoting myself here: <em>“Pragmatism (not to be confused with plain bad code) should trump idealism every time. After all, we’re not building for ourselves, but for users &amp; businesses.”</em></p><p>Unless you’re working on a personal project, every decision you make as a developer should be done with nothing but two things in mind: the users you’re building for &amp; the business you’re building for. If making the site work without JS is not relevant for the target user base, then save that business time &amp; resources by just not doing it.</p><blockquote>“I’m a strong believer in progressive enhancement, but also that each phase of the enhancement needs a user.”</blockquote><blockquote><strong>Jake Archibald</strong></blockquote><h3>Accessibility</h3><p>Just like Progressive Enhancement, a11y is often seen as an ethical decision as much as a technical one. And while building functional UI components with CSS only is fun, as an accessibility advocate, you may want to think about it twice: <a href="http://www.scottohara.me/article/is-it-accessible.html">it is often impossible to build accessible UI components without Javascript</a>.</p><p>Apart from labels and a few other simple code snippets, most ARIA-enhanced components need Javascript to properly reach Assistive Technologies (like Screen Readers). For example: HTML &amp; CSS are not enough to provide proper keyboard functionality or communicate contracted/expanded states.</p><h3>Separation of concerns</h3><p>There is no point in replacing solid Javascript with CSS hacks. Specially considering there are cross-browser issues with CSS as well.</p><p>Using CSS instead of JS for handling logic &amp; states is just as bad as using HTML’s &lt;center&gt; tag instead of CSS to center text. It’s not what the language was meant to do in the first place.</p><p>Separation of concerns is still a very valid principle today, and it perfectly fits this scenario.</p><h3>Performance</h3><p>Most content-based websites can still benefit from the “start with HTML, then progressively add CSS and Javascript” approach. After all, you should not need JS to make your small blog’s or marketing website’s content available to a browser.</p><p>However, web applications are a whole different story.</p><p>Models like <a href="https://developer.chrome.com/apps/offline_apps">offline-first</a> and the <a href="https://developers.google.com/web/updates/2015/11/app-shell">app-shell architecture</a> now give us the opportunity to build robust applications with realiably good performance. This is specially important for users with slow, unreliable and spotty internet connections (mostly in developing countries).</p><p>The only downside is that these models are often hard to “progressively enhance”, making it almost impossible to make core functionality available without Javascript. Yes, that would be ideal. No, it’s not always possible.</p><p>You are now faced with a choice: Either drop support for non-js users, or deliver a frustrating, sub-par experience for users with lie-wifi and slow network connections.</p><p>According to a study conducted by Yahoo! in 2010, 0.25% (Brazil) to 2% (USA) of people on the web have JavaScript disabled.</p><p><a href="https://en.wikipedia.org/wiki/List_of_countries_by_Internet_connection_speeds">Akamai’s rankings for Q3 2015</a> show 16 countries with an average internet connection speed of less than 5mbps. That includes China, with an average of 3.7mbps, representing about <a href="http://www.internetlivestats.com/internet-users/">22% of the total internet population</a>.</p><p>So while you should always consider your app’s target market first, it’s worth mentioning that if you ever decide to drop support for non-JS users for the sake of building a more performant and robust web application for those users with poor network connections, maybe the math is on your side.</p><h3>Final Thoughts</h3><ul><li>It’s not a binary choice. There’s no simple answer to this matter.</li><li>Stay pragmatic. Remember every enhancement needs a user. If there is no user, there is no point.</li><li>Don’t make Javascript more of a dependency than it needs to be, but don’t avoid it either. Javascript can be awesome for accessibility &amp; performance.</li></ul><h3>Further Reading</h3><ul><li><a href="http://www.scottohara.me/article/is-it-accessible.html">“Is It Accessible?” by Scott Ohara</a></li><li><a href="https://nolanlawson.com/2016/10/13/progressive-enhancement-isnt-dead-but-it-smells-funny/">Progressive Enhancement isn’t dead but it smells funny by Nolan Lawson</a></li><li><a href="https://medium.com/@codepo8/we-need-javascript-to-fix-the-web-a01bca57ff97#.xftagc8jd">We Need Javascript To Fix The Web by Christian Heilmann</a></li><li><a href="http://hugogiraudel.com/2016/10/13/you-might-need-javascript/">You Might Need Javascript by Hugo Giraudel</a></li></ul><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea851e2b57b2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/why-javascript-as-a-dependency-is-fucking-fine-ea851e2b57b2">Should your site work without JS?</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS Utility Classes: How To Use Them Effectively ]]></title>
            <link>https://medium.com/mariano-css/css-utility-classes-how-to-use-them-effectively-d61ee00dad2d?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/d61ee00dad2d</guid>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Fri, 14 Oct 2016 22:19:11 GMT</pubDate>
            <atom:updated>2018-03-23T20:50:19.047Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Fq8IzVxeUrl3t-Mr7rf7VQ.jpeg" /></figure><p>Utility classes are meant to do only one thing, and do it well. They are designed to be simple, composable and re-usable, allowing for easy and fast development.</p><p>While a CSS system based on utility classes alone is <a href="https://blog.mariano.io/battle-of-the-architectures-30c512d542a4">not desirable</a>, having a set of utility classes that allow you to quickly put together templates is great.</p><p>So where do we draw the line? How do we decide if a utility class is the right approach in any given situation?</p><p>Utility classes should be the exception, not the rule. Only consider using a utility class if the rule you want to apply is:</p><ul><li><strong>Exceptional &amp; Specific:</strong> “In <em>this particular case</em>, I want <em>this</em> card to have a larger top margin”. If you find yourself consistently employing the utility class across many instances of the same component, you should consider either using a <a href="http://csswizardry.com/2013/05/scope-in-css/">scope class</a> (if it occurs only inside a specific context) or introducing a new variant to your component.</li><li><strong>Optional:</strong> Could it be safely removed without breaking the component’s appearance? Using the previous example, it makes sense to employ a utility class to give your card a larger top margin, but not to give it a white background color or a black box shadow (non-optional, component-specific styling).</li><li><strong>Definite:</strong> You don’t expect this rule to be overridden by any other rule in your stylesheet (One exception to this rule is responsive utilities, where you have multiple utility classes applied at different breakpoints). All of your utility classes should carry an “!important” declaration to force <a href="http://csswizardry.com/2015/03/immutable-css/">immutability</a>.</li></ul><h3>Common Use Cases</h3><p>I find utility classes really helpful for:</p><ul><li>Margin/padding</li><li>Text (colors, size, styles)</li><li>Common Background Colors</li><li>Hiding/Showing stuff</li><li>Display (block, inline-block)</li></ul><p>However, you still have to consider each case separately using the guidelines above. Just because you have a utility class for something, it doesn’t mean it’s the right approach for that particular case.</p><h3>Naming utility classes</h3><p>To separate utility classes from component classes, it’s good to namespace them. I use the .u- namespace.</p><p>You can also shorthand most properties for faster coding. Here are a couple I use:</p><ul><li>p/m for margin/padding</li><li>t/r/l/b for top/right/left/bottom</li><li>v/h for vertical/horizontal</li><li>bg for background</li></ul><h3>BEM and utility classes</h3><p>I’ve recently seen an example of spacing utility classes named like this:</p><pre>&lt;div class=&quot;u-mt--large&quot;&gt;</pre><pre>  &lt;p&gt;Content&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><p>Where mt means margin-top and large is a variable that means 32px. In BEM, the two dashes (also known as the modifier notation) imply that this class .u-mt--large is a modifier of the original .u-mt class.</p><p>Modifier classes are not meant to be independent. And that means the original class should always be included. The proper BEM way of doing it would be:</p><pre>&lt;div class=&quot;u-mt u-mt--large&quot;&gt;</pre><pre>  &lt;p&gt;Content&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><p>This doesn’t really make sense. Utility classes are meant to be independent.</p><p>Also, not only I’m making it much longer than it needs to be (two classes vs just one). I’m overriding the first class with another.</p><p>The solution I’ve found is to remove the modifier notation and camel case the classname for better readability:</p><pre>&lt;div class=&quot;u-mtLarge&quot;&gt;</pre><pre>  &lt;p&gt;Content&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><p>Of course, you could also do:</p><pre>&lt;div class=&quot;u-mt-large&quot;&gt;</pre><pre>  &lt;p&gt;Content&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><h3>Responsive Utilities</h3><p>If you need to employ different utility classes across different screen sizes, you can use the responsive suffix @&lt;breakpoint&gt;:</p><pre>&lt;div class=&quot;u-mt u-mtLarge@medium&quot;&gt;</pre><pre>  &lt;p&gt;Content&lt;/p&gt;</pre><pre>&lt;/div&gt;</pre><h3>“Won’t all these utility classes bloat my CSS?”</h3><p>Utility classes should never be the bulk of your system. However, it’s easy to over-do them, specially when introducing breakpoints into the mix. My advice:</p><ul><li><strong>Always be refactoring.</strong> Make it a habit to check for cases where rules (and combinations of rules) should be formalized into a new component or a variant of an existing one.</li><li><strong>Consider post-processing your CSS</strong> with a tool like <a href="https://github.com/giakki/uncss">UnCSS</a>. This way you can have the best of both worlds: Develop quickly with utility classes, and avoid bloat by removing the ones you don’t use from your production stylesheet.</li></ul><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d61ee00dad2d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/css-utility-classes-how-to-use-them-effectively-d61ee00dad2d">CSS Utility Classes: How To Use Them Effectively 🔥</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Common CSS Mistakes (And How To Fix Them)]]></title>
            <link>https://medium.com/mariano-css/common-css-mistakes-and-how-to-fix-them-8ee0f5e88d64?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ee0f5e88d64</guid>
            <category><![CDATA[responsive-design]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[sass]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Sun, 28 Aug 2016 00:59:01 GMT</pubDate>
            <atom:updated>2018-03-23T20:45:16.265Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/869/1*wBlRGaXA1AoiSqpFExldYQ.jpeg" /></figure><p>These are some common causes of design, scalability, performance and maintainability issues I find when refactoring CSS for clients:</p><h3>Using units for setting line heights</h3><p>Using units when setting your line heights will make child elements inherit the computed value from their parent. The lack of relativity will force you to keep adding line-heights to override previous values:</p><pre>h1 {<br>  font-size: 48px;<br>  line-height: 72px;<br>}<br>.post-title {<br>  font-size: 36px;<br>  line-height: 54px;<br>}<br>.page-title {<br>  font-size: 72px;<br>  line-height: 108px;<br>}</pre><p>With unitless line heights, child elements will inherit the raw number, and will be able to compute their own line height based on font size.</p><pre>h1 {<br>  font-size: 48px;<br>  line-height: 1.5;<br>}<br>.post-title {<br>  font-size: 36px;<br>}<br>.page-title {<br>  font-size: 72px;<br>}</pre><p>Of course, if you seriously care about achieving a “perfect” vertical rhythm, then you will most likely need to set your line heights individually. It’s up to you to decide if you’d rather sacrifice maintainability and simplicity for the sake of perfection.</p><h3>Pixel units everywhere</h3><p>You can always save yourself some time and set your font sizes, margins and paddings using rem and em units. Pixels are simple and consistent, which sometimes is desirable, but there are a few neat tricks you can achieve with relative units:</p><pre>html {<br>  font-size: 100%;<br>}</pre><pre>h1 { <br>  font-size: 3rem;<br>  margin: 1rem 0;<br>}</pre><pre>/* let&#39;s proportionally scale the site for massive screen sizes */<br>@media (min-width: 2000px) {<br>  html {<br>    font-size: 100vw;<br>  }<br>}</pre><p>You can also combine rems and ems for better results. For example:</p><pre>.button {<br>  font-size: 1.125rem;<br>  padding: .5em 1em;<br>}</pre><pre>/* ems will scale with font size, so you don’t have to declare paddings again */<br>.button--large {<br>  font-size: 1.5rem;<br>}</pre><h4><strong>Device breakpoints</strong></h4><blockquote>Apple aren’t the only people who make handheld devices with browsers on them. No really. — <a href="https://medium.com/@Heydon/things-to-avoid-when-writing-css-1a222c43c28f#.xaadm01hk">Heydon Pickering</a></blockquote><p>Letting a popular device’s dimension dictate your breakpoints is not what responsive design is about. Here’s how you should do it:</p><blockquote><em>Start with the small screen first, then expand until it looks like shit. Time for a breakpoint! — </em><a href="http://bradfrost.com/blog/mobile/bdconf-stephen-hay-presents-responsive-design-workflow/"><em>Stephen Hay</em></a></blockquote><p>Most likely, you’ll find different components will break at different widths. Use major (global) and minor (component-specific) breakpoints.</p><h4><strong>Avoiding !important</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/275/1*zBIerUAdZeQUJrMc7WzEwg.gif" /><figcaption>“You should never use !important”</figcaption></figure><p>There are legit use cases for !important, like <a href="http://csswizardry.com/2016/05/the-importance-of-important/">forcing immutability</a> in utility classes. Do avoid using it as a quick way to deal with specificity issues.</p><h4>No comments</h4><p>Commenting your CSS will make life easier for anyone inheriting your code. As a rule of thumb, you want to comment on anything that isn’t obvious from your code alone.</p><h4><strong>Overdoing comments</strong></h4><p>Go <a href="https://www.smashingmagazine.com/2008/05/improving-code-readability-with-css-styleguides/">overboard</a> with comments and people <em>will </em>forget to update them. Unreliable comments are worse than no comments at all.</p><pre>/*------------------------------------------------------------------<br>[Master Stylesheet]</pre><pre>Project:	Smashing Magazine<br>Version:	1.1<br>Last change:	05/02/08 [fixed Float bug, vf]<br>Assigned to:	Vitaly Friedman (vf), Sven Lennartz (sl)<br>Primary use:	Magazine <br>-------------------------------------------------------------------*/<br>@import &quot;reset.css&quot;;<br>@import &quot;layout.css&quot;;<br>@import &quot;colors.css&quot;;<br>@import &quot;typography.css&quot;;<br>@import &quot;flash.css&quot;;<br>/* @import &quot;debugging.css&quot;; */</pre><p>To make your code more maintainable, avoid redundancy. Some things that shouldn’t be in your comments:</p><ul><li>Things that are obvious from the code alone.</li><li>Unit conversions (i.e: font-size: 1.5rem; // 24px).</li><li>Changes and revisions. We have version control for that!</li></ul><h4><strong>Hard-coded values</strong></h4><p>Following the <a href="https://en.wikipedia.org/wiki/Don%27t_repeat_yourself">DRY principle</a>, every piece of knowledge must have a single, unambiguous and authoritative representation within your stylesheet.</p><p>Take this example:</p><pre>h1 {<br>  margin: 30px 0;<br>}</pre><pre>.hero {<br>  margin-bottom: 30px;<br>}</pre><pre>.marg-top {<br>  margin-top: 30px;<br>}</pre><p>What if we decide that we want to do 40px instead of 30px? You’ll have to remember to change every one of these values manually. Usually these rules will be spread across multiple files, which makes it even worse.</p><p>You can either use a preprocessor or CSS custom variables, and you’ll only have to change your value once:</p><pre>$base-font-size: 16px;<br>$base-line-height: 1.5;<br>$spacing-unit: $base-font-size * $base-line-height;</pre><pre>h1 {<br>  margin: rem($spacing-unit);<br>}</pre><pre>.hero {<br>  margin-bottom: rem($spacing-unit);<br>}</pre><pre>.marg-top {<br>  margin-top: rem($spacing-unit);<br>}</pre><h4>Working against the cascade</h4><p>The cascade, inheritance and specificity make CSS a huge chronology where source order matters a LOT. Ignore this fact and headaches will follow.</p><p>These are all equally bad ideas:</p><ul><li>Organizing CSS to mimick the design (i.e: header at the top of the stylesheet, footer at the end).</li><li>Organizing CSS in random, multiple files without considering specificity. Multiple files are not a frigging panacea.</li><li>Adding new CSS at the bottom of the stylesheet.</li></ul><p>The principles behind <a href="https://www.youtube.com/watch?v=1OKZOV-iLj4">ITCSS</a> make a lot of sense here: Start with generic, low-specificity, far-reaching styles (i.e: bare html elements) and progress to more explicit, specific and smaller ones (i.e: utility classes carrying !important rules).</p><h4>ID’s inside selectors</h4><p>ID’s have higher specificity than classes and will do more harm than good in the long run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*qHjU8PJj26OpRen07-S47w.png" /><figcaption><a href="https://css-tricks.com/specifics-on-css-specificity/">https://css-tricks.com/specifics-on-css-specificity/</a></figcaption></figure><p>Use ID’s in HTML. Don’t use ID’s in CSS. If you <strong>have </strong>to, lower their specificity to class level:</p><pre>[id=&quot;YourID&quot;] {<br>  // your rules<br>}</pre><h4>Abusing extends</h4><p>Extends are one of those things that people tend to abuse… to the point of creating <a href="http://vanseodesign.com/css/dry-principles/">entire methodologies around them</a>. <strong><em>Ugh</em></strong>.</p><p>While extends make sense in some (limited) cases, I’m still to find a case where I couldn’t use a mixin with similar results and less potential issues.</p><p>Mixins will help you keep your code DRY while avoiding most of the nightmares that come with extends, like 125 lines CSS selectors:</p><h3>Gaël Métais on Twitter</h3><p>Damn! I wouldn&#39;t like to be the one who maintains this 125 lines CSS selector!pic.twitter.com/0jAEb2h8VF</p><h4>Bad selector intent</h4><p>Avoid making selectors more specific or qualified than strictly necessary. I’m borrowing this example from <a href="http://cssguidelin.es/#reusability">Philip Walton</a>:</p><pre>/* Grenade */<br>#main-nav ul li ul { }</pre><pre>/* Sniper Rifle */ <br>.subnav { }</pre><p>This is <a href="https://www.stevesouders.com/blog/2009/03/10/performance-impact-of-css-selectors/">not about selector efficiency</a>. It’s about reducing unnecessary specificity and increasing reusability.</p><p><strong>Always choose sniper rifles over grenades.</strong> I’m still talking about code.</p><h4>Generic classnames</h4><p>Generic classnames are more likely to be used for different purposes throughout large projects, producing unreliable code:</p><pre>.card .title {<br>  color: #000;<br>}</pre><pre>.post .title {<br>  color: #666;<br>  font-size: 1.5rem;<br>}</pre><p>Now what happens if you place a card component within a post?</p><pre>&lt;article class=&quot;post&quot;&gt;<br>  &lt;h1 class=&quot;title&quot;&gt;Post title&lt;/h1&gt;<br>  &lt;div class=&quot;card&quot;&gt;<br>    &lt;h3 class=&quot;title&quot;&gt;Card title&lt;/h3&gt;<br>  &lt;/div&gt;<br>&lt;/article&gt;</pre><p>In this case, your card title will inherit an unwanted font-size rule from the post title. An easy fix for this particular case would be to use the <a href="https://developer.mozilla.org/es/docs/Web/CSS/Child_selectors">child selector</a>:</p><pre>.post &gt; .title {<br>  color: #666;<br>  font-size: 1.5rem;<br>}</pre><pre>.card &gt; .title {<br>  color: #000;<br>}</pre><p>However, a more sustainable way of fixing it, is to use <a href="http://getbem.com/introduction/">BEM</a>-like notation. This paints a clearer picture of the relationship between different elements:</p><pre>.post__title {<br>  color: #666;<br>  font-size: 1.5rem;<br>}</pre><pre>.card__title {<br>  color: #000;<br>}</pre><p>And your HTML would look like this:</p><pre>&lt;article class=&quot;post&quot;&gt;<br>  &lt;h1 class=&quot;post__title&quot;&gt;Post Title&lt;/h1&gt;<br>  &lt;div class=&quot;card&quot;&gt;<br>    &lt;h3 class=&quot;card__title&quot;&gt;Card Title&lt;/h3&gt;<br>  &lt;/div&gt;<br>&lt;/article&gt;</pre><p>If you’re interested, I suggest you take a look at <a href="http://csswizardry.com/2015/08/bemit-taking-the-bem-naming-convention-a-step-further/">BEMIT</a>, which takes BEM even further by adding namespaces and responsive suffixes into the mix.</p><h4>Monoliths</h4><p>Monolithic rulesets make it difficult to introduce changes and variations to your components. You will often find yourself writing more CSS to achieve less styling (always a bad symptom):</p><pre>.button {<br>  display: inline-block;<br>  padding: .5em 1em;<br>  color: #666;<br>  background: #eee;<br>  font-size: 1rem;<br>  border: 1px solid #ddd;<br>  text-shadow: 1px 1px 1px #000;<br>}</pre><pre>.button.red {<br>  color: white;<br>  background: red;<br>  border: none;<br>}</pre><pre>.button.big {<br>  font-size: 2.5rem;<br>  padding: 2em 3em;<br>}</pre><pre>.button.no-shadow {<br>  text-shadow: none;<br>}</pre><p>Breaking down your buttons into smaller classes will help you re-use classes and introduce variations with ease:</p><pre>.button {<br>  display: inline-block;<br>}</pre><pre>.button--gray {<br>  background: #eee;<br>  color: #666;<br>  border: 1px solid #ddd;<br>}</pre><pre>.button--red {<br>  background: red<br>  color: white;<br>}</pre><pre>.button--small {<br>  padding: .5em 1em;<br>  font-size: 1rem;<br>}</pre><pre>.button--medium {<br>  padding: 1em 2em;<br>  font-size: 1.5rem;<br>}</pre><pre>.button--large {<br>  padding: 2em 3em;<br>  font-size: 2.5rem;<br>}</pre><pre>.button--shadow {<br>  text-shadow: 1px 1px 1px #000;<br>}</pre><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><h4>You may also enjoy:</h4><ul><li><a href="https://blog.mariano.io/battle-of-the-architectures-30c512d542a4">Battle of the architectures</a></li><li><a href="https://blog.mariano.io/quick-tip-testing-component-accessibility-with-css-3c36fe1a6562">Front-End Tip: Testing Component Accessibility with CSS</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ee0f5e88d64" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/common-css-mistakes-and-how-to-fix-them-8ee0f5e88d64">Common CSS Mistakes (And How To Fix Them)</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Front-End Tip: Testing Component Accessibility with CSS]]></title>
            <link>https://medium.com/mariano-css/quick-tip-testing-component-accessibility-with-css-3c36fe1a6562?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c36fe1a6562</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Mon, 08 Aug 2016 12:50:01 GMT</pubDate>
            <atom:updated>2018-03-23T20:34:42.472Z</atom:updated>
            <content:encoded><![CDATA[<h4>A very simple technique to bring inaccessible components to the surface before they make it into production.</h4><p>I love BEM. I love <a href="http://csswizardry.com/2015/08/bemit-taking-the-bem-naming-convention-a-step-further/">BEMIT</a> even more.</p><p>Write perfectly semantic markup, add your BEM classes and BOOM. Simple? Sure, as long as you’re the only one working on that codebase.</p><p>But most likely you’re not. There will be more experienced folks, juniors and people in between. Eventually, someone with a bad day will get his/her hands on your codebase.</p><p>BEM’s nature allows for very sloppy development, often without any visual or behavioral downsides at first sight. I’m talking about those moments where you find a &lt;div&gt; that “works” exactly like a &lt;button&gt;:</p><pre>&lt;div class=&quot;button&quot; onClick=&quot;doSomething()&quot;&gt;Do something&lt;/div&gt;</pre><p>This is not good for accessibility. Here’s what I’ve been doing to help with this issue:</p><p>Whenever you’re writing CSS for a new component, stop for a minute and think about how to make it accessible. Then, using CSS, create tests for that. For example:</p><pre>img {<br>  max-width: 100%;<br>  vertical-align: middle;<br>}</pre><pre>@if ($accessibility-testing-enabled == true) {<br>  img:not([alt]) {<br>    outline: 1em red solid;<br>  }<br>}</pre><p>That’s a very basic example. You can get a lot more complex and test for ARIA roles, labels and whatever you feel is needed for that particular component to be accessible.</p><p>If you build all of your components and objects this way, all you need to do after that is just set that $accessibility-testing-enable variable to trueand all those inaccessible components will come to the surface.</p><p>It’s not perfect, it’s not enough, but it sure helps.</p><h4>Enjoyed this article? 👏🏻 so more people can read it (or <a href="https://mariano.io/">Hire me</a> 🔥)</h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c36fe1a6562" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/quick-tip-testing-component-accessibility-with-css-3c36fe1a6562">Front-End Tip: Testing Component Accessibility with CSS</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Battle of the architectures]]></title>
            <link>https://medium.com/mariano-css/battle-of-the-architectures-30c512d542a4?source=rss-eec132d5a67b------2</link>
            <guid isPermaLink="false">https://medium.com/p/30c512d542a4</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Mariano Miguel]]></dc:creator>
            <pubDate>Tue, 28 Jun 2016 17:40:31 GMT</pubDate>
            <atom:updated>2018-03-23T20:30:32.769Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<h4>A look at two popular approaches to CSS, and why I think they are not good enough.</h4><p>There’s been a lot of debate in the front-end world about what “good CSS” means, and how we should be architecting our code for better maintainability, scalability, accessibility and performance. There are two extremes to this debate:</p><ol><li><strong>On one side, we have the “semantic” approach.</strong> People who thinks code should be as vanilla as possible, arguing that methodologies like BEM and OOCSS are not good enough because of their lack of concern about semantics and accessibility.</li><li><strong>On the other side, we have the “atomic/functional” approach.</strong> People who take the single responsibility principle very very far, making heavy use of ultra-specific utility classes that make for very bloated and often messy markup</li></ol><p>Both extremes are a bit <em>too</em> extreme. The answer lies somewhere between.</p><p>Disclaimer: Long post ahead! If at some point you read something you feel like you’ve read before, check the credits section at the bottom of this post. You probably did.</p><h3>What should we care about when writing CSS?</h3><p>In most cases, you should be able to determine whether or not your CSS is good based on:</p><ul><li><strong>How readable and self-documenting it is:</strong> If someone new on your team was to take a look at your code, how long would it take him/her to understand which elements do what and how they are related to each other?</li><li><strong>How easy to maintain it is:</strong> Maintaining bad CSS can be a <a href="https://twitter.com/gaelmetais/status/564109775995437057">nightmare</a>. On the other hand, a well-thought CSS architecture should enable you to roll out changes and new features easily and without breaking anything in the process.</li><li><strong>How scalable it is:</strong> The patterns and components you create should be abstract enough to be re-used in many instances and for different purposes. For example, does your code know the difference between Content and Display Patterns? If not, <a href="https://medium.com/@danielmall/content-display-patterns-a9726f66eb88#.mnky5uxje">it should</a>.</li><li><strong>File size (after GZIP):</strong> When it comes to file size, less is always more. While there’s no debate on this, you’d do well to notice that because of the way GZIP works, if you compare two minified but un-compressed CSS files, the smallest of the two could actually turn out to be the largest after GZIP.</li></ul><h3>Problems with the “semantic” approach</h3><h4>Not descriptive enough</h4><p>With HTML as we have it today, you will never have as many namespacing opportunities than with a classname-based approach like BEM. Unless you’re working on a small project (and you don’t plan to scale), there is no way you’re going to find as many tags and attributes for every object and component + variations. So after you’ve used all the possible tags and attributes combinations, you’ll be forced to start using classes, making everything inconsistent (why does this have a class, and this doesn’t?).</p><p>And even if you did find a combination for everything, things would still get complex (i.e, unnecessary nesting) in a short time, making your code a pain in the ass to maintain, and all because you wanted to avoid classnames? Please.</p><h4>Believe me, it will get complex</h4><p>Let’s say I wanted to style all my text-like inputs with the semantic approach:</p><pre>[type=&quot;email&quot;], [type=&quot;number&quot;], [type=&quot;password&quot;], [type=&quot;search&quot;], [type=&quot;text&quot;], [type=&quot;tel&quot;], [type=&quot;url&quot;] { }</pre><p>Great. I now have 7 selectors, and will have to add selectors on a one by one basis if HTML were ever to introduce another text-like input.</p><p>Here’s how we could simplify this:</p><pre>.c-input { }</pre><p>Terrible, isn’t it?</p><h4>You can still make your HTML accessible</h4><p>There is no excuse for not keeping your HTML accessible and semantic. You can still add ARIA roles and micro-formats. You can still use meaningful markup. You just don’t target them directly in your CSS.</p><p>The trade-off, is that developers will most likely be able to achieve the same visual design while using arbitrary markup.</p><h4>No one cares</h4><p>Almost no one. Browsers don’t care if you use classes or not, visitors don’t care either. Those new front-end interns on your team definitely will. How easy are you making it for them?</p><h3>Problems with the “functional” approach</h3><p>The main idea behind this approach is the use of highly re-usable classes that provide single-units of style (basically resembling inline styles) and have low-specificity, which allows for easy overrides. The benefits are there: small, scalable and simple CSS, plus an easy way to experiment with your layouts without having to even touch a CSS file.</p><p>To be honest, this approach got me really excited when I first heard about it. But after using it on a couple projects (with decent success), I started noticing there are some flaws to it:</p><h4>Not readable or self-documenting at all</h4><p>With functional/atomic CSS, it’s not unusual for you to see something like this:</p><pre>&lt;div class=&quot;bg-white box-shadow pad-1 marg-1 fl-left&quot;&gt;<br>&lt;/div&gt;</pre><p>If I was to tell you that was a card component, would you have figured it out from the code alone? Unless you’re the one who wrote this code, the answer is most likely no.</p><p>The code also fails to tell us which classes are crucial to our component, and which are optional or contextual. Do all cards need to have pad-1? What about that fl-left?</p><p>Here’s how we could do it instead:</p><pre>&lt;div class=&quot;c-card u-float-left&quot;&gt;<br>&lt;/div&gt;</pre><p>Here, we use BEM-style syntax along with transparent <a href="http://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/">namespaces</a> (in this case .c- for components, and .u- for utility classes). The code now tells us that this piece of DOM is a card component, and also informs which bits of it are optional (.u-float-left).</p><p>In your CSS, you would then have something like this:</p><pre>.c-card {<br>  background: #fff;<br>  margin: 15px;<br>  padding: 15px;<br>  box-shadow: 0 2px 2px 0 rgba(0,0,0,0.5);<br>}</pre><p>Simple, straightforward and consistent. Which brings me to my next point.</p><h4>Leaves too much room for inconsistencies</h4><p>Because you could use any combination of classes at any given point, it doesn’t take much for a developer to either screw up something or come up with a clever variation of your original component without giving it much thought:</p><pre>&lt;!— The original “card&quot; —&gt;<br>&lt;div class=&quot;bg-white box-shadow pad-1 marg-1 fl-left&quot;&gt;<br>&lt;/div&gt;</pre><pre>&lt;!— Someone forgot to add .box-shadow to our card, so now it doesn’t even look like card anymore! —&gt;<br>&lt;div class=&quot;bg-white pad-1 marg-1 fl-left&quot;&gt;<br>&lt;/div&gt;</pre><pre>&lt;!— Wouldn’t this card look great with a black background? —&gt;<br>&lt;div class=&quot;bg-black text-white box-shadow pad-1 marg-1 fl-left&quot;&gt;<br>&lt;/div&gt;</pre><p>The more classes we have, the more likely someone will screw up your design.</p><p>A more BEM-like approach would not only help keep our interfaces consistent by putting a higher entry level for new component variations (since we’d have to create a new class for each), but also help us avoid some unintentional mistakes by reducing the amount of classnames required for each component.</p><h4>No significant file size advantages</h4><p>In order to reduce file sizes, we are told to avoid defining the same styles for common properties (like margin or padding) over and over again. Instead, we should just use a single utility class for each property, which results in DRYer, smaller stylesheets.</p><p>No.</p><p>You can define the same styles for common properties a thousand times in our CSS, as long as you have those values stored in a single place in your codebase (as opposed to manually typing them every time). That’s what DRYness is all about: a single source of truth.</p><p>As for the rest, don’t worry: GZIP will take all the repetitive bits from your compiled CSS and compress them out. If you want to learn more about how GZIP works, take a look at <a href="https://www.youtube.com/watch?v=Mjab_aZsdxw">this video</a> from Kevin Khaw &amp; Eric Higgins.</p><h4>Moves maintenance over the HTML</h4><p>Unless you’re dynamically generating your component markup through a solid templating system, you can see how having to search through all your templates just to globally update a component’s padding from .pad-1 to .pad-2 can be a huge pain in the ass. Add multiple websites into the mix, and there’s even higher potential for disaster.</p><h3>Credits:</h3><ul><li><a href="https://medium.com/@stowball/bemantic-dry-like-you-mean-it-133ea3843d98#.m22yxeba4">“BEMantic: DRY Like You Mean It”</a> by Matt Stow</li><li><a href="http://csswizardry.com/2015/03/can-css-be-too-modular/">“Can CSS be too modular?”</a> by Harry Roberts</li><li><a href="http://csswizardry.com/2015/03/more-transparent-ui-code-with-namespaces/">“More Transparent UI Code with Namespaces”</a> by Harry Roberts</li><li><a href="https://hiddedevries.nl/en/blog/2016-05-08-collaborative-css">“Collaborative CSS”</a> by Hidde de Vries</li></ul><h4><em>Please hit ♥ below if you found this post useful so others can read it.</em></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30c512d542a4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mariano-css/battle-of-the-architectures-30c512d542a4">Battle of the architectures</a> was originally published in <a href="https://medium.com/mariano-css">Mariano.thinks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>