<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[KneyxKodes' Blog]]></title><description><![CDATA[KneyxKodes' Blog]]></description><link>https://kneyxkodes.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Mon, 02 Nov 2026 08:50:43 GMT</lastBuildDate><atom:link href="https://kneyxkodes.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to Create a Simple Navigation Menu Often Addressed as a Hamburger Menu.]]></title><description><![CDATA[In this article, we will learn how to create a simple toggle navigation menu using HTML, CSS,& JavaScript. This menu is commonly known as a hamburger menu.]]></description><link>https://kneyxkodes.hashnode.dev/how-to-create-a-simple-navigation-menu-often-addressed-as-a-hamburger-menu</link><guid isPermaLink="true">https://kneyxkodes.hashnode.dev/how-to-create-a-simple-navigation-menu-often-addressed-as-a-hamburger-menu</guid><dc:creator><![CDATA[Afomachukwu Onyekaba]]></dc:creator><pubDate>Tue, 02 May 2023 13:46:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1683004937974/fa805f7e-c569-4278-8b0e-3d48366244cc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, we will learn how to create a simple toggle navigation menu using HTML, CSS, and JavaScript. This menu is commonly known as a hamburger menu, and it's important for developers to have a foundational knowledge of how it's done.</p>
<p>We will begin by creating an HTML file and setting up a template with the necessary elements. To attach the bar icon to the menu, we will use the Font Awesome CDN link.</p>
<pre><code class="lang-html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-meta-keyword">html</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">"en"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">"UTF-8"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">http-equiv</span>=<span class="hljs-string">"X-UA-Compatible"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"IE=edge"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1.0"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>Document<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"style.css"</span>&gt;</span>
    <span class="hljs-comment">&lt;!-- Load an icon library to show a hamburger menu: --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"stylesheet"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span>

    <span class="hljs-comment">&lt;!-- To create a navigation  menu and bar --&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"navbar"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav_1"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">""</span>&gt;</span>KED_KULTURE<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>

            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"menu"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Contact Us<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Catalogue<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Register/Login<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

            <span class="hljs-comment">&lt;!-- To create the icon link for navigation --&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"javascript:void(0);"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">onclick</span>=<span class="hljs-string">"Ked_kulture()"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">i</span> <span class="hljs-attr">onclick</span> =<span class="hljs-string">"Ked_kulture()"</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"fa fa-bars"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">i</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">script</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span>
</code></pre>
<p>The above is the HTML part of the source code linked to the CSS and JavaScript files for styling and to add some functionality. My sole aim of writing this article is to help my readers fully understand whatever concept they want to learn. I know the "href" assigned to the bar icon for navigation may be new to some of us, but don't worry, I will explain it in the JavaScript session.</p>
<p>Now, let's move on to the CSS styling:</p>
<pre><code class="lang-css"><span class="hljs-selector-tag">body</span>{
    <span class="hljs-attribute">background-color</span>: peachpuff;
}

<span class="hljs-comment">/* To style the Navbar */</span>
<span class="hljs-selector-class">.navbar</span>{
    <span class="hljs-attribute">background-color</span>: black;
    <span class="hljs-attribute">border-radius</span>: <span class="hljs-number">1rem</span>;
    <span class="hljs-attribute">margin</span>: <span class="hljs-number">50px</span>;
    <span class="hljs-attribute">height</span>: <span class="hljs-number">500px</span>;
    <span class="hljs-attribute">max-width</span>: <span class="hljs-number">450px</span>;
    <span class="hljs-attribute">box-shadow</span>: <span class="hljs-number">5px</span> <span class="hljs-number">5px</span> grey;
}

<span class="hljs-comment">/* To style the logo */</span>
<span class="hljs-selector-class">.nav_1</span>{
    <span class="hljs-attribute">position</span>: relative;
}


<span class="hljs-comment">/* To style the navigation menu */</span>
<span class="hljs-selector-class">.nav_1</span> <span class="hljs-selector-id">#menu</span>{
    <span class="hljs-attribute">display</span>: none;
}

<span class="hljs-comment">/* To style the links */</span>
<span class="hljs-selector-class">.nav_1</span> <span class="hljs-selector-tag">a</span> {
    <span class="hljs-attribute">text-decoration</span>: none;
    <span class="hljs-attribute">color</span>: white;
    <span class="hljs-attribute">padding</span>: <span class="hljs-number">10px</span> <span class="hljs-number">12px</span>;
    <span class="hljs-attribute">font-size</span>: <span class="hljs-number">16px</span>;
    <span class="hljs-attribute">display</span>: block;
}

<span class="hljs-comment">/* To style the Navigation bar toggle bar */</span>
<span class="hljs-selector-class">.nav_1</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-class">.icon</span> {
    <span class="hljs-attribute">display</span>: block;
    <span class="hljs-attribute">position</span>: absolute;
    <span class="hljs-attribute">right</span>: <span class="hljs-number">0</span>;
    <span class="hljs-attribute">top</span>: <span class="hljs-number">0</span>;
}

<span class="hljs-comment">/* To add an hover effect on navigation logo and menu */</span>
<span class="hljs-selector-class">.nav_1</span> <span class="hljs-selector-tag">a</span><span class="hljs-selector-pseudo">:hover</span> {
    <span class="hljs-attribute">background-color</span>: <span class="hljs-number">#b9b1b1</span>;
    <span class="hljs-attribute">color</span>: black;
            }
</code></pre>
<p>Let's define the function in JavaScript:</p>
<pre><code class="lang-javascript">
<span class="hljs-comment">// Function to toggle the bar</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Ked_kulture</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> btn = <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">"menu"</span>);
    <span class="hljs-keyword">if</span> (btn.style.display === <span class="hljs-string">"block"</span>) {
        btn.style.display = <span class="hljs-string">"none"</span>;
    } 
    <span class="hljs-keyword">else</span> {
        btn.style.display = <span class="hljs-string">"block"</span>;
    }
}
</code></pre>
<p>Here, "javaScript;" is often referred to as a pseudo URL. When "javascript:" is assigned as the value of the "href" attribute on an anchor tag, the code that follows after the colon is interpreted as JavaScript code. Using "javascript:", you can run code that does not change the current page. This is useful in cases where you do not want a link to navigate to another page or reload the current page. When used with "void(0)", it means to do nothing – does not reload, does not navigate, and does not run any code. "void(0)" evaluates the given expression and returns undefined.</p>
<p>Hope this is clear enough.</p>
<p>.</p>
]]></content:encoded></item></channel></rss>