Quick Tip: Pure CSS Text Gradients
videos

Quick Tip: Pure CSS Text Gradients

Tutorial Details
  • Technology: CSS
  • Difficulty: Moderate
  • Estimated Completion Time: 4 Minutes

With the latest advancements in CSS, we now have access to powerful styling techniques, including box shadows, rounded corners, background gradients, etc. However, we don’t currently have the ability to apply gradients to the text itself. Luckily, with a bit of trickery, we can force this effect — at least in webkit browsers! I’ll show you how in today’s video quick tip.


4 Minutes: Video Tutorial

Screenshot

Final Code

<!DOCTYPE html>

<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Text Gradients</title>
	<link href='http://fonts.googleapis.com/css?family=Lobster' rel='stylesheet' type='text/css'>

	<style>
	body {
		background: #292929;
		padding: 1em;
	}
	
	h1 {
		position: relative;
		font-size: 70px;
		margin-top: 0;
		font-family: 'Lobster', helvetica, arial;
	}
	
	h1 a {
		text-decoration: none;
		color: #666;
		position: absolute;
		
		-webkit-mask-image: -webkit-gradient(linear, left top, left bottom, from(rgba(0,0,0,1)), color-stop(50%, rgba(0,0,0,.5)), to(rgba(0,0,0,1)));
	}
	
	h1:after {
		content : 'Hello World';
		color: #d6d6d6;
		text-shadow: 0 1px 0 white;
	}
	
	</style>
</head>
<body>
     <h1> <a href="#"> Hello World </a> </h1>
</body>
</html>	

I originally learned this technique from the guys over at NiceWebType.com. Be sure to visit their website to learn more! So what do you think?

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • http://www.dofollowchecker.com dofollowchecker

    nice css trick here. I spent ages googling and playing around with various gradient codes and snippets. This is a very simple solution. Brilliant :)

  • Misael

    Do I have to use h1 tag specifically for this to work?

    • Saptarshi

      No…you can use it anywhere like div,image,table,label,input…..any tags

  • abc

    test