<?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 nthn on Medium]]></title>
        <description><![CDATA[Stories by nthn on Medium]]></description>
        <link>https://medium.com/@nthnh?source=rss-2ea0f56fe964------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*i984CM1wfzVIwZvRbt0QzA.jpeg</url>
            <title>Stories by nthn on Medium</title>
            <link>https://medium.com/@nthnh?source=rss-2ea0f56fe964------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 09:15:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nthnh/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[Embedding SVG code into React]]></title>
            <link>https://levelup.gitconnected.com/embedding-svg-code-into-react-2bcca190987a?source=rss-2ea0f56fe964------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bcca190987a</guid>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[svg]]></category>
            <dc:creator><![CDATA[nthn]]></dc:creator>
            <pubDate>Sat, 29 Jun 2019 05:24:26 GMT</pubDate>
            <atom:updated>2022-06-18T17:11:28.189Z</atom:updated>
            <content:encoded><![CDATA[<h4>This is my first ever blog post, and I would appreciate feedback on the technical content as well as my general writing style :)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/188/1*tB2RIT9kOwzqSX7DjypPAQ.gif" /></figure><p>Why would you want to use SVGs (Scalable Vector Graphics)? The major reasons would be <strong>Resolution, Flexibility, and Great Browser Support.</strong></p><p><strong>Resolution:</strong> SVGs are commonly made with vector-based graphic design software, such as Illustrator, Sketch, and Inkscape. This means they can be enlarged or shrunk to whatever size without them losing resolution or increasing in file size. This is great news :)</p><p><strong>Flexibility: </strong>Let your creativity run wild with SVGs, they are fully customizable using CSS. Accessibility options can be implemented, and you can add interactivity with JavaScript. You can also provide fallback images or background color if for some weird reason (ancient browsers etc.) SVGs aren’t supported on a particular machine.</p><blockquote><a href="http://themaninblue.com/experiment/Blobular/">Click here to see an amazing SVG based experiment</a>.</blockquote><p>Well… great browser support just means exactly that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lCcAGcxhzBIBbwAcoNyVbQ.png" /><figcaption><a href="https://caniuse.com/#search=svg"><strong>caniuse</strong></a> search for SVG shows basic functionality is widely supported across most modern browsers.</figcaption></figure><p>There are many ways to embed SVGs into your website regardless of the framework you use. <a href="https://www.sarasoueidan.com/">Sara Soueidan</a> in her <a href="https://www.smashingmagazine.com/2014/11/styling-and-animating-svgs-with-css/"><strong>article</strong></a> details <strong>7 ways</strong> of doing this. For this post, however, I’ll be using the inline method with a basic create-react-app. The final file would look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EDz60z3jaSi30u6ii7_Tcw.gif" /></figure><p><strong>Find the Demo in the CodeSandbox below, scroll further down for explanations.</strong></p><p><a href="https://codesandbox.io/embed/embed-svg-react-v3l9e">Embed SVG React - CodeSandbox</a></p><blockquote><strong>View the complete code on Github: </strong><a href="https://github.com/horsfallnathan/EmbedSVGInReact.git"><strong>completeFile</strong></a></blockquote><h4>So let’s start</h4><p>Create your SVG file using your favorite vector tool, save the file, and open with any text editor. You can use the generated code directly, but I recommend optimization using online tools. <a href="http://petercollingridge.appspot.com/svg-editor"><strong>Here</strong></a><strong> </strong>is a great site for that.</p><p>The benefits of optimization include: making your SVG code more readable and smaller by taking away all unnecessary header texts your software usually adds.</p><p>Next, create a new file and paste the optimized SVG code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c2b2641f6069b772fc2286816c3573f/href">https://medium.com/media/3c2b2641f6069b772fc2286816c3573f/href</a></iframe><p>Notice in the code above, the React className rule still applies, so you have to change ‘class’ in your original SVG code to ‘className’. I have exported the styles to an external CSS file, but if I wanted to leave it inline, I would have to add curly braces, the ‘React way’ <em>[see lines 14–16 below]</em>:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6cf4166e6da54f8bbb5435bf3e412e3/href">https://medium.com/media/a6cf4166e6da54f8bbb5435bf3e412e3/href</a></iframe><p>Awesome! all we have to do now is to import this file into our App. As any React component, you can pass props to it for conditional rendering to give desired animation-like effects.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4a75749a65fa19cd60399b093cb9f202/href">https://medium.com/media/4a75749a65fa19cd60399b093cb9f202/href</a></iframe><h3>Summary:</h3><p>Embedding SVGs inline in React opens a whole new world of creative possibilities and when combined with JavaScript animation libraries such as <a href="https://greensock.com/">GSAP</a> you can make your projects more impressive.</p><p><a href="https://codesandbox.io/embed/embed-svg-react-v3l9e">Embed SVG React - CodeSandbox</a></p><blockquote><strong>View the complete code on Github: </strong><a href="https://github.com/horsfallnathan/EmbedSVGInReact.git"><strong>completeFile</strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bcca190987a" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/embedding-svg-code-into-react-2bcca190987a">Embedding SVG code into React</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>