How to create a gradient text effect in CSS

Arif Billah Babu

         

  CSS



Image not found!!

Creating a gradient text effect in CSS involves using the background-clip property along with a gradient background and the text-fill-color or background-clip: text property. Here's how you can achieve it:

css
.gradient-text { /* Set the gradient background */ background: linear-gradient(to right, #ff9966, #ff5e62); /* Set the background clip to text */ -webkit-background-clip: text; background-clip: text; /* Set the text fill color transparent so the gradient background shows through */ color: transparent; /* For older browsers, set fallback color */ /* If the browser doesn't support background-clip: text, the text will be visible with this color */ /* You can adjust this color to match your gradient or to provide a fallback color */ -webkit-text-fill-color: transparent; text-fill-color: transparent; }

Here's a breakdown of what each part does:

  • background: Sets the gradient background. You can adjust the colors and direction of the gradient as needed.
  • -webkit-background-clip and background-clip: These properties set the clipping area for the background image. By setting it to text, the gradient background will only be visible where the text is.
  • color: Sets the text color to transparent so that the background gradient shows through the text.
  • -webkit-text-fill-color and text-fill-color: These properties set the color of the text. By setting it to transparent, the actual text will not be visible, and only the gradient background will show through. This property serves as a fallback for browsers that do not support background-clip: text.

Remember to adjust the colors and other styles according to your design requirements. Additionally, browser support for background-clip: text varies, so it's a good idea to provide a fallback color for older browsers that don't support this feature.