1

Please help me to find the issue why svg linear gradient is not working with react

     <svg width='258' height='229' viewBox='0 0 258 229' >
        <defs>
            <lineargradient x1='.258%' y1='49.75%' x2='101.258%' y2='49.75%' id='bgGradient'>
                <stop stopColor='#3023AE' offset='0%' />
                <stop stopColor='#53A0FD' offset='47.525%' />
                <stop stopColor='#B4EC51' offset='100%' />
            </lineargradient>
        </defs>
        <g id='Page6' fill='none' fillRule='evenodd' strokeLinecap='round'>
            <path d='M10.1757812,18.984375 C183.016927,-13.7135417 261.63151,52.9101563 246.019531,218.855469'
            id='Path7' stroke='url(#bgGradient)' strokeWidth='20' />
        </g>
    </svg>
Achyut Kr Deka
  • 739
  • 1
  • 8
  • 18

2 Answers2

4

This is a syntax error:

  • linearGradient NOT lineargradient

If this is generated SVG (and not a React Template - it's not clear what you're showing here) - you should be using SVG syntax, not React syntax. AKA:

  • stop-color NOT stopColor
  • stroke-width NOT strokeWidth
  • fill-rule NOT fillRule
  • stroke-linecap NOT strokeLinecap

In SVG, attribute names are generally lowercase and dashed, element names are Camel cased and concatenated. The one exception is with filter primitive attributes - which confusingly - are also Camel case (e.g tableValues)

Michael Mullany
  • 30,283
  • 6
  • 81
  • 105
1

I'll add to the list of syntax errors Michael Mullany's

  • stop offset NOT offset

Seemingly minor mistake, but no corrections code not working

In the end, after all errors have been corrected, - working code

 <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width='258' height='229' viewBox='0 0 258 229' >
       <defs>
 
  <linearGradient   x1='.258%' y1='49.75%' x2='101.258%' y2='49.75%' id='bgGradient' > 
  
                <stop offset='47.525%'  stop-color='#3023AE'  />
                <stop offset='47.525%' stop-color='#53A0FD'  /> 
    <stop offset='100%' stop-color='#B4EC51'  /> 
    </linearGradient>
</defs>
        <g id='Page6' fill='none' fill-rule='evenodd' stroke-linecap='round'>
            <path d='M10.1757812,18.984375 C183.016927,-13.7135417 261.63151,52.9101563 246.019531,218.855469'
            id='Path7'  stroke-width='20'  stroke="url(#bgGradient)" />
        </g>
 </svg>
Alexandr_TT
  • 13,635
  • 3
  • 27
  • 54