Creating Gradient Text with CSS

CSSCSSBeginner
Practice Now

This tutorial is from open-source community. Access the source code

Introduction

In this lab, we will explore the concept of gradient text in CSS. The purpose of this lab is to help you understand how to create gradient text using the linear-gradient() function, as well as how to use the webkit-text-fill-color and webkit-background-clip properties to fill the text with a gradient background. By the end of this lab, you will be able to create visually appealing gradient text that can enhance the design of your web pages.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL css(("`CSS`")) -.-> css/BasicConceptsGroup(["`Basic Concepts`"]) css(("`CSS`")) -.-> css/BasicStylingGroup(["`Basic Styling`"]) css(("`CSS`")) -.-> css/IntermediateStylingGroup(["`Intermediate Styling`"]) css/BasicConceptsGroup -.-> css/selectors("`Selectors`") css/BasicStylingGroup -.-> css/colors("`Colors`") css/BasicStylingGroup -.-> css/fonts("`Fonts`") css/BasicStylingGroup -.-> css/text_styling("`Text Styling`") css/IntermediateStylingGroup -.-> css/backgrounds("`Backgrounds`") subgraph Lab Skills css/selectors -.-> lab-35204{{"`Creating Gradient Text with CSS`"}} css/colors -.-> lab-35204{{"`Creating Gradient Text with CSS`"}} css/fonts -.-> lab-35204{{"`Creating Gradient Text with CSS`"}} css/text_styling -.-> lab-35204{{"`Creating Gradient Text with CSS`"}} css/backgrounds -.-> lab-35204{{"`Creating Gradient Text with CSS`"}} end

Gradient Text

index.html and style.css have already been provided in the VM.

To give text a gradient color, you can use CSS properties. First, use the background property with a linear-gradient() value to give the text element a gradient background. Then, use webkit-text-fill-color: transparent to fill the text with a transparent color. Finally, use webkit-background-clip: text to clip the background with the text and fill the text with the gradient background as the color. Here's an example code snippet:

<p class="gradient-text">Gradient text</p>
.gradient-text {
  background: linear-gradient(#70d6ff, #00072d);
  -webkit-text-fill-color: transparent;
  -webkit-background-clip: text;
  font-size: 32px;
}

Please click on 'Go Live' in the bottom right corner to run the web service on port 8080. Then, you can refresh the Web 8080 Tab to preview the web page.

Summary

Congratulations! You have completed the Gradient Text lab. You can practice more labs in LabEx to improve your skills.

Other CSS Tutorials you may like