Creating a stylish bottom navigation bar can significantly enhance the user experience of your website. In this tutorial, I’ll walk you through building a simple yet visually appealing navigation bar using HTML, CSS, and JavaScript.
1. HTML Structure
The basic HTML structure consists of a div container that holds the navigation bar and four SVG icons representing menu items. Each icon will act as a clickable element, and a div slider will be used to visually indicate the selected menu item.
Here’s the HTML code:
- The
containerholds the entire bottom nav and centers it on the page. - The
navis the bottom navigation bar that holds the SVG icons. - The
sliderwill be animated to move under the selected icon.
2. CSS Styling
The CSS handles the layout, appearance, and animation. Here’s how the styling works:
- Container: Positioned centrally with a background gradient.
- Nav Bar: Styled with a white background, rounded corners, and flex alignment to distribute the icons.
- Icons: Each icon has a transition effect for smooth animations when clicked.
- Slider: A circular slider under the icons moves to highlight the active icon.
3. JavaScript for Interactivity
The JavaScript adds click functionality to the icons. When an icon is clicked, it moves the slider to that icon and changes its color and margin to indicate it’s selected.
- Icon Click: The script listens for clicks on any icon. When clicked, it adjusts the margin and color to show the active state.
- Slider Animation: Based on the icon index, the slider’s
marginLeftis adjusted, creating the sliding effect.
4. How the Slider Works
The slider div is centered on the page initially and then moves horizontally based on the clicked icon’s position. This is achieved by changing the marginLeft of the slider dynamically in the JavaScript code.
Conclusion
This bottom navigation bar is responsive, easy to implement, and stylish. It uses only a few lines of HTML, CSS, and JavaScript to create a smooth, animated interaction. Feel free to customize the icons, colors, and animation timings to suit your project!
Let me know if you have any questions in the comments below!

0 Comments