How do I create a CSS-only radial menu with icons?

Creating a CSS-Only Radial Menu with Icons

A radial menu, also known as a pie menu or circle menu, is a circular context menu that allows users to interact with a web application in a unique and intuitive way. This blog post will guide you through the process of creating a CSS-only radial menu using icons. We’ll be using the Font Awesome library to add icons to our menu items.

Step 1: Include Font Awesome Library

To get started, let’s include the Font Awesome library in our project. Add the following link in the head section of your HTML file:

<!-- html -->
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha384-KyZXEAg3QhqLMpG8r+Knujsl5wILpD1z+K9+VIRx5J++1q6enNJz3f+3DOFwzCqc" crossorigin="anonymous">
</head>
<body>
  <!-- other html code here -->
</body>
</html>

Step 2: Create the HTML Structure for the Radial Menu

Next, we’ll create the HTML structure for our radial menu. We’ll use an unordered list with list items for each menu option, and add Font Awesome icons as the content of the list items.

<!-- html -->
<div class="radial-menu">
  <input type="checkbox" id="toggle" class="toggle">
  <label for="toggle" class="menu-button"><i class="fas fa-bars"></i></label>
  <ul>
    <li>
      <a href="#"><i class="fas fa-home"></i></a>
    </li>
    <li>
      <a href="#"><i class="fas fa-user"></i></a>
    </li>
    <li>
      <a href="#"><i class="fas fa-envelope"></i></a>
    </li>
    <li>
      <a href="#"><i class="fas fa-cog"></i></a>
    </li>
  </ul>
</div>

Step 3: Style the Radial Menu with CSS

Now, let’s style our radial menu using CSS. We’ll position the menu items in a circle around the center of the menu, and add transitions for a smooth opening and closing effect.

/* CSS */
.radial-menu {
position: relative;
width: 200px;
height: 200px;
}

.toggle {
display: none;
}

.menu-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: #333;
color: #fff;
border-radius: 50%;
width: 50px;
height: 50px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
}

.menu-button:hover {
background-color: #555;
}

.radial-menu ul {
list-style: none;
padding: 0;
margin: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}

.radial-menu li {
position: absolute;
top: 50%;
left: 50%;
width: 50px;
height: 50px;
margin: -25px 0 0 -25px;
opacity: 0;
transition: all 0.3s;
}

.radial-menu a {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
border-radius: 50%;
background-color: #333;
color: #fff;
text-decoration: none;
}

.radial-menu a:hover {
background-color: #555;
}

.toggle:checked ~ ul li:nth-child(1) {
transform: translate(-50%, -50%) rotate(0deg) translate(100px) rotate(-0deg);
opacity: 1;
}

.toggle:checked ~ ul li:nth-child(2) {
transform: translate(-50%, -50%) rotate(90deg) translate(100px) rotate(-90deg);
opacity: 1;
}

.toggle:checked ~ ul li:nth-child(3) {
transform: translate(-50%, -50%) rotate(180deg) translate(100px) rotate(-180deg);
opacity: 1;
}

.toggle:checked ~ ul li:nth-child(4) {
transform: translate(-50%, -50%) rotate(270deg) translate(100px) rotate(-270deg);
opacity: 1;
}

Conclusion:

You have now successfully created a CSS-only radial menu with icons. This menu is fully functional and offers a unique user experience. The radial menu can be further customized by adding more menu items, adjusting the size, or changing the colors and icons to match the design of your website.

Got question?

Submit it here

© All rights reserved.