Currently I'm working on a little project and want to know how to add gradient to text using JavaScript like in CSS.
Asked
Active
Viewed 204 times
-3
-
Take a look here: https://codepen.io/search/pens?q=text%20gradient&page=1&order=popularity&depth=everything – Nir Tzezana Mar 17 '19 at 10:08
-
Have you already tried something on you own to solve it? – joka00 Mar 17 '19 at 10:14
1 Answers
0
Adding gradient to text using JS is as same as adding it using CSS
According to CSS written on CSS Tricks it's possible to add in JS using this code
const h1 = document.getElementsByTagName('h1')[0];
h1.style.background = 'linear-gradient(#eee, red)';
h1.style.webkitBackgroundClip = 'text';
h1.style.webkitTextFillColor = 'transparent';

joka00
- 2,357
- 1
- 10
- 27