Home  >  Q&A  >  body text

Fill SVG path elements with a background image

Is it possible to set background-image for an SVG <path> element?

For example, if I set the element class="wall", the CSS style .wall {fill: red;} works, but .wall{background-image : url(wall.jpg)} is not available, nor is .wall {background-color: red;}.

P粉021553460P粉021553460285 days ago328

reply all(1)I'll reply

  • P粉998100648

    P粉9981006482024-01-29 00:10:37

    You can do this by setting the background to a pattern:

    
      
        
      
    

    Adjust the width and height according to your image and then reference it from the path like this:

    Working example

    reply
    0
  • Cancelreply