Quick Tip: Create Pure CSS3 Ticket-Like Tags
Tags are a familiar feature of many Web 2.0 services, websites and especially blogs. During this tutorial we're going to use CSS3 to create ticket-like tags, without relying on any images.
Here's a quick breakdown of the process:
- Create the HTML markup.
- Style the main tags.
- Style the four corners of the tag.
- Style the link.
- Add and style a punched hole in the tag.
Step 1: HTML Header Markup
Let's start by first adding the markup inside the head of our document. We've added two style sheets: "tut.css" and "tickets.css"; You can remove the former whenever you want to implement your own work, but we'll use it in the demo. The style sheet "tickets.css" contains all the styles that will format our tooltips. Here's our document head markup:
1 |
|
2 |
<meta charset="utf-8"> |
3 |
<title>Pure CSS3 Ticket-like Tags</title> |
4 |
<link rel="stylesheet" href="styles/tut.css" /> |
5 |
<link rel="stylesheet" href="styles/tickets.css" /> |
Step 2: HTML Tags Markup
Now we need to add the markup for the tags. We've used a division for each tag with class attribute ticket which we'll use to style the tags. Then we have a span with class attribute circle. Finally, you'll see a link with text for the tags. Here's the tags markup (I added four tags as a sample, but you can add as many as you wish):
1 |
|
2 |
<div class="ticket"><span class="circle"></span><a href="#">CSS3</a></div> |
3 |
<div class="ticket"><span class="circle"></span><a href="#">HTML5</a></div> |
4 |
<div class="ticket"><span class="circle"></span><a href="#">Design</a></div> |
5 |
<div class="ticket"><span class="circle"></span><a href="#">Development</a></div> |
Step 3: CSS Main Tag
Let's start by styling the main tags div (.ticket). Here we set font styles, set position to relative
so that we can absolute position elements inside it (notice it has !important
because without this we can't achieve the results we want), background color, floating to left
which you can also set to right
, then finally some padding and margins for spacing.
1 |
|
2 |
.ticket { |
3 |
font-family: Arial; |
4 |
font-size: 12px; |
5 |
font-weight: bold; |
6 |
position: relative !important; |
7 |
background: #8dc63f; |
8 |
float: left; |
9 |
padding: 7px 3px; |
10 |
margin: 0 5px 5px 0; |
11 |
}
|
Our tags should look like this.

Step 4: CSS Top Corners
Now we style the top two corners to make it look like a cutout quarter of a circle. To create this we are going to use pseudo elements after
and before
. Both pseudo elements have the same styling, the only difference being that after
is positioned left whereas before
is positioned right.
Start by setting the content value to nothing, position absolute
, z-index
to 100
or any large positive value, set its position from top, left or right, and zero. Set the border-bottom style and left or right, then finally we set border-radius to 20px
(bottom right corner for after
and bottom left for before
.
To learn more about creating shapes using CSS borders styles you can view this
guide.
1 |
|
2 |
.ticket:after { |
3 |
content: ""; |
4 |
position: absolute !important; |
5 |
z-index: 100; |
6 |
top: 0; |
7 |
left: 0; |
8 |
border-right: #fff 7px solid; |
9 |
border-bottom: #fff 7px solid; |
10 |
-moz-border-radius: 0 0 20px 0; |
11 |
-webkit-border-radius: 0 0 20px 0; |
12 |
border-radius: 0 0 20px 0; |
13 |
}
|
14 |
|
15 |
.ticket:before { |
16 |
content: ""; |
17 |
position: absolute !important; |
18 |
z-index: 100; |
19 |
top: 0; |
20 |
right: 0; |
21 |
border-left: #fff 7px solid; |
22 |
border-bottom: #fff 7px solid; |
23 |
-moz-border-radius: 0 0 0 20px; |
24 |
-webkit-border-radius: 0 0 0 20px; |
25 |
border-radius: 0 0 0 20px; |
26 |
}
|
Our tags should look like this.

Step 5: CSS Links Within our Tags
Within the links we can now create the effect of stitching by utilizing borders and outlines. We style the links with a dashed 1px outline with 40% transparent white color, set the borders with 30% transparent black color, padding to make the stitching look more realistic on the edges, no text decoration, set text color to 50% transparent white (so that we don't have to change the text color every time we change the background color of the tags) and set white space to nowrap
. Finally, we set the hover state text color to 50% transparent black.
1 |
|
2 |
.ticket a { |
3 |
outline: 1px rgba(255,255,255,0.4) dashed; |
4 |
border: 1px rgba(0,0,0,0.3) dashed; |
5 |
padding: 4px 10px 4px 20px; |
6 |
text-decoration: none; |
7 |
color: rgba(255,255,255,0.5); |
8 |
white-space: nowrap; |
9 |
}
|
10 |
|
11 |
.ticket a:hover {color: rgba(0,0,0,0.5);} |
Our tags should look now like this. Notice that both the cutout corners lie on top of the stitching.

Step 6: CSS Bottom Corners
For the bottom corners we're also going to use pseudo elements after
and before
but this time within the link. The styling of these two corners is obviously similar to the top corners, we just change the position and border to match their position.
1 |
|
2 |
.ticket a:after { |
3 |
content: ""; |
4 |
position: absolute !important; |
5 |
z-index: 100; |
6 |
bottom: 0; |
7 |
left: 0; |
8 |
border-right: #fff 7px solid; |
9 |
border-top: #fff 7px solid; |
10 |
-moz-border-radius: 0 20px 0 0; |
11 |
-webkit-border-radius: 0 20px 0 0; |
12 |
border-radius: 0 20px 0 0; |
13 |
}
|
14 |
|
15 |
.ticket a:before { |
16 |
content: ""; |
17 |
position: absolute !important; |
18 |
z-index: 1000; |
19 |
bottom: 0; |
20 |
right: 0; |
21 |
border-left: #fff 7px solid; |
22 |
border-top: #fff 7px solid; |
23 |
-moz-border-radius: 20px 0 0 0; |
24 |
-webkit-border-radius: 20px 0 0 0; |
25 |
border-radius: 20px 0 0 0; |
26 |
}
|
Our tags should now look like this.

Step 7: CSS Adding The Punched Hole
In the HTML markup we've already added an empty span element with the class name circle
and it's mainly used to create our punched hole effect. We'll use borders and border-radius again to create circles with zero height and width values. We'll set their position to absolute
, z-index to a large positive number, 50% from top, 8px
from left with a box shadow to make it look more realistic, and finally a top margin of -5px
to align it perfectly to the center.
1 |
|
2 |
.ticket .circle { |
3 |
position: absolute !important; |
4 |
z-index: 100; |
5 |
border: 5px #fff solid; |
6 |
-moz-border-radius: 10px; |
7 |
-webkit-border-radius: 10px; |
8 |
border-radius: 10px; |
9 |
margin-top: -5px; |
10 |
width: 0; |
11 |
height: 0; |
12 |
top: 50%; |
13 |
left: 8px; |
14 |
-moz-box-shadow: 0 -1px 0 rgba(0,0,0,0.5), |
15 |
0 1px 0 rgba(255,255,255,0.3); |
16 |
-webkit-box-shadow: 0 -1px 0 rgba(0,0,0,0.5), |
17 |
0 1px 0 rgba(255,255,255,0.3); |
18 |
box-shadow: 0 -1px 0 rgba(0,0,0,0.5), |
19 |
0 1px 0 rgba(255,255,255,0.3); |
20 |
}
|
Our tags should look be complete!

Conclusion
My approach for creating these tickets does have a problem. The four corners and the punched hole don't change color if the background color is altered. In other words, they aren't transparent and you need to change their color each time you change the background color.
As for browser compatibility this has been tested to work on Firefox 4.5+, Chrome 13, Opera 11 and IE9.
Your final result should look like the image above. For your end result to look exactly like our demo you should use the styles inside "tut.css", but feel free to add your own adjustments.
I hope that you have all learned some techniques from this CSS tutorial! Share your thoughts below :)