Multi colored text in CSS
Multi colored gradient text is becoming increasingly popular all over the web. In the past, mutli colored text required static images, but now it can easily be done with CSS rather than photoshop. The great thing about doing this in CSS is it keeps the text as text - so it can still be indexed by search engines.
Creating multi colored text in CSS
To make colorful text with just CSS we'll create a few different text gradients. Here are a few examples below:
A New Startup
How do CSS Text Gradients work?
It might surprise you to know that CSS gradient text is actually done through an unstandardized set of webkit CSS properties. These properties have become so pervasive on the web, that even Firefox supports them now.
Since most other browsers are largely chromium based, gradient text has very broad support in all modern web browsers for a set of non-standardized properties. Worried about older browsers? Since these are webkit properties, older browsers just ignore them, so you don't need to worry much about support.
That means those who can see gradient text, do, and those that cannot, just see the normal text color. Easy!
Adding Gradient Text
To add gradient text, we need to add the following CSS:
background-image: linear-gradient(225deg, #28d8ff, #032eff);
filter: drop-shadow(0 20px 30px #28d8ff33);
Let's break this down:
- background-image - is the gradient we want to use for our text
- -webkit-text-fill-color - replaces the normal color of the font with a transparent color, so the text disappears!
- -webkit-background-clip - clips the background image to the outline of the text. Now the background will only show where the text is.
- -webkit-box-decoration-break - is the strangest property I've ever seen in CSS, but it ensures the gradient works on multiple lines.
- filter - since we're using background clips and text, we can use a filter for the drop shadow rather than a normal box shadow.
Now it's up to you what gradient you want! Just adjust the background-image colors to show the gradient style you desire. You can find the full code for this demo here.
Happy text gradient-ing!
More Tips and Tricks for CSS
- A Guide to Level 4 CSS Selectors
- CSS Transformations
- Creating Custom, Interactive CSS Checkboxes
- How to do Deletion Animations with CSS
- CSS Glass Morphism Generator
- CSS 3d Mosaic Parallax Effect
- CSS Units
- A first look at CSS When and Else Statements
- A Complete Guide to How the CSS not Selector Works