Home > Web Front-end > CSS Tutorial > How Can I Embed SVG Images Directly into My CSS Using Inline Definitions?

How Can I Embed SVG Images Directly into My CSS Using Inline Definitions?

Patricia Arquette
Release: 2024-12-09 20:52:10
Original
829 people have browsed it

How Can I Embed SVG Images Directly into My CSS Using Inline Definitions?

Incorporating Inline SVG Images into CSS

CSS provides a convenient method to integrate Scalable Vector Graphics (SVGs) directly within its codebase using inline definitions. This technique allows developers to embed SVG graphics as background images or other design elements.

Usage

To embed an inline SVG image in CSS, use the following syntax:

/* Class with inline SVG background image */
.my-class {
  background-image: url("data:image/svg+xml;utf8,
    <svg xmlns='http://www.w3.org/2000/svg' width='...' height='...'>
      ...
    </svg>");
}
Copy after login

Example

Consider the following example:

body {
    background-image: url("data:image/svg+xml;utf8,
      <svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'>
        <linearGradient>
Copy after login

In this example, an inline SVG definition creates a colorful gradient background that spans the entire page. The inline SVG contains a linearGradient to define a color gradient and a rect filled with the gradient.

The above is the detailed content of How Can I Embed SVG Images Directly into My CSS Using Inline Definitions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template