Apply gradient color to text
Quick Answer
Apply a `background` gradient, then set `background-clip: text` and `-webkit-text-fill-color: transparent` to reveal the gradient through the text shape.
1.gradient-text {
2 background: linear-gradient(to right, #667eea 0%, #764ba2 100%);
3 -webkit-background-clip: text;
4 -webkit-text-fill-color: transparent;
5 background-clip: text;
6}CSS gradient text works by applying a gradient as the background of the element and then clipping it to the text shape using background-clip: text and making the text color transparent so the background shows through. This technique is widely supported and produces sharp, scalable gradient text at any font size.
Yes — the text is real DOM text so it is selectable, copyable, and readable by screen readers. Ensure sufficient contrast between the lightest gradient colour and the background for WCAG compliance.
This free css code snippet for gradient text is production-ready and copy-paste friendly. Whether you are building a web app, API, or frontend interface, this beginner-level example will help you implement gradient text quickly and correctly.
All snippets in the Snippetly library follow css best practices and are tested for real-world use. You can adapt this code to work with React, Vue, Node.js, or any project that uses css.
Organise your team's code snippets with Snippetly. Share knowledge and boost productivity across your organisation.