{"id":135249,"date":"2025-11-12T05:37:58","date_gmt":"2025-11-12T05:37:58","guid":{"rendered":"https:\/\/phppot.com\/?p=24603"},"modified":"2025-11-12T05:37:58","modified_gmt":"2025-11-12T05:37:58","slug":"how-to-build-a-responsive-react-navbar-with-dropdown-and-mobile-menu","status":"publish","type":"post","link":"https:\/\/sickgaming.net\/blog\/2025\/11\/12\/how-to-build-a-responsive-react-navbar-with-dropdown-and-mobile-menu\/","title":{"rendered":"How to Build a Responsive React Navbar with Dropdown and Mobile Menu"},"content":{"rendered":"<div class=\"modified-on\" readability=\"7.1489361702128\"> by <a href=\"https:\/\/phppot.com\/about\/\">Vincy<\/a>. Last modified on November 25th, 2025.<\/div>\n<p>A responsive navigation bar is a one of a must-needed requirement of any modern web application. It is an easy job if the navigation bar contains single level menu and action controls. But, it will be complex it is a <a href=\"https:\/\/phppot.com\/react\/react-dropdown-menu\/\">multi-level menu<\/a> to fit the layout into a small viewport.<\/p>\n<p>With this React example code you\u2019ll learn how to build a responsive React navbar. It includes a multi-level dropdown menu for different view port. It will a plugable and reusable React component for your different application frontend.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-24718\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/responsive-react-navbar-dropdown-mobile-menu-550x288.jpg\" alt=\"Responsive React Navbar Dropdown Mobile Menu\" width=\"550\" height=\"288\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/responsive-react-navbar-dropdown-mobile-menu-550x288.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/responsive-react-navbar-dropdown-mobile-menu-300x157.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/responsive-react-navbar-dropdown-mobile-menu-768x402.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/responsive-react-navbar-dropdown-mobile-menu.jpg 1200w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<h2>Responsive navbar in React header<\/h2>\n<p>This React JSX code has the a responsive navigation bar component. It provides 1) menu bar with Desktop and mobile variants, 2)sub menu bar with <a href=\"https:\/\/phppot.com\/jquery\/jquery-sidebar-expand-collapse\/\">click-to-expand effect<\/a>.<\/p>\n<p>The menuData contains the array of multi-level menu items. The image shown below renders the <a href=\"https:\/\/phppot.com\/jquery\/how-to-create-horizontal-scrolling-menu-using-jquery-and-php\/\">horizontal menu on the site header<\/a>.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-24609\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-550x106.jpg\" alt=\"react drop down navbar\" width=\"550\" height=\"106\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-550x106.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-300x58.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-768x149.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-1536x297.jpg 1536w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar.jpg 1731w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<p class=\"code-heading\"><code>src\/components\/Navbar\/Navbar.jsx<\/code><\/p>\n<pre class=\"prettyprint\"><code class=\"language-jsx\">import { useState } from \"react\";\nimport menuData from \".\/MenuData\";\nimport Dropdown from \".\/DropDown\";\nimport \"..\/..\/..\/public\/assets\/css\/style.css\"; const Navbar = () =&gt; { const [menuOpen, setMenuOpen] = useState(false); const [openIndex, setOpenIndex] = useState(null); const toggleSubmenu = (index, e) =&gt; { if (window.innerWidth &lt;= 768) { e.preventDefault(); setOpenIndex(openIndex === index ? null : index); } };\nreturn ( &lt;nav className=\"navbar\"&gt; &lt;div className=\"navbar-container\"&gt; &lt;h2 className=\"logo\"&gt;&lt;\/h2&gt; &lt;button className=\"menu-toggle\" onClick={() =&gt; setMenuOpen(!menuOpen)} aria-label=\"Toggle menu\" &gt; \u2630 &lt;\/button&gt; &lt;ul className={`menu ${menuOpen ? \"open\" : \"\"}`}&gt; {menuData.map((menu, i) =&gt; ( &lt;li key={i} className=\"menu-item has-submenu\"&gt; &lt;a href=\"#\" onClick={(e) =&gt; toggleSubmenu(i, e)}&gt; {menu.title} &lt;span className=\"expand\"&gt;\u25bc&lt;\/span&gt; &lt;\/a&gt; {menu.subMenu &amp;&amp; ( &lt;Dropdown items={menu.subMenu} className={openIndex === i ? \"open\" : \"\"} \/&gt; )} &lt;\/li&gt; ))} &lt;\/ul&gt; &lt;\/div&gt; &lt;\/nav&gt;\n);\n};\nexport default Navbar;\n<\/code><\/pre>\n<p>These are the main and submenu items defined for this React example.<\/p>\n<p class=\"code-heading\"><code>src\/components\/Navbar\/MenuData.js<\/code><\/p>\n<pre class=\"prettyprint\"><code class=\"language-js\">const menuData = [ { title: \"Popular Toys\", subMenu: [ { title: \"Video Games\", subMenu: [ { title: \"Car\", subMenu: [\"Racing Car\", \"Toy Car\", \"Remote Car\"] }, \"Bike Race\", \"Fishing\" ] }, \"Barbies\", \"Teddy Bear\", \"Golf Set\" ] }, { title: \"Recent Toys\", subMenu: [ \"Yoyo\", \"Doctor Kit\", { title: \"Fun Puzzle\", subMenu: [\"Cards\", \"Numbers\"] }, \"Uno Cards\" ] }, { title: \"Toys Category\", subMenu: [ \"Battery Toys\", { title: \"Remote Toys\", subMenu: [\"Cars\", \"Aeroplane\", \"Helicopter\"] }, \"Soft Toys\", \"Magnet Toys\" ] }\n]; export default menuData;\n<\/code><\/pre>\n<h2>React menu dropdown hooks to toggle submenu<\/h2>\n<p>A component Dropdown returns the submenu look-and-feel. The React state openIndex has the menu open\/close state by its index.<\/p>\n<p>The Dropdown component\u2019s expand\/collapse state is depends on the menuOpen set with a toggle action. The <a href=\"https:\/\/phppot.com\/jquery\/toggle-html-with-jquery\/\">menu toggle effect<\/a> is for the mobile view to slide down the menu options on clicking a burger icon.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-24611\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-menu-550x210.jpg\" alt=\"react drop down navbar menu\" width=\"550\" height=\"210\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-menu-550x210.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-menu-300x115.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-menu-768x294.jpg 768w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-menu.jpg 918w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<p class=\"code-heading\"><code>src\/components\/Navbar\/DropDown.jsx<\/code><\/p>\n<pre class=\"prettyprint\"><code class=\"language-jsx\">import { useState } from \"react\"; const Dropdown = ({ items, className }) =&gt; { const [openIndex, setOpenIndex] = useState(null); const toggleSubmenu = (index, e) =&gt; { if (window.innerWidth &lt;= 768) { e.preventDefault(); setOpenIndex(openIndex === index ? null : index); } }; return ( &lt;ul className={`dropdown ${className || \"\"}`}&gt; {items.map((item, i) =&gt; typeof item === \"string\" ? ( &lt;li key={i}&gt; &lt;a href=\"#\"&gt;{item}&lt;\/a&gt; &lt;\/li&gt; ) : ( &lt;li key={i} className=\"has-submenu\"&gt; &lt;a href=\"#\" onClick={(e) =&gt; toggleSubmenu(i, e)}&gt; {item.title} &lt;span className=\"expand\"&gt;\u203a&lt;\/span&gt; &lt;\/a&gt; {item.subMenu &amp;&amp; ( &lt;Dropdown items={item.subMenu} className={openIndex === i ? \"open\" : \"\"} \/&gt; )} &lt;\/li&gt; ) )} &lt;\/ul&gt; );\n};\nexport default Dropdown;\n<\/code><\/pre>\n<h2>Mobile menu navbar view<\/h2>\n<p>This heading shows the mobile view of this responsive navbar. In the mobile view, a burger icon will be appeared on the top right corner of the web layout.<\/p>\n<p>This icon\u2019s click event is bound to <a href=\"https:\/\/phppot.com\/jquery\/jquery-sliding-menu\/\">toggle a sliding menu<\/a>. In this sliding menu, each menu items are vertically expandable to show its submenu.<br \/><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-large wp-image-24614\" src=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-mobile-responsive-550x545.jpg\" alt=\"react drop down navbar mobile responsive\" width=\"550\" height=\"545\" srcset=\"https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-mobile-responsive-550x545.jpg 550w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-mobile-responsive-300x297.jpg 300w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-mobile-responsive-150x150.jpg 150w, https:\/\/phppot.com\/wp-content\/uploads\/2025\/11\/react-drop-down-navbar-mobile-responsive.jpg 621w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\"><\/p>\n<p><strong>References:<\/strong><\/p>\n<ol>\n<li><a href=\"https:\/\/m3.material.io\/components\/navigation-bar\/overview\" target=\"_blank\" rel=\"noopener\">Navigation bar modals with Material Design<\/a>.<\/li>\n<li><a href=\"https:\/\/www.figma.com\/community\/website-templates\/navbar?resource_type=mixed&amp;editor_type=all&amp;price=free&amp;sort_by=all_time\">Free navigation bar templates by Figma<\/a>.<\/li>\n<\/ol>\n<p><a class=\"download\" href=\"https:\/\/phppot.com\/downloads\/react\/responsive-react-navbar-dropdown-mobile-menu.zip\">Download<\/a><\/p>\n<div class=\"written-by\" readability=\"9.8427672955975\">\n<div class=\"author-photo\"> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/phppot.com\/wp-content\/themes\/solandra\/images\/Vincy.jpg\" alt=\"Vincy\" width=\"100\" height=\"100\" title=\"Vincy\"> <\/div>\n<div class=\"written-by-desc\" readability=\"14.764150943396\"> Written by <a href=\"https:\/\/phppot.com\/about\/\">Vincy<\/a>, a web developer with 15+ years of experience and a Masters degree in Computer Science. She specializes in building modern, lightweight websites using PHP, JavaScript, React, and related technologies. Phppot helps you in mastering web development through over a decade of publishing quality tutorials. <\/div>\n<\/p><\/div>\n<p> <!-- #comments --> <\/p>\n<div class=\"related-articles\">\n<h2>Related Tutorials<\/h2>\n<\/p><\/div>\n<p> <a href=\"https:\/\/phppot.com\/react\/responsive-react-navbar-dropdown-mobile-menu\/#top\" class=\"top\">\u2191 Back to Top<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>by Vincy. Last modified on November 25th, 2025. A responsive navigation bar is a one of a must-needed requirement of any modern web application. It is an easy job if the navigation bar contains single level menu and action controls. But, it will be complex it is a multi-level menu to fit the layout into [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":135250,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[65],"tags":[],"class_list":["post-135249","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php-updates"],"_links":{"self":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/135249","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/comments?post=135249"}],"version-history":[{"count":0,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/posts\/135249\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media\/135250"}],"wp:attachment":[{"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/media?parent=135249"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/categories?post=135249"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sickgaming.net\/blog\/wp-json\/wp\/v2\/tags?post=135249"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}