Home >Web Front-end >CSS Tutorial >How to Add a Background Image to an SVG Circle Without a Black Fill?

How to Add a Background Image to an SVG Circle Without a Black Fill?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-17 09:49:26206browse

How to Add a Background Image to an SVG Circle Without a Black Fill?

How to Add a Background Image to an SVG Circle Shape (Without Filling It Black)

Creating an SVG circle with an image background is possible using SVG patterns. Here's how to implement it:

Problem:

The following SVG code attempts to add a background image to a circle but instead fills the circle with black:

<circle ... fill="url('images/word-cloud.png')"/>

Solution:

To use an image fill, SVG patterns are employed:

<svg ...>
  <defs>
    <pattern>

Explanation:

  • Define a element within the tag, specifying its coordinates and dimensions.
  • Embed the image using the element within the pattern.
  • Reference the pattern's ID using the fill attribute on the circle to apply the background image.
  • Example:

    Adding a background image to a circle with ID "top":

    <svg ...>
      <defs>
        <pattern>

    The above is the detailed content of How to Add a Background Image to an SVG Circle Without a Black Fill?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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