blog image

Lineicons Team

in Blog

Updated on: 10/24/2023

How to Use SVG Images on Website

For newbies, terms like SVG, PNG, gif, and all are references to image files. They see no difference between SVG Images and all other image formats and end up dumping their project with all kinds of image elements. The fact is that the obvious difference is just a zoom away.

Whereas, SVG stands for Scalable Vector Graphics. It is a popular image format due to its flexibility, scalability, and adaptability in web development. SVG images are vector-based, which means we can scale infinitely without losing quality, making it ideal for any resolution. They are also lightweight, enhancing website performance.

In this guide, we’ll get into the vast potential of SVG images and demonstrate how you can effectively utilize them on your various kinds of websites.

SVG: A Brief Overview

SVG is a vector image format designed for the web using XML. Unlike raster images like JPEG or PNG, SVGs comprise mathematically defined shapes, enabling resizing and manipulation without any loss of quality. SVGs contain a range of elements, such as paths, rectangles, circles, ellipses, and more, rendering them highly versatile for crafting complex graphics and animations.

On the other hand, SVG images are based on a shape and path algorithm and never pixelate no matter how large their size is increased. They are relatively less in memory than raster images.

Why to use SVG?

Why to use SVG Images

  1. Scalability: You can scale SVG up or down without pixelation or loss of quality, making them perfect for responsive web design.
  2. Small File Size: SVG files usually have a smaller size compared to raster images, contributing to faster website loading times.
  3. Editable and Customizable: You can easily edit SVGs using various graphic editing tools and manipulate them using CSS and JavaScript.
  4. SEO-Friendly: Search engines can index and search SVGs, contributing to SEO efforts.

 

Why SVG is a good replacement in 2023?

In 2023, SVG (Scalable Vector Graphics) remains a highly relevant and advantageous image format in web development. Unlike every other image file, SVG files are not based on pixels and are extremely small in size.  To be more precise, we have two types of image files. Raster images and vector images. Raster images are based on pixels. They are large in memory when compared to SVG images, and also pixelate when we zoom in.

There are practically a plethora of advantages to using vector images in our projects, and even in our daily tasks.

Advantage of Using SVG images on Website

Here are several reasons why SVG is a good replacement :

  1. Scalability without Loss of Quality: SVGs are vector-based, allowing them to scale indefinitely without a loss of quality.
  2. Small File Sizes: SVGs are typically much smaller in file size compared to bitmap image formats like JPEG, PNG, or GIF, especially for simple graphics and icons.
  3. SEO Benefits: SVGs are part of the HTML document, making them accessible to search engines for indexing.
  4. Support for Animation and Interaction: SVGs support animations and interactivity through CSS and JavaScript. This allows for engaging user experiences, such as hover effects, transitions, and interactive graphics.
  5. Editable and Maintainable: SVGs can be easily edited and maintained using code or vector graphic editors. Developers can modify SVGs directly within the HTML code.
  6. Support for Complex Graphics: SVGs support complex graphics and complex visual elements, making them suitable for logos, illustrations, data visualizations, and other complicated design components.
  7. Compatibility with Modern Technologies: SVGs can seamlessly integrate with modern web technologies and frameworks like React, Angular, Vue.js, and more.

In conclusion, SVGs offer benefits such as scalability, small file sizes, SEO advantages, interactivity, accessibility, and compatibility, making them a versatile and efficient image format. As web development trends grow, SVG remains a good replacement for traditional image formats in 2023 and beyond.


In this article, we’ll focus on the specifics of integrating SVGs into different platforms and frameworks, making them an integral part of your web development journey.

How to Use SVG on an HTML Website

HTML(HyperText Markup Language) is the foundation of any web page. Let’s explore how you can seamlessly integrate SVG into your HTML website. It’s a straightforward process and offers several advantages.

1. Inline SVG

The easiest way to use SVG on an HTML website is by using inline SVG. This involves inserting the SVG code directly into your HTML file using the SVG element.
Code to use Inline SVG Images
In this example, we’ve created an SVG element with a circle inside. The cx and cy attributes define the centre of the circle, and r defines the radius. The fill attribute sets the fill colour.

2. External SVG File

we can also use the <img> tag to link to external SVG images. This method proves useful for reusing SVGs across multiple pages.

Code to use External SVG

Replace path/to/your-svg-file.svg with the actual path to your SVG file.

3. SVG <use> Element

The <use> element allows you to reuse an SVG shape by referencing it.

Code to use SVG Images Using USE tag

In this example, we’ve referenced an SVG file with an id of “circle” using the <use> element.

These methods allow you to effectively use SVG within your HTML website, providing the benefits of scalability and flexibility that SVG offers.

Let’s proceed with the next section i.e. on “How to use SVG in different CMS“.


How to Use SVG on a WordPress Site

WordPress is a widely used content management system (CMS) that allows for the integration of SVG images into your website. Incorporating SVGs in a WordPress site can enhance its visual appeal and optimize load times due to SVG’s scalability and smaller file size. Let’s explore how to utilize SVGs effectively on a WordPress website.

Use SVG on a WordPress Website

1. Using the WordPress Block Editor (Gutenberg)

The WordPress Block Editor, also known as Gutenberg, allows for easy insertion of SVGs into your posts or pages.

Create a New Post or Page

Add a Block for SVG:  Click on the “+” icon to add a new block, then search for the “Custom HTML” block. Add the SVG code to this block.

<svg width="100" height="100">
<circle cx="40" cy="40" r="50" fill="red" />
</svg>

Preview or Publish: Preview or publish your post/page to see the SVG in action.

2. Using an SVG Plugin

If you prefer a plugin-based approach, you can utilize various WordPress plugins to handle SVG integration.

  • Install a Plugin: From your WordPress dashboard, go to Plugins > Add New and search for SVG plugins. Install and activate a suitable plugin, such as “Safe SVG.
  • Upload SVG Images via Plugin: Once the plugin is activated, you can upload SVGs directly through the WordPress Media Library. The plugin will handle the security aspects of SVGs.

3. Direct Embedding in the Theme Files

For developers or those comfortable with modifying theme files:

  • Access Theme Files: Access your WordPress theme files, usually located in wp-content/themes/your-theme-name.
  • Insert SVG Code: Embed the SVG code directly in the PHP files where you want the SVG to appear. This is usually in theme template files (e.g., header.php, footer.php).
  • <svg width="100" height="100">
    <circle cx="50" cy="50" r="40" fill="red" />
    </svg>
  • Save and Preview: Save the file, and preview your website to see the SVG.

4. FTP Way:

Using FTP involves directly uploading SVG files to your server.

Access via FTP: Use an FTP client like FileZilla to connect to your server.

Navigate to Upload Folder: Navigate to the upload directory to upload the SVG file (e.g., wp-content/uploads/).

Upload SVG File: Simply drag and drop the SVG file from your local computer to the upload directory.

Use SVG: Once uploaded, you can use the SVG in the content by using the appropriate URL in a <img> tag.

<img src="<http://website.com/wp-content/uploads/svg-file.svg>" alt="SVG Image" />

Replace http://website.com/wp-content/uploads/svg-file.svg with the correct URL to your SVG file.

Note: Make sure that you only upload SVGs from trusted sources and verify they do not contain any harmful code or scripts (e.g., JavaScript) that could potentially pose security threats.

Choose the method that best fits your needs and comfort level with working within the WordPress environment or directly with server files via FTP. All the approaches are valid and achieve the goal of using SVGs in your WordPress site.

Using SVG on WordPress has some security issues as anything can be dumped into the code that would turn out to be malicious. So, you cannot always rely on SVGs that don’t come from a reliable source. However, SVG can aid you in SEO as the text in these images is accessible. If you would like to learn more and step by step using SVG on WordPress you may follow this tutorial by WPbeginner.


How to Use SVG Images on a Drupal Website

Drupal, a robust and flexible content management system, allows for the seamless integration of SVG images into your website. SVGs, with their scalability and small file sizes, are an excellent choice for enhancing visual elements on your Drupal site. Let’s get into how you can effectively use SVGs on a Drupal website.

1. Uploading SVG Images

Drupal provides a straightforward process to upload SVG files to your site.

  • Open Drupal Dashboard: Access your Drupal site and log in to the dashboard.
  • Navigate to Media Library: Go to Structure > Media Library.
  • Upload SVG: Click on the “Upload” button to upload your SVG file to the media library.

2. Using SVG in Content

Once the SVG is uploaded to the media library, you can easily use it within your content.

  • Create or Edit Content: Create a new page or edit an existing one where you want to insert the SVG.
  • Insert SVG using CKEditor: Use the CKEditor to insert the SVG into your content. Click on the “Image” icon and select the uploaded SVG from the media library.
  • Customize Attributes: Customize attributes such as width, height, and alt text.

3. Using SVG in Theme Files

For more advanced users or developers who want to directly embed SVGs into their theme files:

  • Access Theme Files: Access the Drupal theme files, usually located in themes/theme-name.
  • Insert SVG Code: Embed the SVG code directly into the PHP files where you want the SVG to appear.
  • <svg width="100" height="100">
    <circle cx="60" cy="60" r="50" fill="red" />
    </svg>
  • Save and Preview: Save the file, and preview your Drupal website to see the SVG.

Drupal offers various methods to integrate SVGs into your website. Choose the approach that aligns with your needs, and utilize SVG’s scalability and lightweight nature to enhance the visual elements.

Next, let’s explore the way to use SVG on the Wix Website.


How to Use SVG Images on the Wix Website

How to Use SVG Images on Wix

Wix is a popular website-building platform that allows users to create stunning websites with ease. Integrating SVG images into your Wix website can enhance its visual appeal and improve performance. Here’s a guide on how to use SVG on a Wix website.

1. Uploading SVG Files to Wix

Log in to Your Wix Account: Log in to your Wix account and access your Wix dashboard.

Using Media Manager:

  • Go to your Media Manager.
  • Click Upload Media.
  • Select where you want to add the media from

Using HTML iframe:

  • Go to the Editor: Navigate to the Editor to access the website you’re working on.
  • Add an SVG Element: In the Editor, click on “Add” and choose “More” to add an HTML iframe.
  • Paste SVG Code: Paste the SVG code directly into the HTML iframe.
  • <svg width="100" height="100">
    <circle cx="60" cy="60" r="40" fill="yellow" />
    </svg>

Adjust the width, height, and other attributes to customize the appearance of your SVG.

2. Using SVG images on your site:

  • Access the Wix Media manager in the Editor.
  • Click the SVG image you want to add to your site.
  • Click on Add to Page.

3. Using SVG as a Background

  • Add a Section or Element: Add a section or element where you want to use the SVG as a background.
  • Customize the Section/Element: Customize the section/element and set the SVG as the background.

Wix provides intuitive ways to integrate SVGs into your website. Whether you want to use SVGs as standalone images, backgrounds, or icons, Wix offers the flexibility to do so seamlessly.

Next, let’s discuss the way to use SVG on Webflow.


How to Use SVG on Webflow

How to Use SVG Images on Webflow

&nbsp;

Webflow is a popular web design and development platform that allows for seamless integration and usage of Scalable Vector Graphics (SVG) in your web projects. Here’s a step-by-step guide on how to use SVG on Webflow.

Webflow allows you to upload SVG files and use them in various elements of your design.

1. Uploading SVG to Webflow

  • Access Webflow Editor: Log in to your Webflow account and go to the Webflow Editor for your project.
  • Upload SVG: Navigate to the Assets panel. then click on the “Upload” and select the SVG file you want to use.

2. Insert SVG into Your Design

  • Insert SVG as an Image: Drag an Image element onto your canvas where you want to use the SVG. Select the Image element and click on the image icon in the element settings. Choose the uploaded SVG from the assets.
  • Insert SVG as Code: Drag an Embed element onto your canvas where you want to use the SVG. Double-click the Embed element to open the code editor and paste the SVG code directly.

3. Style SVG: Style the SVG using Webflow’s styling options such as colours, dimensions, and positioning.

4. Optimize SVG: Optimize SVG files for the web by removing unnecessary metadata, comments, and whitespace to reduce file size.

5. Preview: Test your Webflow project to ensure the SVGs are displayed correctly and are responsive.

By following these steps, you can effectively use SVG images in your Webflow project, enhancing visual appeal and scalability while utilizing Webflow’s design and customization features. Whether you choose to embed SVG as an image or directly as code, Webflow provides the flexibility to seamlessly integrate SVGs into your web designs.

Next, let’s discuss the way to use SVG on Sanity.


How to Use SVG on Sanity

How to Use SVG Images on Sanity.io

Sanity is a headless content management system (CMS) that allows for flexible content creation and dynamic content delivery. Integrating SVG images into your Sanity-powered website can enhance its visual appeal and offer a dynamic user experience.

Let’s explore how to effectively use SVG on a Sanity-powered website.

1. Using SVG in Content

You can easily use SVG within your content, just by uploading SVG as used to upload normal images.

  • Create a New Document or Edit an Existing One: Create a new document or edit an existing one where you want to insert the SVG.

SVG Image option on Sanity

  • Insert SVG using the image button: Use an image button and insert the SVG using the image toolbar or by directly embedding the SVG code.
  • Customize Attributes: Customize attributes such as width, and height as required.

2. Using SVG in Your Website

  • Fetch SVG Data: Depending on your website setup, fetch the SVG data from Sanity using the Sanity API.
  • Render SVG in Your Website: Use the fetched SVG data to render the SVG on your website.

Sanity’s flexibility allows you to seamlessly integrate SVGs into your website, making use of the powerful features it offers for content management and delivery.

Next, let’s discuss the way to use SVG on different JavaScript Frameworks like React, Next.js, Vue.js Angular.js.


How to Use SVG Images on a React Site

React, a popular JavaScript library provides a powerful way to integrate SVG into your web applications. SVGs can be easily used as components within React, offering flexibility and ease of customization.

Let’s explore how to effectively use SVG on a React site.

1. Importing SVG Files

  • Store SVG Files in Your Project: Store your SVG files in a folder within your React project, e.g., src/assets/svg.
  • Import SVG File: Import the SVG file as a React component.

How to Use SVG Images on React Website

2. Using SVG as a Component

  • Insert SVG Component: Use the SVG component in any other React component.

Using SVG as React Component

3. Passing Props to SVG Components

  • Customize SVG Appearance: Pass props to your SVG components to customize their appearance dynamically.
  • <MyLogo fill="blue" width="50" height="50" />

4. Styling SVG Components

  • Style Using CSS: Style the SVG components using CSS classes.
  • .MyLogo {
    fill: red;
    }
  • Inline Styles: Alternatively, use inline styles.
  • <MySVG style={{ fill: 'green' }} />

React simplifies the process of using SVG on your website by treating SVGs as components, allowing for easy integration and seamless rendering.

Next, let’s discuss the way to use SVG on  Next.js websites…


How to Use SVG on the Next.js Site

Next.js, a popular React-based web framework, offers a straightforward approach to integrating SVGs into your web application. SVGs can be easily used as components within Next.js, providing scalability and ease of use.

Let’s explore how to effectively use SVG on a Next.js site.

1. Importing SVG Files

  • Store SVG Files in Your Project: Store your SVG files in a folder within your Next.js project, e.g., App/assets/svg/.
  • Import the SVG File: Import the SVG file as a component in your React file.
  • import YourLogo from './assets/svg/your-Logo-file.svg';

2. Using SVG Components

  • Use the SVG Component: Use the SVG component within your React component

Using SVG images as Next.js Component

3. Passing Props to SVG Components

  • Customize SVG Appearance: Pass props to your SVG components to customize their appearance dynamically.
  • <YourLogo fill="blue" width={50} height={50} />

4. Styling SVG Components

  • Style SVG Components: Style the SVG components using CSS or inline styles.
  • .YourLogo {
    fill: red;
    }
  • Inline styles:
  • <YourLogo style={{ fill: 'green' }} />

Next.js simplifies the process of using SVG on your website by treating SVGs as components, allowing for easy integration and seamless rendering.

Next, let’s discuss the way to use SVG Images in  Vue.js …


How to Use SVG on Vue.js

Vue.js, a progressive JavaScript framework, provides a convenient way to use SVG images as components. Treating SVGs as components allows for efficient management, customization, and styling.

Let’s explore how to effectively use SVG Images on a Vue.js application.

1. Importing SVG Files

  • Store SVG Files in Your Project: Store your SVG files in a folder within your Vue.js project, e.g., src/assets/svg.
  • Import SVG File: Import the SVG file as a component in your Vue component.
  • import YourLogo from '@/assets/svg/your-logo-file.svg';

2. Using SVG Components

  • Use the SVG Component: Use the SVG component within your Vue component.

How to Use SVG Images on Vue.js

3. Passing Props to SVG Components

  • Customize SVG Appearance: Pass props to your SVG components to customize their appearance dynamically.
  • <YourLogo fill="blue" width={50} height={50} />

4. Styling SVG Components

  • Style SVG Components: Style the SVG components using CSS or inline styles.
  • .YourLogo {
    fill: red;
    }
  • Inline styles:
  • <YourLogo style={{ fill: 'green' }} />

Vue.js’s component-based approach allows for efficient management and utilization of SVGs within your Vue.js project, enabling seamless integration, customization, and styling.

Next, let’s discuss the way to use SVG Images in  Angular.js …


How to Use SVG on Angular.js

AngularJS, a widely used JavaScript framework, allows for the integration of SVG images and their dynamic usage within applications. Using SVG in an AngularJS application involves treating SVGs as regular DOM elements and leveraging AngularJS features for dynamic updates.

Let’s explore how to effectively use SVG Images on an AngularJS application.

1. Importing SVG Files

  • Store SVG Files in Your Project: Store your SVG files in a folder within your AngularJS project, e.g., assets/svg.
  • Import SVG File: Import the SVG file or use it directly in your HTML.

Importing SVG File in Angular.js

2. Using SVG in HTML

  • Insert SVG Directly: Include the SVG directly in your HTML file using the <svg> element.

Using SVG image code

3. Dynamically Manipulating SVG

  • Bind SVG Attributes: Use AngularJS data binding to dynamically update SVG attributes based on your application state.

Angular SVG image code

4. Using AngularJS Controller

  • Create an AngularJS Controller: Define an AngularJS controller to manage the SVG data and interactions.

Angular SVG image Controller

5. Optimize SVG

  •  Reduce SVG file size using online tools to improve website performance.

AngularJS provides a powerful platform to use SVG within your web application. By treating SVGs as regular DOM elements, you can dynamically manipulate them, allowing for seamless integration and dynamic updates.

Next, let’s discuss the way to use SVG Images in design tools like Canva & Figma.


How to Use SVG on Figma

Figma is a popular cloud-based design tool that enables collaborative designing and prototyping. While Figma primarily focuses on vector graphics, it does not natively support SVG export directly from its design files. However, you can still use SVG in your Figma projects and eventually export them.

How to Use SVG Images on Figma

Here’s a guide on how to utilize SVG in Figma:

1. Import SVG into Figma

Figma allows us to import SVG files into our projects, which can be used as vector elements, To import:

  • Open or Create a Figma Project: Log in to Figma and create a new project or open an existing one.
  • Import SVG: Use the Menu > File > Place Images > File Explorer.. option to import your SVG file.

Use SVG Images on Figma

2. Edit and Customize SVG

  • Select and Edit: After importing the SVG, you can select and manipulate it using Figma’s editing tools and features.
  • Modify Shapes and Colors: Use Figma’s editing tools to modify the shapes, colours, and other properties of the SVG.

3. Export SVG from Figma

  • Select the SVG Element: Select the SVG element you want to export.
  • Export as SVG: Use the Menu> File > Export ... option to export the selected element as SVG.

4. Optimize SVG (Optional)

  • Optionally, you can optimize the exported SVG using online SVG optimization tools to reduce the file size.

5. Use SVG in Your Web Projects

  • After exporting the SVG file from Figma, you can directly use it in your projects.

While Figma is primarily a design tool, it also streamlines the use of SVGs by allowing them to import, edit, and export for web development purposes.

Next, let’s discuss the way to use SVG Images in  Canva.


How to Use SVG on Canva

How to Use SVG Images on Canva

Canva is a popular online design tool that allows us to create a wide range of graphic designs, presentations, social media posts, and more. Canva is not built for creating or editing SVG files, still, you can utilize SVGs within your Canva designs by importing and exporting them.

Here’s a guide on how to use SVG on Canva:

1. Importing SVG into Canva

  • Create a Design: Log in to Canva and create a new design or select an existing one that you want to work on.
  • Upload SVG: Click on the “Uploads” tab in the left-hand toolbar. Select “Upload an image or video” and now choose the SVG file you want to import.

2. Editing and Customizing SVG

  • Drag and Drop SVG into Your Design: Once the SVG is uploaded, drag and drop it onto your design canvas.
  • Edit and Customize: Resize, rotate and customize the SVG using Canva editing tools.

3. Export SVG from Canva

How to Export SVG image from canva

  • Locate the “Share” button in the top right corner of the Canva.
  • After clicking the “Share” button, the option will appear. Now Click on the Download button and select the “SVG” option among the available download formats.
  • Once you’ve chosen the SVG option, click on the “Download” button to download SVG images.

4. Use SVG in Your Web Projects:

Use the exported SVG in your web projects by embedding it directly in your HTML or CSS, or by using it as a file.

By following these steps, you can easily use SVG in your designs within Canva and then integrate them into your web projects for a more visually appealing experience.

While Canva is not mainly an SVG editing tool, you can still use SVGs by importing them, customizing them within Canva, and then exporting or converting them for use in web development.


Summary

So far, we’ve explored how Scalable Vector Graphics (SVG) offers many benefits such as scalability, smaller file sizes, and easy customization. We have Integrated SVG into various platforms and frameworks for the creation of visually appealing and performance-optimized web applications.

In this comprehensive guide, we explored how to use SVG on different platforms and frameworks:

HTML Websites: SVG can be seamlessly integrated into HTML using inline SVG, linking external SVG files, or using the <use> element.

Content Management Systems (CMS):

  • WordPress: Utilize plugins or directly embed SVG code into posts or pages.
  • Drupal: Upload SVG files to the media library and use them within content or directly in theme files.
  • Wix: Upload SVGs to the Wix media library and use them as images or backgrounds.
  • Sanity: Utilize SVGs by uploading them to content and rendering them on the website.

JavaScript Frameworks:

  • React: Use SVG as a component, allowing for easy integration and dynamic customization.
  • Next.js: Import SVG files and use them as components in your Next.js application.
  • Vue.js: Import and use SVG as components, enabling seamless integration and dynamic styling.
  • Angular.js: Treat SVGs as regular DOM elements, dynamically manipulating and using them in Angular.js applications.

Design Tools:

  • Figma: Import and edit SVGs within Figma, then export them for use in web development.
  • Canva: Utilize SVGs by importing and customizing them, then convert or use them in your web projects.

Understanding how to effectively use SVG on these platforms and frameworks empowers web developers and designers to enhance the visual appeal, performance, and scalability of their websites and applications.

Before concluding this guide, let’s get into an important decision: “Which one to choose, Icon fonts or SVG?”


Icon Fonts or SVG?

Well, icon fonts have been a great replacement for raster images to be used on websites. They added a great performance boost to the sites by contributing to the reduction of loading time.

However, they had their downsides. For example, the icon sets come with a lot of icons that are redundant and never used. They just take up space. Also, they make additional HTTP requests, and sometimes browser fails to interpret them. That’s where vector images prove to be a decent alternative. SVG icons can be added to the site inline for flexibility in customization instead of putting them within the tag.

Though icon fonts are almost as flexible as SVG, vector images have some additional options like multi-coloured icons. Positioning the SVG is a piece of cake when compared to Icon Fonts that require a lot of aligning.

Likewise, there are a lot of reasons why SVG is quite a replacement for Icon Fonts and there is no wonder that developers are moving to SVG.

Still, Icon Fonts are not obsolete yet. SVG is not cached by browsers normally, but Icon Fonts are. Hence, the loading time is somewhat less when it comes to Icon Fonts.

If your site requires a lot of images, then it will be wise for you to go with Icon Fonts rather than SVG. Please follow our documentation to check the step-by-step usage guide with examples of using icon fonts.

At the end of the day, it’s your requirements that matter. Everything comes with its own advantages and disadvantages.

Share This Post