Alex Shul
Alex Shul

Reputation: 500

SVG with radialGradient not work in browsers

Problem:

The following svg code not work in browsers:

<svg width="207" height="209" viewBox="0 0 207 209" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path fill-rule="evenodd" clip-rule="evenodd" d="M96.2318 8.29356C149.379 4.30837 195.684 44.2918 199.657 97.599C203.631 150.906 163.767 197.351 110.62 201.336C57.473 205.321 11.1677 165.338 7.19452 112.031C3.2213 58.7234 43.0847 12.2787 96.2318 8.29356Z" stroke="url(#paint0_angular)" stroke-width="2"/>
    <defs>
        <radialGradient id="paint0_angular" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="translate(103.426 104.815) rotate(-94.2626) scale(96.7891 96.5016)">
            <stop stop-color="#FF7870"/>
            <stop offset="1" stop-color="#FF7870" stop-opacity="0"/>
        </radialGradient>
    </defs> 
</svg>

If replace stroke atribute in path fragment of svg with simple color (for example #f00) - it works, but with radial gradient - not works.


Question:

  1. Is there a way to make this svg valid for browsers?

OR

  1. Is there a way to make this element with HTML & CSS?

All information, that I've found not solves the problems, because:


P. S. Expected view of svg:

expected view of svg

Upvotes: 1

Views: 1575

Answers (1)

Temani Afif
Temani Afif

Reputation: 272723

You can do this using mask and conic-gradient

.box {
  width: 200px;
  height: 200px;
  margin: 20px auto;
  border-radius: 50%;
  background: conic-gradient(#0000, red);
  -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - 10px), #000 calc(100% - 9px));
          mask: radial-gradient(farthest-side, #0000 calc(100% - 10px), #000 calc(100% - 9px));
}

body {
  background: url(https://picsum.photos/id/100/1000/1000) center/cover;
}
<div class="box">

</div>

CSS border conic gradient

Upvotes: 3

Related Questions