<?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 Noam Steiner on Medium]]></title>
        <description><![CDATA[Stories by Noam Steiner on Medium]]></description>
        <link>https://medium.com/@no.steiner?source=rss-11cea0611771------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*1IygL9CWkPXDgdmJa_hdEw.png</url>
            <title>Stories by Noam Steiner on Medium</title>
            <link>https://medium.com/@no.steiner?source=rss-11cea0611771------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:26:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@no.steiner/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[Change SVG icons color with CSS only]]></title>
            <link>https://medium.com/@no.steiner/change-svg-icons-color-with-css-only-ba6a4912e6ba?source=rss-11cea0611771------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6a4912e6ba</guid>
            <category><![CDATA[svg]]></category>
            <category><![CDATA[scss]]></category>
            <category><![CDATA[css]]></category>
            <category><![CDATA[mixin]]></category>
            <dc:creator><![CDATA[Noam Steiner]]></dc:creator>
            <pubDate>Thu, 02 Jan 2020 14:09:47 GMT</pubDate>
            <atom:updated>2020-01-07T09:21:44.486Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are here, you are probably looking for a simple solution for changing SVG icons color, in a way that will be simple for implementation.</p><p>This post shows how to do this, and even has an SCSS bonus, that will reduce it to a single line of code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/450/1*MSPKiu18teIkCA7_il8pKQ.gif" /><figcaption><a href="https://codepen.io/noam-steiner/pen/ExaVdge">Same icon different style</a> - it is even possible to “animate” the icon with a GIF background or CSS keyframes</figcaption></figure><p>So lets get started!</p><h3>The technique</h3><p><strong>This technique uses the </strong><strong>&lt;div&gt; tag with mask-image and background-color, it will not be relevant when:</strong></p><ul><li><em>You wish to use an </em><em>&lt;img/&gt; tag as the html element for the icon since it is not possible to manipulate it with CSS.</em></li><li><em>Implementing the SVG inline, in this case there are probably more appropriate techniques.</em></li></ul><h4>div</h4><p>The html element for the icon will be a div, This will enable us to manipulate the SVG with CSS and get a basic implementation in the html comparing to inline SVG.</p><h4>mask-image</h4><p>We will use a mask for the icon, thus letting the SVG cover the div and give it structure.</p><h4>background-color</h4><p>The icon’s color is obtained from the div’s background-color, by it showing through the SVG’s structure.</p><h3>Most basic implementation</h3><p>The most basic implementation is a single class with all needed CSS attributes to apply to the div.</p><p><strong>index.html</strong></p><pre>&lt;div class=&quot;some-icon&quot;&gt;&lt;/div&gt;</pre><p><strong>style.css</strong></p><pre>.some-icon {<br>  height: 10px;<br>  width: 10px;<br>  background-color: $default-text;<br>  -webkit-mask-size: contain;<br>  mask-size: contain;<br>  -webkit-mask-position: center;<br>  mask-position: center;<br>  -webkit-mask-repeat: no-repeat;<br>  mask-repeat: no-repeat;<br>  mask-image: url(https://medium.com/&quot;/assets/icons/calendar.svg&quot;);<br>}</pre><h3>Advanced implementation</h3><p>Defining one class for all the common attributes in global.css, for the non common attributes such as height, width, background-color and the mask-image add a specific class.</p><p><strong>index.html</strong></p><pre>&lt;div class=&quot;svg-icon calendar&quot;&gt;&lt;/div&gt;</pre><p><strong>style.css</strong></p><pre>.svg-icon.calander {<br>  height: 10px;<br>  width: 10px;<br>  background-color: $default-text;<br>  mask-image: url(https://medium.com/&quot;/assets/icons/calendar.svg&quot;);<br>}</pre><p><strong>global.css</strong></p><pre>.svg-icon {<br>  -webkit-mask-size: contain;<br>  mask-size: contain;<br>  -webkit-mask-position: center;<br>  mask-position: center;<br>  -webkit-mask-repeat: no-repeat;<br>  mask-repeat: no-repeat;<br>}</pre><h3>Implementation for pros — mixins!</h3><blockquote>Mixins allow you to define styles that can be re-used throughout your stylesheet. They make it easy to avoid using non-semantic classes like .float-left, and to distribute collections of styles in libraries.<br><a href="https://sass-lang.com/documentation/at-rules/mixin"><em> — Sass official documentation</em></a></blockquote><p>We will create a mixin using SCSS. The mixin will take arguments for all non-common attributes.</p><p><strong>variables.scss</strong></p><pre><a href="http://twitter.com/mixin">@</a>mixin svg-icon($path, $height, $width, $color ) {<br>  height: $height;<br>  width: $width;<br>  background-color: $color;<br>  mask-image: url(https://medium.com/$path); <br>  background-size: cover;<br>  -webkit-mask-size: contain;<br>  mask-size: contain;<br>  -webkit-mask-position: center;<br>  mask-position: center;<br>  -webkit-mask-repeat: no-repeat;<br>  mask-repeat: no-repeat;<br>}</pre><p><strong>index.html</strong></p><pre>&lt;div class=&quot;calendar&quot;&gt;&lt;/div&gt;</pre><p><strong>style.scss</strong></p><pre>.calendar {<br>  @include svg-icon(&quot;/assets/icons/calendar.svg&quot;, 20px, 20px,   #818aac);<br>}</pre><blockquote>Mixins are included into the current context using the <em>@include</em> at-rule, which is written <em>@include &lt;name&gt;</em> or <em>@include &lt;name&gt;(&lt;arguments...&gt;)</em>, with the name of the mixin being included.<br><a href="https://sass-lang.com/documentation/at-rules/mixin"><em> — Sass official documentation</em></a></blockquote><p>Live example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fnoam-steiner%2Fembed%2Fpreview%2FExaVdge%3Fheight%3D600%26slug-hash%3DExaVdge%26default-tabs%3Dcss%2Cresult%26host%3Dhttps%3A%2F%2Fcodepen.io&amp;url=https%3A%2F%2Fcodepen.io%2Fnoam-steiner%2Fpen%2FExaVdge&amp;image=https%3A%2F%2Fscreenshot.codepen.io%2F2026161.ExaVdge.small.1066ea2d-5c12-4313-a5da-34b47aa1e190.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/0541e09de1a5e02e96b12468721d5580/href">https://medium.com/media/0541e09de1a5e02e96b12468721d5580/href</a></iframe><h3>To conclude</h3><p>This is a very useful and basic implementation, that will keep your assets folder and your code as minimal as possible.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6a4912e6ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>