Over a million developers have joined DZone.

Github Ribbons in CSS

DZone 's Guide to

Github Ribbons in CSS

· Web Dev Zone ·
Free Resource

Github has these cool ribbon images that you can use if you want to encourage forking your project on your site. They're great and I wanted to use them on a little project I am working on. However, one of my goals was not to use any images, but rather produce all display elements with CSS.

It was a little bit of trial and error but I got it working. Basically you do the following:

  • Create a link in a div with an id of "banner"
  • Force div#banner to be 149px x 149px.
  • Set overflow to "hidden"

This creates a square display area that won't show things that stretch out past the bounds of the box.

  • Create an A link
  • Tilt it using a CSS transform
  • Use relative positioning to pull the ribbon into place
  • Use CSS shadows to tweak the text and ribbon shadows
  • Finally I use a CSS gradient in the background of the ribbon to give it the bands that run along the edge.
<!DOCTYPE html> 
	<title>Banner Example</title> 
	<meta name="viewport" content="width=device-width, initial-scale=1">
			padding: 0;
			margin: 0;
			height: 149px;
			width: 149px;
			padding: 0;
			margin: 0;
		#banner a{
			display: block;
			width: 190px;
			font-size: 14px;
			font-family: Frutiger, "Frutiger Linotype", Univers, Calibri, "Gill Sans", "Gill Sans MT", 
				"Myriad Pro", Myriad, "DejaVu Sans Condensed", "Liberation Sans", "Nimbus Sans L", Tahoma, 
				Geneva, "Helvetica Neue", Helvetica, Arial, sans serif;
			background-color: #333;
			color: #FFF;
			word-spacing: 2px;
			text-decoration: none;
			padding: 5px 15px 5px 25px;
			left: 20px;
			top: -37px;
			text-align: center;
			-moz-transform-origin: 0 0 ;
			-moz-box-shadow:    1px 1px 5px 1px #666;
			-webkit-transform-origin: 0 0 ;	
			-webkit-box-shadow: 1px 1px 5px 1px #666;
			-ms-transform-origin: 0 0 ;	
			-ms-box-shadow: 1px 1px 5px 1px #666;
			transform-origin: 0 0 ;	
			box-shadow: 1px 1px 5px 1px #666;
			background-image: linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -o-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -moz-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -webkit-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -ms-linear-gradient(bottom, #000000 3%, #666666 5%, #000000 7%, #000000 93%, #666666 95%, #000000 97%);
			background-image: -webkit-gradient(
				left bottom,
				left top,
				color-stop(0.03, #000000),
				color-stop(0.05, #666666),
				color-stop(0.07, #000000),
				color-stop(0.93, #000000),
				color-stop(0.95, #666666),
				color-stop(0.97, #000000)
	<div id="banner"><a href="">Fork me on GitHub</a></div>
	<a href="http://github.com/you"><img style="position: absolute; top: 0; left: 149px; border: 0;" src="https://a248.e.akamai.net/assets.github.com/img/7afbc8b248c68eb468279e8c17986ad46549fb71/687474703a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub"></a>


  • It's not a pixel perfect representation.
  • It doesn' work on IE before 9. It doesn't appear at all.

I'm not sure if I'm going to use this. I'll sound judgmental here, but the fact that it doesn't show up on IE less than 9 seems like a good thing. Do I want a developer on my project that isn't using the latest browser? Probably not.

See the live demo here.


A couple people pointed out that there was a weird doubling of the letters on their browser (Chrome on Windows, and Safari on iPad.) Looks like it was caused by a slight text-shadow I had on the text. The text on the original banner has some anti-aliasing going on, and on some browsers, the text shadow helps it look a little smoother, but on others you get that doubling. So I've removed the text shadow.  Display should be a little more consistent.


Source: http://www.terrenceryan.com/blog/post.cfm/github-ribbons-in-css


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}