Menu Notification Badges Using HTML5 Data-Attributes

Menu Notification Badges Using HTML5 Data-Attributes

Tutorial Details
  • Topic: CSS3, HTML5
  • Difficulty: Beginner
  • Estimated completion time: 30 mins
This entry is part 5 of 11 in the Bringing Premium Pixels to Life Session
« PreviousNext »

Today we’re going to take Orman Clark’s Menu Notification Badges design and build it using HTML and CSS. We’ll look at a couple of ways to achieve the effect, including the use of HTML5 data attributes which you may be unfamiliar with. Let’s dive in!


Step 1: HTML5 Base Markup

Let’s start off by throwing in some basic markup. We’ll be using the HTML5 doctype throughout the tutorial. We’ll create the menu itself by first adding a main div followed by list items which will create each menu link. We’ve also included the HTML5 shiv (or shim) script in the head of our document. This is called into play with older versions of Internet Explorer, allowing them to recognize and style HTML5 elements.

<!DOCTYPE html>
<html>
	<head>
		<!--Meta tags-->
		<meta charset="utf-8">
		<!--Title-->
		<title>Menu Notification Badges</title>
		<!--Stylesheets-->
		<link rel="stylesheet" href="styles.css">
		<!--HTML5 Shiv-->
		<!--[if lt IE 9]>
			<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
</head>
<body>
</body>
</html>


Step 2: Menu Markup

To create the structure of our menu we’ll use an un-ordered list with 4 list items and an anchor tag inside. You may also want to nest the list within a <nav> tag for deployment.

For the sake of this demonstration, we’ll create a div around the menu with a class of wrapper. This will just be used to move the menu to the middle of the page.

Your markup should look something like this;

<!DOCTYPE html>
<html>
	<head>
		<!--Meta tags-->
		<meta charset="utf-8">
		<!--Title-->
		<title>Menu Notification Badges</title>
		<!--Stylesheets-->
		<link rel="stylesheet" href="styles.css">
		<!--HTML5 Shiv-->
		<!--[if lt IE 9]>
			<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
</head>
<body>
<div class="wrapper">
	<ul class="menu">
		<li><a href="#">Profile</a></li>
		<li><a href="#">Setting</a></li>
		<li><a href="#">Notifications</a></li>
		<li><a href="#">Logout</a></li>
	</ul>
</div>
</body>
</html>

Step 3: Some Basic CSS

Before we start styling the menu, we’ll add some resets and some page styling. We’ll first throw in a reset to remove any margins, padding etc from browser default stylesheet. Next we’ll apply a background color to the body and a font-size of 16px. This fixed font size ensures the base size for our demo, but you may prefer to set it to 100% thus allowing the user to define their browser font size. We’ll apply a width of 70% to the wrapper and center it with a margin-top of 200px.

html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td { margin: 0; padding: 0; border: 0; outline: 0; font-size: 100%; vertical-align: baseline; backound: transparent; } body { line-height: 1; } ol, ul { list-style: none; } blockquote, q { quotes: none; } blockquote:before, blockquote:after, q:before, q:after { content: ''; content: none; } :focus { outline: 0; } ins { text-decoration: none; } del { text-decoration: line-through; } table { border-collapse: collapse; border-spacing: 0; } a { text-decoration: none; }
body { background:#ededed; font-size:16px; }
.wrapper {
	width: 70%;
	margin: 200px auto;
}

Step 4: Menu Base Styles

To kick off styling the menu, we’ll first focus on the base of it. Target the un-ordered list first, which was given a class of ‘menu’. We’ll give it a display of inline-block, allowing us to determine the width/height of it depending on its content like a block element.

Next we’ll apply a gradient background with all the browser prefixes. Then add some border radius, but hey what are those ems?! We’re using ems (instead of pixels) to size the border radius relative to the font size. Check out the demo; you’ll see the radius grow proportionately along with the larger text.

To work out the size we need, we’ll take 16px (our body font size) and divide it by 3 (our desired border radius size in px). So 16px/3px = 0.188 but we’ll round that up to 0.2.

Next we’ll apply a simple gray border, then a box shadow with a drop and inset shadow. Don’t forget those browser prefixes too!

.menu {
	display: inline-block;
	background-image: -webkit-linear-gradient(top, rgb(249, 249, 249), rgb(240, 240, 240));
	background-image: -moz-linear-gradient(top, rgb(249, 249, 249), rgb(240, 240, 240));
	background-image: -o-linear-gradient(top, rgb(249, 249, 249), rgb(240, 240, 240));
	background-image: -ms-linear-gradient(top, rgb(249, 249, 249), rgb(240, 240, 240));
	background-image: linear-gradient(top, rgb(249, 249, 249), rgb(240, 240, 240));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#f9f9f9', EndColorStr='#f0f0f0');
	-webkit-border-radius:0.2em;
	-moz-border-radius:0.2em;
	border-radius:0.2em;
	border:1px solid #cecece;
	-webkit-box-shadow:
		inset 0px 1px 0px #fff,
		0px 1px 2px rgba(0,0,0,.06);
	-moz-box-shadow:
		inset 0px 1px 0px #fff,
		0px 1px 2px rgba(0,0,0,.06);
	box-shadow:
		inset 0px 1px 0px #fff,
		0px 1px 2px rgba(0,0,0,.06);
}

Step 5: List Items

Moving on, let’s improve the menu by styling the list items. First we’ll float the list items to the left so they’re all on one line and not listed. We’ll then position them relatively, this will be needed later on when we create the badges. Next we’ll add a border on the left and a border on the right.

Now we’ll need to target the first list item and the last list item, so we’ll do this by using the pseudo selectors; :first-child and :last-child (bear browser support in mind when using these. For the first one we’ll remove the border left and we’ll remove the right border from the last list item.

.menu li {
	float:left;
	position:relative;
	border-right:1px solid #d8d8d8;
	border-left:1px solid #ffffff;
}
.menu li:first-child { border-left:none; }
.menu li:last-child  { border-right:none;}

Step 6: Anchor Tags

Next thing we’ll need to do is style the anchor tags. First we’ll give them a font-family of Helvetica Neue with some font-stack fall backs for people who don’t have the Helvetica font. Next we’ll give them a font size of 0.75em (13px/16px=0.75). Then we’ll apply a font weight of bold, followed by a color of #666666 and apply a text shadow.

We’ll now apply some padding to the left and right of 1em (13px/13px=1) and some line-height to center the text vertically. We’ve based the line-height on 30px, interpreted into ems.

.menu li a {
	font-family:'Helvetica Neue', Helvetica, sans-serif;
	font-size:0.75em;
	font-weight:bold;
	color:#666666;
	text-shadow:0px 1px 0px #ffffff;
	display: block;
	padding:0 1em;
	line-height:2.5em;
}

Our menu is starting to look pretty good now!

Anchor Tag Styles

Step 7: Notification Bubbles Markup

Time to add the cool little notification bubbles. First you’ll need to replace your menu HTML markup with the following. We’ll create the bubbles using span tags, then for each color we’ll apply an appropriate class. I’ve added pink, yellow and blue.

<div class="wrapper">
	<ul class="menu">
		<li><a href="#">Profile<span class="pink">2</span></a></li>
		<li><a href="#">Setting<span class="yellow">3</span></a></li>
		<li><a href="#">Notifications<span class="blue">6</span></a></li>
		<li><a href="#">Logout</a></li>
	</ul>
</div>

Step 8: Styling the Notification Bubbles

To create the notification bubbles we’ll first style the span tags with everything except for the color and border color. This way we can change the colors easily by simply changing class names.

First we’ll create some widths and heights, take 18px/12px=1.5em. Then we’ll need to position them absolutely (0.5em from the right and -2em from the top). Next, a line height will be applied to center the number vertically and text-align center is used to center horizontally.

A font-family will be applied with Helvetica Neue, again with fallbacks for users without Helvetica. We’ll make it bold, apply a color of white and then add a text-shadow. Next we’ll add some box-shadows (we’ll add two; one drop shadow and one inset shadow). Remember to create these while using browser prefixes. Now we’ll add a border-radius of 4em (roughly 50px).

For the next stage in the process, we’ll take advantage of some CSS3 techniques and get the hover effect working. We’ll first hide the bubble using an opacity of 0. Next, to create our cool little animations we’ll use some transitions. We’ll target the top and opacity and tell it to ease-in over a period of 0.3 seconds (3 milliseconds). These will need the browser prefixes applied including -o- and -ms-.

span {
	position:absolute;
	top:-2em;
	right: 0.5em;
	width: 1.5em;
	height: 1.5em;
	line-height:1.5em;
	text-align:center;
	ont-family:'Helvetica Neue', Helvetica, sans-serif;
	font-weight:bold;
	color:#fff;
	text-shadow:0px 1px 0px rgba(0,0,0,.15);
	-webkit-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,35),
		0px 1px 1px rgba(0,0,0,.2);
	-moz-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	-webkit-border-radius:4em;
	-moz-border-radius:4em;
	border-radius:4em;
	opacity:0;
filter: alpha(opacity=0);
	-webkit-transition: .3s top ease-in, .3s opacity ease-in;
	-moz-transition: .3s top ease-in, .3s opacity ease-in;
	-o-transition: .3s top ease-in, .3s opacity ease-in;
	-ms-transition: .3s top ease-in, .3s opacity ease-in;
	transition: .3s top ease-in, .3s opacity ease-in;
}

Step 9: Bubble Colors

Time for the final aesthetic touches on the bubbles; adding some CSS to style the colors. Remember the classes we added to the span tags? These will make things simple enough, we’ll target each color, apply a gradient and a border color.

.pink {
	background-image: -webkit-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -moz-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -o-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -ms-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#f78297', EndColorStr='#f46677');
	border:1px solid #ce4f5e;
}
.yellow {
	background-image: -webkit-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -moz-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -o-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -ms-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#feda71', EndColorStr='#feba48');
	border:1px solid #dea94f;
}
.blue {
	background-image: -webkit-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -moz-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -o-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -ms-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#ace4f8', EndColorStr='#6ccdf3');
	border:1px solid #79b5cb;
}

Step 10: Hover Styles

Of course, our bubbles are beautifully styled, but completely invisible. We’ll need to add some CSS to allow the bubbles to show on hover. First add some color to the anchor tags when they’re hovered over, just a simple dark gray. Next we’ll target the span when its parent list item is hovered over. We’ll add an opacity of 1 to make it visible and change the top position value to make it appear as if it’s sliding down.

.menu li:hover a {
	color: #343434;
}
.menu li:hover a span {
	top:-1em;
	opacity:1;
filter: alpha(opacity=100);
}
Hover Styles

So What About HTML5 Data Attributes?

Glad you asked..


Step 11: Change the Menu HTML Markup

To create our menu with HTML5 data attributes we’ll first need to change our HTML Markup. We’re going to use some custom attributes to create the bubbles. HTML5 introduced a new data- attribute where the attribute name can be anything as long as it’s at least 1 character long and starts with ‘data-’.

For this tutorial we’ll use ‘data-bubble’. These will allow us to store and access our notification values without adding unnecessary markup structure to our document. Notice we’ve also moved our color classes onto the anchor tags.

<div id="wrapper">
	<ul class="menu">
		<li><a href="#" class="pink" data-bubble="2">Profile</a></li>
		<li><a href="#" class="yellow" data-bubble="3">Setting</a></li>
		<li><a href="#" class="blue" data-bubble="6">Notifications</a></li>
		<li><a href="#">Logout</a></li>
	</ul>
</div>

Step 12: Removing Some CSS

As we’re no longer going to be working with the span elements, you’ll need to go back to your CSS and delete the following rules;

span {
	position:absolute;
	top:-2em;
	right: 0.5em;
	width: 1.5em;
	height: 1.5em;
	line-height:1.5em;
	text-align:center;
	font-family:"Helvetica Neue";
	font-weight:bold;
	color:#fff;
	text-shadow:0px 1px 0px rgba(0,0,0,.15);
	-webkit-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,35),
		0px 1px 1px rgba(0,0,0,.2);
	-moz-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	-webkit-border-radius:4em;
	-moz-border-radius:4em;
	border-radius:4em;
	opacity:0;
filter: alpha(opacity=0);
	-webkit-transition: .3s top ease-in, .3s opacity ease-in;
	-moz-transition: .3s top ease-in, .3s opacity ease-in;
	-o-transition: .3s top ease-in, .3s opacity ease-in;
	-ms-transition: .3s top ease-in, .3s opacity ease-in;
	transition: .3s top ease-in, .3s opacity ease-in;
}
.pink {
	background-image: -webkit-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -moz-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -o-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -ms-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#f78297', EndColorStr='#f46677');
	border:1px solid #ce4f5e;
}
.yellow {
	background-image: -webkit-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -moz-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -o-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -ms-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#feda71', EndColorStr='#feba48');
	border:1px solid #dea94f;
}
.blue {
	background-image: -webkit-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -moz-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -o-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -ms-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#ace4f8', EndColorStr='#6ccdf3');
	border:1px solid #79b5cb;
}
.menu li:hover a span {
	top:-1em;
	opacity:1;
filter: alpha(opacity=100);
}

Step 13: Adding Some CSS

Now let’s target our data-attributes instead, we’ll need to add some rules to our CSS.

It will look very similar to what we used for our span elements. This time though, we’ll target the the :after pseudo elements of anchor tags with an attribute of “data-bubble”. To do so we’re using CSS Attribute Selectors.

As we’re using an :after pseudo (and thereby generating content) we’ll need to define some meat within it with content:”. Once again we’ll use our custom attribute we created in our HTML and insert that.

Again, to manage the visibility of our bubble, we’ll give it an opacity of 1 when the link is hovered over. Unfortunately, due to limitations with attribute selectors we cannot animate them with CSS itself.

.menu li a[data-bubble]:after {
	content:attr(data-bubble);
	position:absolute;
	top:-1.25em;
	right: 0.5em;
	width: 1.5em;
	height: 1.5em;
	line-height:1.5em;
	text-align:center;
	font-family:"Helvetica Neue";
	font-weight:bold;
	color:#fff;
	text-shadow:0px 1px 0px rgba(0,0,0,.15);
	-webkit-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,35),
		0px 1px 1px rgba(0,0,0,.2);
	-moz-box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	box-shadow:
		inset 0px 1px 0px rgba(255,255,255,.35),
		0px 1px 1px rgba(0,0,0,.2);
	-webkit-border-radius:4em;
	-moz-border-radius:4em;
	border-radius:4em;
	opacity:0;
filter: alpha(opacity=0);
}
.menu li:hover a[data-bubble]:after {
	opacity:1;
filter: alpha(opacity=100);
}

Step 14: Colors for Attributes

Finally, we need to style the generated content within the various classes so we can change the colors easily (exactly as we did with the span elements).

a.pink[data-bubble]:after {
	background-image: -webkit-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -moz-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -o-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: -ms-linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	background-image: linear-gradient(top, rgb(247, 130, 151), rgb(244, 102, 119));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#f78297', EndColorStr='#f46677');
	border:1px solid #ce4f5e;
}
a.yellow[data-bubble]:after {
	background-image: -webkit-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -moz-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -o-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: -ms-linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	background-image: linear-gradient(top, rgb(254, 218, 113), rgb(254, 186, 72));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#feda71', EndColorStr='#feba48');
	border:1px solid #dea94f;
}
a.blue[data-bubble]:after {
	background-image: -webkit-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -moz-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -o-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: -ms-linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	background-image: linear-gradient(top, rgb(172, 228, 248), rgb(108, 205, 243));
	filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0,StartColorStr='#ace4f8', EndColorStr='#6ccdf3');
	border:1px solid #79b5cb;
}

Conclusion

We’ve successfully created a menu along with some neat notification bubbles and animated them! We’ve even gone further and taken advantage of new techniques within HTML5.

Completed

I hope you enjoyed this tutorial, thanks for reading!

Luke Spoor is lspoor on Codecanyon
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • mnowluck

    Good use of HTML5 and css3. Will tweak this a bit and use it for personal projects :D

  • http://www.paulund.co.uk Paul

    Thanks for this tutorial.

    I’ve used the span approach to this before, really good idea to use HTML attributes I’m going to use this from now on.

  • http://belpotter.by/ skip405

    Do check your doctype declaration :) It’s half-html5)

    • http://www.snaptin.com Ian Yates

      So it was – wow, the things I miss sometimes.. Thanks :)

  • Robert Smith

    Great tutorial and great looking menu.

    Thanks a lot!

  • http://www.keyframe.com.br claudio

    did not work in browser (Internet explorer).

    • http://www.snaptin.com Ian Yates

      You’re right – the css was missing the IE filter equivalent of opacity.

      Wherever you use an opacity value, back it up with an IE filter like this filter: alpha(opacity=100); and you’ll be set for IE6 onwards. It takes a value from 0 to 100; 0 being transparent, 100 being opaque. I’ve updated the tut to reflect this. Thanks!

  • http://sdplabs.com Srinivas Reddy

    Great Tutorial. Very useful tutorial using HTML5 & CSS3. Thanks a lot for sharing.

  • Pingback: Menu Notification Badges Using HTML5 Data-Attributes | Shadowtek | Hosting and Design Solutions

  • Pingback: 2012년 3월 9일 it 기술 동향 |

  • http://maomuffy.blogspot.com Mfawa Alfred Onen

    Really Nice! Great Job

  • Pingback: Website - Social - Notifications | Pearltrees

  • http://www.veden.pl Kasia

    Thanks for this tutorial :)

  • http://amyself.com Makarand

    Awesome notifications tutorial…thank alot

  • Ben

    Ahhh.. This is really AWESOME!!! :D

  • http://www.queenswebdesignandgraphics.com/ Anthony

    Very good tutorial — What is the reason why the effect seems to work with out passing the data attribute into the css rule:

    .html5.menu li a:after {

    }

    • http://www.snaptin.com Ian Yates

      If I understand your question correctly, what you’ve selected there is every a:after pseudo element within a list item. What Luke uses is an attribute selector: .menu li a[data-bubble]:after which only targets those with a data-bubble attribute. The logout button, for example, doesn’t have such an attribute, and therefore doesn’t reveal a bubble when hovered over.

      Hope that answers your question!

      • Anthony

        Thanks Ian — very useful tut!

  • Gustavo

    Cool, but in internet explorer it is’nt work.

    • dj

      @gustavo … a comment like that isn’t helpful unless you include which IE you are viewing it in and what about it isn’t working.

      I just checked and in IE9 it DOES work, although as we know 9 doesn’t do animations yet and the color background is transparent with white letters. My guess is that both of these issues are easily corrected.

      @ian – thanks for taking the time to include the MS filter methods – a practice which I wish you’d require of all your authors. Although I personally don’t like the method, MS has as much right to their own proprietary methods as -moz or -webkit or -o does, and it doesn’t take that much more effort to type it in than all the rest of the proprietary stuff. Why not make it all work instead of just blowing off the majority of internet users in the name of MS bashing. I must say that I’m glad MS has begun it’s renewed browser interest and look forward to IE10 – as much as I do to -o, -moz and -webkit dropping their proprietary stuff and supporting “native CSS” selectors.

  • http://www.raylo.net Raymond Lopez
    • http://www.lukespoor.com Luke
      Author

      Always one :)

      That’s the whole point of this tutorial buddy, the aim was to recreate them while having permission from Orman to do so ;-)

  • Tom

    Slight problem, apologies if it’s already been mentioned but if you’re using a screen reader and an out of date browser such as Internet Explorer 7(which is still quite common I believe with screen reader users) then the HTML5 method won’t be read out to the user (Try with NVDA if you wanna see for yourself).

    With the span option the number gets read out.

    Some suggestions for improving it though, reading them out with numbers doesn’t really give a lot of context in this case, if it were an email inbox it would be obvious but you could add some description text in there to tell the screen reader user what the numbers mean and just hide it off screen with position:absolute; left:-9999px;

    Also it would be nice to add a :focus state so keyboard users see them on focus as well instead of just users with a pointing device.

    • Tom

      One tiny additional point… always put a space in there, you wouldn’t read it Inbox8, it’s Inbox 8… span’s don’t affect screen readers so it would be read out as if it were 1 word which could cause some odd/annoying outcomes.

      Could also have an affect where SEO is concerned as well

      • http://www.lukespoor.com Luke
        Author

        Hey Tom, to answer most of that. It wasn’t done because it wasn’t designed like that. The aim of the tutorial was to show the user how to take the design and convert it to HTML/CSS. Also the data attribute won’t work in in IE7, to use this method you first have to use the custom attribute then use CSS3 selectors to make it appear. The data-attribute will be supported but would need some jQuery to allow it to be used. Hope this clears things up.

        • Tom

          Hey Luke,

          I don’t really like to stir it up but that doesn’t answer any of that, so few developers take care when developing when it comes to accessibility and with a tiny bit of care it can make all the difference.

          Regardless of whether it was “designed” like that, making it accessible is a piece of cake. But instead you’re pushing a method which isn’t needed it’s just “cool”.

          It’d just be nice if people who wrote these tutorials and pushed this stuff out there took this stuff into consideration and made a reference to it. I can totally understand it if you’re not aware of it so don’t take this as a knock (unless you are aware of it!) in which case you should add a note! :)

  • Pingback: HTML5 Menu Notification Badges | Just An Ordinary Blog

  • http://www.web-mate.gr webmate

    nice tutoriaL!

  • Pingback: Latest news from Magnus Attefall 03/13/2012 | Läsvärt | Attefall Allehanda - Nyheter och recensioner

  • http://chrisfrees.com Chris Frees

    Step 8, Line 12 misspelled font-family :)

  • http://roadha.us haliphax

    One correction: In #8, you have:

    ont-family:’Helvetica Neue’, Helvetica, sans-serif;

    That should probably be “font-family”. ;)

  • Anders Frohm

    You could replace the background-image properties with the following code, to make it work in IE 9 to:

    pink:
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPgo8bGluZWFyR3JhZGllbnQgaWQ9Imc1IiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgo8c3RvcCBzdG9wLWNvbG9yPSIjRjc4Mjk3IiBvZmZzZXQ9IjAiLz48c3RvcCBzdG9wLWNvbG9yPSIjRjQ2Njc3IiBvZmZzZXQ9IjEiLz4KPC9saW5lYXJHcmFkaWVudD4KPHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNnNSkiIC8+Cjwvc3ZnPg==);

    yellow:
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPgo8bGluZWFyR3JhZGllbnQgaWQ9Imc1NjEiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+CjxzdG9wIHN0b3AtY29sb3I9IiNGRURBNzEiIG9mZnNldD0iMCIvPjxzdG9wIHN0b3AtY29sb3I9IiNGRUJBNDgiIG9mZnNldD0iMSIvPgo8L2xpbmVhckdyYWRpZW50Pgo8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2c1NjEpIiAvPgo8L3N2Zz4=);

    blue:
    background-image: url(data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPgo8bGluZWFyR3JhZGllbnQgaWQ9Imc0MTAiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+CjxzdG9wIHN0b3AtY29sb3I9IiNBQ0U0RjgiIG9mZnNldD0iMCIvPjxzdG9wIHN0b3AtY29sb3I9IiM2Q0NERjMiIG9mZnNldD0iMSIvPgo8L2xpbmVhckdyYWRpZW50Pgo8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2c0MTApIiAvPgo8L3N2Zz4=);

    • http://www.lukespoor.com Luke
      Author

      I could of but I find that to be rather messy code :) I would preferably take an image route for browsers that don’t support gradients :)

  • Pingback: Weekly Web Developer`s Kit – vol. 1 (3-16-2012) « CSS Tips

  • http://www.webexstudios.com/ webexstudios

    Great tutorial. i love this

  • Suresh

    really useful example…

  • Mário

    Hey Luke.
    Are you sure that it works doing it step by step #1 to #10?
    I dont get your final result (#10 2nd screenshot).
    My final result is the bar without bubbles.

    #8 – a flaw: ‘ont-family’

    Thanks,
    M

    • Mário

      Nevermind. Fixed. :)

  • Annie

    I added:

    padding: 0 0.25em;
    min-width: 1em; /* No-width, only a min-width */

    Because I put the data-bubble number within my coding so I don’t know if the number will be greater than one digit (for example, a user’s mailbox with the number of new messages).

    Great tutorial!

  • http://damatajhiz.com/ Hamid

    Great tutorial and great looking menu

  • http://stocklove.net Sean Sr.

    This is beautiful. Unfortunately, I don’t know how to hook it up to a WordPress Theme, but it’s gorgeous none the less.

    8-)

  • http://bittersmann.de Gunnar Bittersmann

    Just another tutorial that got the linear-gradient syntax wrong: http://www.1stwebdesigner.com/css/mastering-css-gradients-in-less-than-1-hour/#comment-205142

    Tutorial writers, please do your homework!

  • Pingback: 70 Fresh jQuery and CSS3 Tutorials From 2012

  • http://damatajhiz.com/categories/1/%DA%A9%D9%88%D9%84%D8%B1-%DA%AF%D8%A7%D8%B2%DB%8C-%D9%88-%D8%A7%D8%B3%D9%BE%D9%84%DB%8C%D8%AA-%D9%87%D8%A7 کولر گازی

    nice job …

  • Pingback: Modern CSS3 Tutorials For Professional Developers and Designers | CSS Tips

  • Pingback: Ultimate Tutorials of HTML5, CSS3 and jQuery | Dzinepress

  • Pingback: All You Need to Know About the HTML5 Data Attribute | Webdesigntuts+

  • Pingback: All You Need to Know About the HTML5 Data Attribute - itcenter-bg.com | itcenter-bg.com

  • Pingback: All You Need to Know About the HTML5 Data Attribute - Website Design Prices

  • http://www.facebook.com/alanrichtrader Alan Rich

    This is just want i needed. Perfect!

  • Pingback: Menu Notification Badges Using HTML5 Data-Attributes | Webdesigntuts+ | Important Links

  • Pingback: 40 Web Tutorial Desarrollo que hará que sus habilidades Skyrocket | Clear Data

  • http://www.facebook.com/profile.php?id=100000208030779 Ryan Jan Borja

    I really want to have this. Pulling a 0 – 1 (status) from database and shows the badge the number of incoming messages for example.