How to Create a Modern Ribbon Banner Navigation Bar with Pure HTML/CSS3

As CSS3 becomes more robust and is more widely supported, the options for fun modern design elements that can be created without graphics are virtually limitless! For a recent project, I decided to see if I could create a centered ribbon banner with pure CSS3. This tutorial will walk you through how it was done.

As it turns out, it’s actually quite easy, using only simple, semantic HTML and some CSS3 trickery thanks to the magic of the the border-width property. The only caveat: As with all new CSS3 techniques, it can act a bit wonky in some IE browsers... we'll address that at the end of the tutorial.

Here’s how:

Step 01: The Navigation Links

We want to create a navigation link bar, so we’re going to begin with a simple unordered list [ul] with links inside [a]. This is one of the most basic building blocks of markup; good for creating lists of elements to be styled in a similar way like we’re going to do here:

To add the stars, I’ve placed an HTML entity &#10029; (which looks like this ✭) inside of each link. This is purely decorative, and not needed for the functionality.

At this point, we already have a nice usable navigation link section that we could add into a page. But we’re going to keep going to create a nice ribbon to put these links inside of.

Step 02: The Ribbon Banner

The border-width technique that we’re going to use does require that we add 4 extra elements to the markup. While it’s not ideal to add extraneous elements, in the long-run it’s probably still more efficient than loading up extra graphics, and we’ll keep things as simple as possible.

First, we’ll create a container element around the links. This will allow us to set a width to keep all the banner elements together:

We’ll add the following styles to create the ribbon body background. We’re setting a z-index of 500 because the rectangle needs to be stacked on top of the triangles that we’ll create next. I’m adding both -moz-box-shadow and box-shadow to account for Firefox and -webkit/IE9 respectively:

Finally, we’ll add some border-width magic. The key to this is setting a border-color of transparent for each side of the element except for the bottom (for the top triangles) and top (for the bottom triangles). Then, we set a border-width of 50px. This creates an isosceles triangle, which we will then position behind the main body of the ribbon:

And we’re done! This will render perfectly in Firefox and Webkit browsers. IE is notoriously bad at using these CSS3 properties, so it won't render perfectly there, but we'll do our best to get it pretty close using a couple custom stylesheets.

For IE8 and IE9, we'll add some custom positioning rules through the "ie.css" stylesheet:

Just to be on the safe side (and since we believe in progressive enhancement), we’ll also add a fix for IE7, which can be placed in either the head section of your page or in a separate IE7 stylesheet. My choice of a fix is to simply hide the triangles in browsers lower than IE8. The browser-width property is supported in IE7, but the spacing will be a bit off. It’s up to you whether you’d like to spend the extra time re-positioning the elements in IE7:

Wrapping It Up

The background images are just for fun - you can add your own and build around this document... or just grab everything above this and drop it into your own design. But, in the interest of being comprehensive, here's the CSS that's adding in those images:

Credits: The images are from iStockPhoto - we can't distribute the bottom island image with the demo, but you can grab it for yourself here.

That's It!

Hope you guys enjoyed this one! Remember that this is a fairly new set of techniques... so if your goal is 100% stability on all browsers known to man, there are more stable ways of accomplishing this using basic images for the background. Leave your comments and questions below ;)

Read More about creating a ribbon or folding effect:

Create a 3D Ribbon Wrap-Around Effect (Plus a Free PSD!)

I thought it might be fun to create a tutorial on the popular 3d Wrap-Around Ribbon effect that has been popping up so much this year. This is a great way to add depth to your designs, and it’s pretty darn easy to complete.

Quick Tip: Practical CSS Shapes

A common design technique lately is to create a fold effect, where it appears as if a heading is wrapping behind its container. This is generally achieved through the use of tiny images; however, with CSS, we can mimic this effect quite easily. I’ll show you how in four minutes.