Write a text with a color gradient

Today I offer you a CSS tip. In CSS, gradients are very popular, they allow a clean and pretty design. It also happens that we want to use the “color” property to apply a gradient to a text, unfortunately at the moment this feature is not supported by …


This content originally appeared on DEV Community and was authored by Clément Gaudinière

Today I offer you a CSS tip. In CSS, gradients are very popular, they allow a clean and pretty design. It also happens that we want to use the "color" property to apply a gradient to a text, unfortunately at the moment this feature is not supported by web browsers. That's why I propose you a simple tutorial to apply a linear gradient to a text.

You can see below the final result:

default-tab

To do this, we will use "webkit" extensions. First of all we will add "-webkit-background-clip" which will allow to apply a gradient to the text.
Learn more...

Then we will add this property: "-webkit-text-fill-color" which allows to define the color used to draw the content of the letters.
Learn more...

Finally, we will apply the gradient with the property: "background", which is a fundamental property of CSS.

The complete code :

<!DOCTYPE html>
<html>
  <head>
    <style>
      h1 {
       font-size: 72px;
       background: -webkit-linear-gradient(350deg, #22c1c3, #fd2df5);
       -webkit-background-clip: text;
       -webkit-text-fill-color: transparent;
       text-align: center;
      }
    </style>
  </head>

  <body>

    <h1>Text Gradient </h1>  

  </body>

</html>


This content originally appeared on DEV Community and was authored by Clément Gaudinière


Print Share Comment Cite Upload Translate
APA
Clément Gaudinière | Sciencx (2022-09-26T20:51:20+00:00) » Write a text with a color gradient. Retrieved from https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/.
MLA
" » Write a text with a color gradient." Clément Gaudinière | Sciencx - Sunday May 2, 2021, https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/
HARVARD
Clément Gaudinière | Sciencx Sunday May 2, 2021 » Write a text with a color gradient., viewed 2022-09-26T20:51:20+00:00,<https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/>
VANCOUVER
Clément Gaudinière | Sciencx - » Write a text with a color gradient. [Internet]. [Accessed 2022-09-26T20:51:20+00:00]. Available from: https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/
CHICAGO
" » Write a text with a color gradient." Clément Gaudinière | Sciencx - Accessed 2022-09-26T20:51:20+00:00. https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/
IEEE
" » Write a text with a color gradient." Clément Gaudinière | Sciencx [Online]. Available: https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/. [Accessed: 2022-09-26T20:51:20+00:00]
rf:citation
» Write a text with a color gradient | Clément Gaudinière | Sciencx | https://www.scien.cx/2021/05/02/write-a-text-with-a-color-gradient/ | 2022-09-26T20:51:20+00:00
https://github.com/addpipe/simple-recorderjs-demo