Vector svg icons. How to Implement Cross Browser SVG Icons

PSD icons are an indispensable element of any UI design, not inferior in importance even to fonts, however, in practice, rarely does anyone develop their own icons for each web project. On the other hand, it also takes a lot of time to search for icons of suitable quality and design, but today we decided to help you and prepared a selection of free icon sets for all occasions.

01.Icons8

Icons8 is a set of 20 thousand flat icons in any format, size and color! Here you can find categories such as business, clothing, food and many others. Icons8 can be downloaded as a Mac app or as a ZIP archive.

02. Freepik

A bright collection of vector icons from a specialized resource Freepik is just one of the many presented. It is ideal for business and independent projects. Additionally, you can download PSD icons in .AI, .EPS and .SVG formats.

03. Iconfinder

Designed in black and white, this set contains a combination of clear functional and emotional vector icons. In addition to the standard icons, this set contains icons in the form of hearts and eyes, which will allow you to give your own projects an emotional color.

04. 195 flat flag PSD icons

An excellent website PSD icon set that can be used in the development of an international website, online store or travel blog. The set includes 195 free icons with rounded corners.

05.Metro UI Icon Set

If you are a fan of Windows 8, then you should check out this free icon pack. It includes 700 well-designed icons that can be freely applied to any type of project.

06. Modern UI Icons

Another set of free icons that you can use when creating your user interface software for Windows or Android/iOS. By downloading this set, you'll get 1000 hand-drawn flat icons, including even icons for the Windows Phone app drawer.

07. 350 pixel perfect icons

Incredible set of 350 perfectly crisp icons for apps or websites. However, they can be resized without loss of quality.

08.80 mini icons

80 perfectly crisp miniature icons that can be downloaded both in PSD format and as an iconic font. These neat and sophisticated social PSD icons are perfect for any type of project.

09. Simple and practical web icon vector graphic

Lots of useful icons to use in personal and commercial projects.

10. Free flat icons

Set of flat style icons including calendar, email, clock, maps and more.

11.Mono icons

A set that includes 108 unique monochrome icons made in a minimalist style. All of them are available in PNG format at a size of 32 by 32.

12. Metric icons

A free Metro style collection that you can use in your own apps and web projects. PSD social media icons are free for both personal and public commercial use. The archive contains not only PSD , SVG , ESP and AI formats, but also web fonts.

13. Tab Bar Icons iOS 7

An elegant icon pack inspired by iOS 7 that you can use in your own apps. You can download icons in the following formats: PSD, AI and ESP.

14 Chunky Pika Icon Set

Pika style icons created by Dutch Icon agency from Denmark. This set includes 42 perfectly clear icons.

15. Iconic

Another set of simple yet eye-catching icons perfect for minimalist designs. Iconic is an open source set that can be downloaded in PNG , SVG , SWC and other formats, allowing you to adapt them to your own designs.

16. 44 Shades of Free Icons

Set of 44 icons. It contains PSD icons for the forum, which will allow you to easily edit and adapt them to your own projects.

17. Token icon set

Token includes 128 unique icons available in 16x16px, 32x32px and 256x256px ICO format and 128x128px PNG format. Each icon comes in dark and light versions, and is complete with a .psd file.

18. Flat Icons (PSD)

Colorful icons in a flat style that you can download in PSD format and edit to your own needs.

19. Free 32px icons set

A set in which you will find a PSD icon for any purpose: Skype , Facebook , Twitter , RSS , a cup of coffee, “like” and much more.

20. 48 flat designer icons

If you are a fan of minimalism, then you will definitely like this set. It consists of 48 free icons representing office tasks, social aspects, and travel. All of them are presented in AI and PNG formats, and they can be scaled without loss of quality.

21.Plex icons set

The set includes over 100 icons, including calendars, antivirus, clock, Email, applications Microsoft Office , social networks and much more.

22. Vectory mini free

A set of over 1000 PSD icons designed by the Icojam team. All of them are also in PNG format. They are ideal for use when developing a new site, as they are free to use in both personal and commercial projects.

23. Eldorado mini free

Another collection of mini icons from Icojam, featuring over 1200 icons in 40 x 40 pixels.

In this post, I will demonstrate how to implement SVG icons, how to implement fallback, and how to turn icons into an SVG sprite.

Basic integration of SVG elements

Especially for this tutorial, I will use one page that will work like an online business card. I will briefly present my services and show three profiles from professional networks related to my work. We will be using SVG icons.

You can see from the screenshot above that I'm using icons (Twitter, Dribbble and GitHub) to symlink to my work profiles. I downloaded these icons from flaticon , which had a lot of different icons and symbols in vector and raster formats.

png and svg

We'll start by using the PNG versions of these icons, for compatibility with previous versions, and then prepare SVG icons to work in supporting browsers.

I used Sketch to get the PNG icons, and I'll use it again to prepare the SVG icons.

If you look at the screenshot above, you'll notice that I've named all the groups and shapes in the left panel accordingly (Adobe Illustrator has the same list in the Layers panel). It is very important to name all sources correctly, this will not only help to organize the project well, but will also help in the subsequent steps of this tutorial.

Export SVG versions

Now I'm exporting the icons as SVG icons, this is very easy to do with Sketch's slicing tool. For a more detailed description of how this option works, check out Understanding Sketch's Export Options. I will export them as individual files and put them in the images folder in my project.

Normally, to display an image on a site, you link to the source using an element with a src attribute or something similar:

But with SVG files, there are several other ways that can be used in an HTML document. For example, you can use the SVG code directly - here's what it should look like:

twitter icon Created with Sketch.

This is one of the icons I exported, in XML format. This code is very similar to HTML (it's a structured format), which means we can embed it right into the page.

Adding SVG to HTML

Let's start with a basic HTML page, which includes PNG icons with their anchors, and a container:

And now I'll copy and paste the SVG code, although I'll ignore the top line, which refers to the nature of the file's embedding and other attribute details. The HTML document already contains information that need not be duplicated.

twitter icon Created with Sketch.

I placed the SVG directly above the corresponding PNG icons in the HTML page. On the this moment I'll wrap the line with the regular PNG image in a comment tag so it doesn't appear next to the SVG version

Cleaner SVG

I will also clean up the code in my SVG. Removing the attribute elements is optional since most of the fragments I remove won't change the behavior of the SVG. Here is the code before and after, in case you want to do the same:

twitter icon Created with Sketch.

See what items I removed. The elements , <desc>, and <defs>not needed now, but they will come in handy later in this tutorial. There are also several elements <g>which refer to groups, and correspond to the groups created in my Sketch document. Sketch places everything inside the page by default, hence the group element <g id=”Page-1”… . Вы можете это удалить, так как он нам не нужен (сама группа в нем важнее). Sketch предоставляет возможность получить более чистый SVG при экспорте , но и в чистке кода вручную нет никаких проблем.</p><p>The last part of this step is to remove the height and width attributes of the icon SVG element itself. This will need to be compensated in my CSS file as shown below:</p><p> <svg viewBox="0 0 50 41" version="1.1" xmlns="http://www.w3.org/2000/svg"> <g id="twitter-icon" fill="#55ACEE"> <path d="M0,36.3461306 C0.803663004,36.4417973 1.62142857,36.4907387 2.45054945,36.4907387 C7.26336996,36.4907387 11.6928571,34.8346712 15.2086081,32.0564595 C10.71337,31.9727973 6.91959707,28.9779505 5.61245421,24.8624369 C6.23956044,24.9834054 6.88315018,25.0482297 7.54505495,25.0482297 C8.48205128,25.0482297 9.38956044,24.9217207 10.2516484,24.684955 C5.55201465,23.7334595 2.01117216,19.5466577 2.01117216,14.5276667 C2.01117216,14.4840811 2.01117216,14.4406802 2.01190476,14.397464 C3.3970696,15.1733243 4.98095238,15.6392838 6.66501832,15.693027 C3.90860806,13.8354685 2.09487179,10.6648018 2.09487179,7.07102252 C2.09487179,5.17264865 2.6014652,3.39321171 3.48571429,1.86328378 C8.55238095,8.13037387 16.1217949,12.2543829 24.6595238,12.6863604 C24.4844322,11.9282297 24.3934066,11.1375946 24.3934066,10.3257207 C24.3934066,4.60511261 28.9930403,-0.0328738739 34.6664835,-0.0328738739 C37.6210623,-0.0328738739 40.2908425,1.2251982 42.1648352,3.23844595 C44.5047619,2.77377928 46.7032967,1.91167117 48.6880952,0.724702703 C47.9210623,3.14351802 46.2923077,5.17357207 44.1712454,6.45565315 C46.2492674,6.20522072 48.2291209,5.6483964 50.0714286,4.82451802 C48.6941392,6.90185135 46.952381,8.72635135 44.9454212,10.1868378 C44.9652015,10.6310045 44.9750916,11.0777568 44.9750916,11.5269099 C44.9750916,25.2155541 34.6424908,41 15.7472527,41 C9.9459707,41 4.54615385,39.2852027 0,36.3461306 L0,36.3461306 Z" id="bird"></path> </g> </svg>.icon ( max-width: 40px; max-height: 40px; transition: .2s; -webkit-filter: drop-shadow(0 1px 0 #11222d); )</p><p>If you follow these steps, you will see a sharp and clean vector version of your graphic in the browser.</p><p><b>Advice</b>: Check if the graphic is in SVG format by scaling with keys <b>Command-+</b> while browsing in a browser. Graphics should stay sharp no matter how you zoom.</p><h2>Fallback implementation</h2><p>If you are doing this for a client, it is important for you to know the list of supported browsers. Embedded SVG icons work in all browsers except Internet Explorer 8 (and earlier) and Opera Mini. According to statistics, only 4% of users use IE8, and about 3% use Opera Mini. So in your case, the fallback is not needed, but I will demonstrate its implementation.</p><p> <a href="http://twitter.com/DavidDarnes" title="twitter profile"> <svg viewBox="0 0 50 41" version="1.1" xmlns="http://www.w3.org/2000/svg"> <g id="twitter-icon" fill="#55ACEE"> <path d="M0,36.3461306 C0.803663004,36.4417973 1.62142857,36.4907387 2.45054945,36.4907387 C7.26336996,36.4907387 11.6928571,34.8346712 15.2086081,32.0564595 C10.71337,31.9727973 6.91959707,28.9779505 5.61245421,24.8624369 C6.23956044,24.9834054 6.88315018,25.0482297 7.54505495,25.0482297 C8.48205128,25.0482297 9.38956044,24.9217207 10.2516484,24.684955 C5.55201465,23.7334595 2.01117216,19.5466577 2.01117216,14.5276667 C2.01117216,14.4840811 2.01117216,14.4406802 2.01190476,14.397464 C3.3970696,15.1733243 4.98095238,15.6392838 6.66501832,15.693027 C3.90860806,13.8354685 2.09487179,10.6648018 2.09487179,7.07102252 C2.09487179,5.17264865 2.6014652,3.39321171 3.48571429,1.86328378 C8.55238095,8.13037387 16.1217949,12.2543829 24.6595238,12.6863604 C24.4844322,11.9282297 24.3934066,11.1375946 24.3934066,10.3257207 C24.3934066,4.60511261 28.9930403,-0.0328738739 34.6664835,-0.0328738739 C37.6210623,-0.0328738739 40.2908425,1.2251982 42.1648352,3.23844595 C44.5047619,2.77377928 46.7032967,1.91167117 48.6880952,0.724702703 C47.9210623,3.14351802 46.2923077,5.17357207 44.1712454,6.45565315 C46.2492674,6.20522072 48.2291209,5.6483964 50.0714286,4.82451802 C48.6941392,6.90185135 46.952381,8.72635135 44.9454212,10.1868378 C44.9652015,10.6310045 44.9750916,11.0777568 44.9750916,11.5269099 C44.9750916,25.2155541 34.6424908,41 15.7472527,41 C9.9459707,41 4.54615385,39.2852027 0,36.3461306 L0,36.3461306 Z" id="bird"></path> </g> </svg> <!-- <img src='https://i0.wp.com/img/twitter-icon.png' height="51" width="50" loading=lazy loading=lazy> --> </a> </p><p>Here's one of my SVG icons on the page, and you'll notice that my original PNG icon is still there, but it's commented out. it <a href="https://zhumor.ru/en/internet/izobrazhenie-v-formate-png-kak-otkryt-redaktirovat-i-konvertirovat-fail-formaty-izobrazhenii-sv.html">PNG image</a> and will be our fallback.</p><h2>Deleting comments</h2><p>I will remove the comments first. Gotta move <img>up and to the svg> element, just after the group containing the icon itself. Then I will wrap <img>in the SVG element called foreignObject. If the browser cannot understand the vector information of the SVG, then it will refer to an “external object” and will use <img>out of him. We also need to tell the browser to use the vector version if it's supported. And for this the element is used <switch>, in which I wrapped both the group and the foreignObject itself. And here is the updated code:</p><p> <a href="http://twitter.com/DavidDarnes" title="twitter profile"> <svg viewBox="0 0 50 41" version="1.1" xmlns="http://www.w3.org/2000/svg"> <switch> <g id="twitter-icon" fill="#55ACEE"> <path d="M0,36.3461306 C0.803663004,36.4417973 1.62142857,36.4907387 2.45054945,36.4907387 C7.26336996,36.4907387 11.6928571,34.8346712 15.2086081,32.0564595 C10.71337,31.9727973 6.91959707,28.9779505 5.61245421,24.8624369 C6.23956044,24.9834054 6.88315018,25.0482297 7.54505495,25.0482297 C8.48205128,25.0482297 9.38956044,24.9217207 10.2516484,24.684955 C5.55201465,23.7334595 2.01117216,19.5466577 2.01117216,14.5276667 C2.01117216,14.4840811 2.01117216,14.4406802 2.01190476,14.397464 C3.3970696,15.1733243 4.98095238,15.6392838 6.66501832,15.693027 C3.90860806,13.8354685 2.09487179,10.6648018 2.09487179,7.07102252 C2.09487179,5.17264865 2.6014652,3.39321171 3.48571429,1.86328378 C8.55238095,8.13037387 16.1217949,12.2543829 24.6595238,12.6863604 C24.4844322,11.9282297 24.3934066,11.1375946 24.3934066,10.3257207 C24.3934066,4.60511261 28.9930403,-0.0328738739 34.6664835,-0.0328738739 C37.6210623,-0.0328738739 40.2908425,1.2251982 42.1648352,3.23844595 C44.5047619,2.77377928 46.7032967,1.91167117 48.6880952,0.724702703 C47.9210623,3.14351802 46.2923077,5.17357207 44.1712454,6.45565315 C46.2492674,6.20522072 48.2291209,5.6483964 50.0714286,4.82451802 C48.6941392,6.90185135 46.952381,8.72635135 44.9454212,10.1868378 C44.9652015,10.6310045 44.9750916,11.0777568 44.9750916,11.5269099 C44.9750916,25.2155541 34.6424908,41 15.7472527,41 C9.9459707,41 4.54615385,39.2852027 0,36.3461306 L0,36.3461306 Z" id="bird"></path> </g> <foreignObject> <img src='https://i0.wp.com/img/twitter-icon.png' height="51" width="50" loading=lazy loading=lazy> </foreignObject> </switch> </svg> </a> </p><p>If you followed my instructions and also structured your HTML like I did, then your graphics should switch to the original bitmap if the browser doesn't support SVG icons.</p><h2>Creating an SVG Sprite</h2><p>SVG sprites work very similar to regular graphic sprites. In their simplest form, sprites are a collection of graphical elements combined into a single image. Each image is then selected using CSS and HTML, coordinates and a viewport.</p><p>Main advantages - <a href="https://zhumor.ru/en/internet/kak-uskorit-zagruzku-prilozhenii-iz-steam-nizkaya-skorost.html">accelerated loading</a> pages, more <a href="https://zhumor.ru/en/computer/kak-sdelat-udobnoi-rabotu-s-bolshim-kolichestvom-vkladok-v-brauzere-kak-vernut.html">comfortable operation</a> and persistence among page graphic elements. The second and third points apply very well to SVG sprites. Instead of multiple blocks of SVG code cluttering up the page, we'll have all the SVG-related code in one place, and it's very easy to update.</p><p>To begin, I will create <a href="https://zhumor.ru/en/computer/vindovs-10-propal-rabochii-stol-sozdanie-novogo-elementa-proverka.html">new element</a> <svg>in element <head>my page, just before the closing tag. This new SVG will contain all the icons that were previously on the page.</p><p> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title>

Then I need to place the icons there. I don't need to wrap the whole SVG, I just need the group element with its content. I can embed this in an element in the head of the file.

David Darnes - Web Designer & Front End Developer

Note: If you're comfortable using Grunt, here's a plugin that automates the merging of all individual SVG files.

Hide!

Now we have all the SVG icons in the head and we need to hide them; add the attribute display=”none” to the new svg> which means no icon will appear at the top of the page.

Defining each SVG icon

The next step is to define each icon so that we can use it on the page where we previously removed the defs element. With this tag to wrap all the groups, by wrapping all the icons accordingly, I can indicate that I want to reuse them anywhere on the page.

David Darnes - Web Designer & Front End Developer

How to use SVG icons

The icons are now defined, but we also need to specify a method for using them, and for this we will take the use element. Element allows you to take any element from and call it anywhere on the page. We select an element by its ID, so it was important to name the icons correctly back in the Sketch document. Look at the ID in the example above and how I refer to each using the element .

If you did everything like I did and didn't make any mistakes, you won't see any changes in how the graphics are rendered, but now you can reuse SVG icons (at whatever size you want) and call each one as many times as you like on the page.

Improving Our SVG Sprite

Another benefit to using SVG sprites is that the page code is much cleaner and easier to read for other people who are also working on the site. We can improve the result a little more. Below I have replaced the elements in my SVG sprite on the symbol element, plus I moved the viewbox attribute from the SVG elements on the page to the new symbol elements.

David Darnes - Web Designer & Front End Developer

Usage not only is it more semantically correct, in my example, but it also eliminates the need to repeat the viewbox attribute along with elements and . We can bring back the title and desc elements we removed earlier and use them to improve the accessibility of the icons. Note: Remember that the content of elements is displayed by default in IE7.

David Darnes - Web Designer & Front End Developer Twitter Twitter account Dribbble Dribbble portfolio GitHub GitHub account

By changing the group element to symbol. We can implement all these improvements. You can delete an element from an SVG sprite, making the code even cleaner.

Conclusion

Well, what started as simple raster icons has evolved into a super-powerful vector graphics set that can be easily applied where needed and in any size needed. I hope you found this tutorial useful and that you continue to experiment and create SVG icons in your next project.

Tags: , ,

Preparing an SVG for use on the web is a very simple process, no more difficult than exporting a JPEG or PNG. Use whatever image editor you're used to (Illustrator, Sketch, Inkscape [free], etc. [or even Photoshop if you're using shape layers]) at the image size you plan to use. I usually work in Illustrator, so I will explain some of the ways to prepare files in this program, but in general they are applicable to any other program. You might want to convert the text to outlines as the font will most likely not render correctly unless you plan to style them with the web font used on the page of course (which is possible!). It's also not a good idea to turn all objects into single shapes, especially if you have a stroke that you will need to control on the page, especially since converting objects often does not reduce the file size. Any names given to groups or layers will be added to the SVG as an element ID. This is pretty handy for styling, but will slightly increase the overall file size.

Before exporting, you need to check if all images are in an integer pixel grid (that is, for example, not 23.3px × 86.8px ). AT otherwise most likely the image will not have enough clarity and part of the image will be cut off. In Illustrator this can be done like this: Object > Artboards > Fit to Artwork Bounds . Then click save as and select SVG , and leave the default settings. There's a little bit of optimization to do here, but not really worth it, as we'll be applying various enhancements later on, so we won't waste time on those tweaks for now.

Techniques for reducing file sizes.

(See optimization)

To achieve the smallest SVG size, it would be logical to remove everything unnecessary from it. The most famous and useful program(at least I think so) for SVG processing it is SVGO . It removes all unnecessary code. But! Be careful using this program if you plan to manipulate SVG when CSS help/ JS , as it can clean up the code too much, making further changes difficult. The convenience of SVGO is also that it can be included in the automatic build process of the project, but you can also use GUI if you want.

Understanding in more detail with the correct removal of all unnecessary, we can do something else in graphics editor. First you need to make sure that you use as few paths/shapes as possible, as well as points on these paths. You can combine and simplify everything that can be simplified, and remove all unnecessary points. Illustrator has a VectorScribe plugin with the Smart Remove Brush Tool that will help you remove dots while still keeping the overall shape the same.

Pre-optimization

Smart Remove Brush Tool removed dots

Next, we will enlarge the image. In Illustrator, it is convenient to turn on the pixel grid view View > Pixel Preview and check how the paths are arranged. It will take a bit of time to place the paths on the grid, but the effort will pay off and result in a sharper rendering (it's better to pay attention to this in advance).

Points outside the grid

Grid alignment

If there are two or more objects to align, then it is worth removing all unnecessary overlaps. Sometimes, even if the contours are carefully aligned, a thin white line may be visible. To prevent this, you can slightly overlay objects on top of each other in places of overlap. Important: In SVG, z-index has a certain order that depends on the object that is on the bottom, so it's worth putting the top object at the bottom of the file in the code.

And finally, last but not least, something that is usually forgotten is to enable gzip compression of SVGs on your site in the .htaccess file.

AddType image/svg+xml svg svgz AddOutputFilterByType DEFLATE "image/svg+xml" \ "text/css" \ "text/html" \ "text/javascript" ... etc

As an example of how effective this technique is, I'll take the original Breaking Borders logo and optimize it this way: increase the size to what it should be; I will put in order the contours; I will delete the maximum possible number of points; move points by integer pixels; move all overlap areas and send it all to SVGO .

Original: 1,413b

After optimization: 409b

As a result, the file size became ~ 71% smaller (and ~ 83% smaller when compressed)

The icons you find on these resources can also be used to illustrate information in a slideshow, decorate Business Cards, menus, flyers and more.

We wrote that the icons on these sites are free, but still pay attention to the download conditions, as they can change at any time.

01. Smashing Magazine

22.PixelsMarket

26.Blugraphic

Blugraphic - PSD, PNG and vector icon options. The search is limited to tags, but you can subscribe to the newsletter and receive weekly free selection by email.

27 Icon Shock

Icon Shock is thousands of free icons for personal use. To use an image in a commercial project, you need to make a one-time payment.

28. CSS Author

CSS Author offers weekly selections of the best free icons on the web.

29. Creative Tail

Want fresh icons? There are kits on Creative Tail that you won't find anywhere else.

30. All-Free-Download

All-Free-Download offers easy search and direct downloads of PSD, PNG and vectors.

31.Ego Icons

Ego Icons offers over 1500 premium icons and 100 free vector icons. Visit also the subsites by clicking on the buttons on the top navigation bar.

32. Alien Valley

AlienValley offers a wide range of high quality icons in exchange for your email address.

33. Dreamtale

Dreamstale will provide you with great free premium icons with attribution.

34. DuckFiles

35. 1001 Free Downloads

1001 Free Downloads specializes in flat icons that come with a variety of beautiful and whimsical options.

36. Graphics Bay

37.Pixeden

On Pixeden, you can search for icons in several sizes. There is a wide selection from 16x16 to 512x512 in PNG format.

38. NounProject

NounProject is a convenient search, easy download and high quality icons. A link to the author is required. Membership with a monthly fee removes download restrictions.

39. Iconmonstr

Iconmonstr offers icons in several sizes without attribution.

40 Fusion plate

Internet