Search code examples
javascriptcssreactjsstyled-components

React Styled Components - Gradient


How can I add css gradient to styled component?

background: radial-gradient(50% 50%, circle cover, red 0, blue 100%);

Solution

  • Gradients in styled-components are the same as in regular CSS, but your gradient syntax seems to be invalid – for example the cover keyword was only in early browser implementations many years ago. Try this instead:

    background: radial-gradient(circle at center, red 0, blue 100%);
    

    Read Using radial gradients on MDN for more details.

    Also, DevTools (right click > inspect element) will tell you when there is something wrong with your styles:

    enter image description here