Skip to content
cjhaas blog

Basically a place that Chris can post solutions to problems so he can easily find them later

cjhaas blog

Basically a place that Chris can post solutions to problems so he can easily find them later

Using SVGs in HTML

Posted on September 9, 2014 By [email protected]

I’ve been using SVGs in websites for a long time now but always as files on disk linked either via img or image tags. Recently, however, I started to use them in-content as if they were actually HTML tags. By doing this you have easier access for color changes as well as adding things like animations. Below is a very basic start to finish from Illustrator to page. Obviously your browser needs to support SVG but that’s outside of this post.

For starters, I created a very simple Adobe Illustrator file with the lowercase letter “c” in Arial, converted the letter to outlines and saved as an SVG.

Lowercase letter “c” in Arial converted to outlines
Save as settings for SVG

This produced the following SVG:

<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
     width="134.535px" height="157.373px" viewBox="0 0 134.535 157.373" enable-background="new 0 0 134.535 157.373"
     xml:space="preserve">
<g>
    <path d="M114.396,101.42l20.139,5.087c-4.222,16.541-11.818,29.154-22.786,37.838c-10.969,8.686-24.378,13.028-40.226,13.028
        c-16.401,0-29.741-3.338-40.018-10.018c-10.277-6.678-18.099-16.35-23.461-29.014C2.681,105.676,0,92.078,0,77.544
        c0-15.847,3.027-29.671,9.083-41.471c6.055-11.798,14.671-20.762,25.848-26.886C46.107,3.062,58.408,0,71.835,0
        c15.224,0,28.028,3.876,38.409,11.626c10.38,7.751,17.611,18.651,21.696,32.699l-19.828,4.671
        c-3.529-11.072-8.651-19.135-15.363-24.187c-6.713-5.051-15.156-7.578-25.329-7.578c-11.696,0-21.472,2.803-29.326,8.409
        c-7.855,5.605-13.375,13.131-16.558,22.578c-3.184,9.446-4.775,19.188-4.775,29.222c0,12.942,1.885,24.239,5.657,33.894
        c3.771,9.654,9.636,16.869,17.596,21.644c7.958,4.775,16.573,7.163,25.848,7.163c11.279,0,20.83-3.252,28.651-9.758
        C106.333,123.878,111.627,114.224,114.396,101.42z"/>
</g>
</svg>

Next, I ran my SVG through the SVGO library via the SVGO GUI tool to optimize/shrink my SVG. The optimized SVG (with whitespace added back just to make it easier to post here) now looks like:

<svg xmlns="http://www.w3.org/2000/svg" width="134.535" height="157.373" viewBox="0 0 134.535 157.373">
    <path d="M114.396 101.42l20.139 5.087c-4.222 16.541-11.818 29.154-22.786 37.838-10.969 8.686-24.378 13.028-40.226 13.028-16.401 0-29.741-3.338-40.018-10.018-10.277-6.678-18.099-16.35-23.461-29.014-5.363-12.665-8.044-26.263-8.044-40.797 0-15.847 3.027-29.671 9.083-41.471 6.055-11.798 14.671-20.762 25.848-26.886 11.176-6.125 23.477-9.187 36.904-9.187 15.224 0 28.028 3.876 38.409 11.626 10.38 7.751 17.611 18.651 21.696 32.699l-19.828 4.671c-3.529-11.072-8.651-19.135-15.363-24.187-6.713-5.051-15.156-7.578-25.329-7.578-11.696 0-21.472 2.803-29.326 8.409-7.855 5.605-13.375 13.131-16.558 22.578-3.184 9.446-4.775 19.188-4.775 29.222 0 12.942 1.885 24.239 5.657 33.894 3.771 9.654 9.636 16.869 17.596 21.644 7.958 4.775 16.573 7.163 25.848 7.163 11.279 0 20.83-3.252 28.651-9.758 7.82-6.505 13.114-16.159 15.883-28.963z"/>
</svg>

If your browser supports SVG you should be able to see it here (with a border added by me):

(For the remainder of these changes I’m just going to be talking about the changes and then posting the raw SVG code for you to look at.)

So what can we do with this? How about just coloring it? We can add a simple style style="fill:#f00;" to the <path> tag to make it red:

Or maybe a radial gradient?

HTML SVG

Post navigation

Previous post
Next post

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Google open redirect
  • How to use AI to write code
  • Doctrine/Symfony MariaDB DSN connection string
  • Creating a portable copy of pdftotext from source
  • Gravity Forms shortcode getting extra line breaks when used with ACF

Recent Comments

  • jose luis on #2 – VB.Net iTextSharp Tutorial – Add an image to a document
  • Eliezer Castanon on iTextSharp slightly smarter text extraction strategy
  • javad on How to recompress images in a PDF using iTextSharp
  • MANOUS3784 on Flock is awesome
  • Sang on Flock is awesome

Archives

  • June 2026
  • October 2025
  • November 2023
  • September 2023
  • July 2023
  • June 2023
  • May 2023
  • April 2023
  • December 2022
  • September 2022
  • April 2022
  • October 2021
  • September 2021
  • April 2021
  • January 2021
  • October 2020
  • August 2020
  • June 2020
  • May 2020
  • December 2019
  • November 2019
  • October 2019
  • July 2019
  • May 2019
  • December 2018
  • October 2018
  • July 2018
  • November 2017
  • October 2017
  • August 2017
  • July 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • September 2015
  • December 2014
  • November 2014
  • October 2014
  • September 2014
  • August 2014
  • July 2014
  • November 2013
  • May 2013
  • April 2013
  • March 2013
  • January 2013
  • November 2012
  • October 2012
  • July 2012
  • March 2012
  • January 2012
  • October 2011
  • September 2011
  • July 2011
  • February 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • August 2010
  • June 2010
  • April 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009

Categories

  • Accessibility
  • Advanced Custom Fields
  • Authorize.Net
  • BWP Minify
  • Composer
  • Crappy Google Search Results of the Day
  • CSS
  • Doctrine
  • Drupal
  • Drush
  • Elasticsearch
  • Fun links of the day
  • Google Analytics
  • Gravity Forms
  • HHVM
  • HTML
  • iTextSharp
  • JavaScript
  • Linux
  • mysql
  • nginx
  • Optimization
  • PDF
  • PdfPTable
  • PHP
  • Plugins
  • Ramblings
  • Random things I learned
  • Redis
  • Security
  • simplesamlphp
  • SQL Server
  • SSH
  • SSL/TLS/HTTPS
  • Stack Overflow
  • SVG
  • Symfony
  • Synology
  • Uncategorized
  • Unicode
  • Varnish
  • Vendi Best Practice
  • VIP
  • Weird Google Search Results
  • Windows
  • WordPress
  • WP-CLI

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
©2026 cjhaas blog | WordPress Theme by SuperbThemes