Code a Spinning Circular Menu With CSS

Don’t be a square, break outside your boring box and try on a circle for size. Today we’re going to build a circular navigation menu that spins to different points as the user hovers over an anchor.

Along the way we’ll have to overcome several obstacles like how to structure our HTML to be conducive to a remote hover and how to position all of the elements just right so that everything works. It’s a fun challenge and there’s a lot to learn, let’s get started!

The Ultimate Designer Toolkit: 2 Million+ Assets

Envato Elements gives you unlimited access to 2 million+ pro design resources, themes, templates, photos, graphics and more. Everything you'll ever need in your design resource toolkit.

Explore Digital Assets

Launch DemoDownload Files

Step 1: Structural HTML

Before we write a single character of HTML, we have to figure out the structure of what it is that we’re building. For this, we can turn to Photoshop and make a basic sketch of how we want the menu to look. Here’s what I came up with:


Basically, each of the rectangles at the top are tied to one of the four little circles inside of the big circle. When a rectangle is hovered over, its corresponding little circle will rotate up to the top of the menu. Again, we’re making use of the concept of a “remote” hover because the user interacts with one area and it affects another.

Every time I try to pull off a remote hover, it takes me a few tries to get the structure just right. This is because of the way CSS selectors work, and more specifically, the way the hover pseudo class works. Consider the following:

Let’s say that we put this structure into place with the idea that we wanted a hover over the anchor to change the color of the paragraph. If you have a basic idea of how remote hovers work, you might come up with some CSS like this:

As it turns out, this simply doesn’t work. In our CSS selector, we have to tie the anchor being hovered in with the paragraph to be acted upon, but our elements are in two completely separate divs. There’s no easy way to climb this far up and across the DOM tree.

So what do we do? The answer lies in restructuring our HTML. This time we’ll toss the two elements onto the same level of the tree.

Now our paragraph is a sibling of our anchor, which means we have a clear way to tie them together in our CSS. Here’s how it works:

This time around, we’re telling the browser to trigger a color shift on any paragraph that is the immediate sibling of an anchor that is being hovered over.


If we apply this knowledge to our scenario, we can come up with a structure that works. Start by creating three divs: wrapper, menu and circle. Nest menu inside of wrapper and circle inside of menu.

Inside of the menu div, place four anchors, each with a unique class. Inside of the circle div, place an unordered list containing the numbers one through four.

It might still be a little confusing as to how all of these pieces relate to our previous sketch, so let’s update it with some visual cues to give you an idea of what everything does.


Step 2: Wrapper CSS

The code above represents all of the HTML that we’ll need for this little project. The rest of our work is all CSS. To begin, let’s lay down some basic resent and positioning code:

There’s not much here to be confused about, we’re simply sketching out our wrapper. Note that the -webkit-backface-visibility bit is to prevent a bug that causes Webkit to flicker on CSS transitions.

Step 3: Circle CSS

Next we’ll jump to coding that big circle. Making a circle in CSS is pretty easy, just make sure that the height and width are equal and that the border-radius is set to at least 50%. Everything else here just helps position everything nicely.

To make the circle look a little fancier, let’s add in an inset shadow. Finally, we toss in a transition so that the circle will animate the rotation that happens later.

If we take a look at our live preview, we should have a nice big circle and some other various scattered elements that we’ll address next.


Step 4: Menu CSS

For our next trick, we’ll style the menu items. To do this, target the anchors, add in some margin and padding, set the width and the color, strip out the text-decoration and style the font. Then target the hover state and add in a background color. Here’s the code:

Now if we check out our live preview, the links in our menu will look much nicer. The list items are still all out of whack though so we’ll attack those next.


Step 5: Little Circle CSS

To create the little circles, we first target the list items and set them up very similar to the big circle: make the height and width equal and set the border-radius to 50%. Also be sure to clear the bullet points, set the background to white, and style the font like you see below.

Here’s the tricky part. Above, we gave each of the circles absolute positioning, so now we have to scoot them into place. We can target each individual circle with nth-child, then use top and left to nudge them where we want them. Finally, we want to make it so that the top of each number faces the outer edge of the big circle so that when the whole element rotates, the number on top is always right side up. We do this by using a CSS transform.

If we take a look at our preview now, everything is pretty great. There’s one thing that’s not quite right though…


Step 6: Inner Circle CSS

Our original concept wasn’t just one big circle, there was also centered inner circle. We can pull this off without any extra HTML markup using our old friend before. Create an element before wrapper, set the content to “DS”, make it a circle like the others (130px this time), align and style the text, move it to the top with z-index and scoot it into place with absolute positioning.

That looks much better! With that, our visual styling is completely finished. Now all that’s left is to bring this sucker to life.


Step 7: Hover Circle CSS

To make our menu spin, we have to use our remote hover trick combined with a CSS transform. When the user hovers over one of the top menu items, the entire circle element will spin so that the corresponding number is on top.

The trickiest part of this is figuring out the selector. We start at the highest level that contains both the circle div and the menu items. This is of course the menu div. Then we narrow our options down to a specific child of the menu and target it on hover. Finally, we tell the browser that we want to act upon any sibling of that item being hovered over with a class of “circle.” Here’s what that looks like in practice:

It’s a beast of a selector, but it gets the job done and is good enough for our fun little experiment. Now, since we’re targeting the second circle here, we need to rotate the whole div by 90 degrees. Also, since we want to go counter-clockwise, the number will be negative:

That’s all there is to it, now we simply use this technique across all four circles. We start with a rotation of 0, then -90, -180 and finally, -270.

Take a Look!

Congratulations, you’re finished! Now it’s time to check out the fruits of our hard labor. Here’s a demo.

Demo: Click here to launch.


As always, thanks a bunch for reading and feel free to leave a comment below to let me know what you think. There are a bunch of different ways that you could approach this project, how would you have done it differently?