{"id":3012,"date":"2022-03-24T03:36:02","date_gmt":"2022-03-24T03:36:02","guid":{"rendered":"https:\/\/rengga.dev\/blog\/?p=3012"},"modified":"2023-06-12T14:32:12","modified_gmt":"2023-06-12T14:32:12","slug":"css-tutorial-svgbox","status":"publish","type":"post","link":"https:\/\/rengga.dev\/blog\/css-tutorial-svgbox\/","title":{"rendered":"CSS Tutorial &#8211; SVGBOX"},"content":{"rendered":"<p><span style=\"color: #ef3207;\"><a style=\"color: #ef3207;\" href=\"https:\/\/rengga.dev\/\" target=\"_blank\" rel=\"noopener\"><strong>Rengga Dev<\/strong><\/a> <\/span>&#8211; I\u2019ve been saying for years that\u00a0a pretty good icon\u00a0system is just dropping in icons with inline\u00a0<code>&lt;svg&gt;<\/code>\u00a0where you need them. This is simple to do, offers full design control, has (generally) good performance, and means you aren\u2019t smurfing around with caching and browser support stuff.<\/p>\n<p>Along those lines\u2026 using\u00a0<code>&lt;img&gt;<\/code>\u00a0isn\u2019t the worst idea for icons either. It doesn\u2019t offer as much fine-grained design control (although you\u00a0can still\u00a0<code>filter<\/code>\u00a0them) and arguably isn\u2019t\u00a0<em>quite<\/em>\u00a0as fast (since the images need to be fetched separately from the document), but it still has many of the same upsides as inline SVG icons.<\/p>\n<p>Shubham Jain has a project called\u00a0<a href=\"https:\/\/svgbox.net\/\" rel=\"noopener\">SVGBOX<\/a>\u00a0that offers icons-as-<code>&lt;img&gt;<\/code>\u00a0and removes one of the design-control limitations by offering a URL parameter to change colors.<\/p>\n<p>Want an Instagram icon, but in red? Pass in\u00a0<code>red<\/code>:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;img src=\"\/\/s.svgbox.net\/social.svg?fill=red&amp;ic=instagram\"&gt;\r\n\r\n&lt;img src=\"\/\/s.svgbox.net\/social.svg?fill=blue#twitter\"&gt;\r\n\r\n&lt;img src=\"\/\/s.svgbox.net\/social.svg?fill=805ad5#facebook\"&gt;<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"css\">img {\r\n  max-width: 40px;\r\n}<\/pre>\n<p><iframe style=\"width: 100%;\" title=\"CSS Tutorial - SVGBOX\" src=\"https:\/\/codepen.io\/renggagumilar\/embed\/RwMepBX?default-tab=result&amp;theme-id=dark\" height=\"300\" frameborder=\"no\" scrolling=\"no\" allowfullscreen=\"allowfullscreen\"><br \/>\nSee the Pen <a href=\"https:\/\/codepen.io\/renggagumilar\/pen\/RwMepBX\"><br \/>\nCSS Tutorial &#8211; SVGBOX<\/a> by Rengga Gumilar (<a href=\"https:\/\/codepen.io\/renggagumilar\">@renggagumilar<\/a>)<br \/>\non <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<br \/>\n<\/iframe><br \/>\nIf you\u2019re going to use a bunch of icons, the provided copy-and-paste code offers an \u201cSVG sprite\u201d version where the URL is like this:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"html\">&lt;img src=\"\/\/s.svgbox.net\/social.svg?fill=805ad5#instagram\"&gt;<\/pre>\n<p>That is going to increase the download weight of the icon (because it\u2019s downloading all the icons from this set), but possibly be more efficient as it\u2019s a single download not many. Hard to say if that\u2019s more efficient or not these days,\u00a0with HTTP\/2 around.<\/p>\n<p>What\u2019s interesting is the\u00a0<code>#instagram<\/code>\u00a0part at the end of the URL. Just a hash-link, right? No! Fancier! In SVG land, that can be\u00a0a fragment identifier, meaning it will only show the bit of the SVG that matches the proper\u00a0<code>&lt;view&gt;<\/code>\u00a0element. Don\u2019t see that every day.<\/p>\n<h2><span style=\"color: #ff0000;\"><a class=\"button\" style=\"color: #ff0000;\" href=\"https:\/\/svgbox.net\/\" target=\"_blank\" rel=\"noopener\">DIRECT LINK \u2192<\/a><\/span><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>Rengga Dev &#8211; I\u2019ve been saying for years that\u00a0a pretty good icon\u00a0system <a class=\"read-more\" href=\"https:\/\/rengga.dev\/blog\/css-tutorial-svgbox\/\" title=\"CSS Tutorial &#8211; SVGBOX\" itemprop=\"url\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":3753,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,2],"tags":[197,262,103,227],"newstopic":[],"class_list":{"0":"post-3012","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-html-css","8":"category-web-design","9":"tag-css-tutorial","10":"tag-svgbox","11":"tag-web-design","12":"tag-web-designer"},"_links":{"self":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3012","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/comments?post=3012"}],"version-history":[{"count":1,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3012\/revisions"}],"predecessor-version":[{"id":3014,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/posts\/3012\/revisions\/3014"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media\/3753"}],"wp:attachment":[{"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/media?parent=3012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/categories?post=3012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/tags?post=3012"},{"taxonomy":"newstopic","embeddable":true,"href":"https:\/\/rengga.dev\/blog\/wp-json\/wp\/v2\/newstopic?post=3012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}