Github Inspired Navbar

Bring the functionality of GitHub's navbar to your website effortlessly. Learn how to replicate GitHub's navbar design to improve navigation and user experience on your site.

Implementing a navbar inspired by GitHub's clean and functional design can enhance the navigation experience on your website. This guide will help you create a GitHub-inspired navbar using HTML and CSS. Follow these steps to copy the provided code snippet, link the required CSS files, and personalize the navbar to fit your specific requirements.

Step 1: Copy the Code Snippet

  • Begin by copying the provided HTML and CSS code snippet below. This snippet includes the essential structure and styles for the GitHub-inspired navbar. Simply select the code, copy it, and paste it into your HTML and CSS files.

Step 2: Link CSS Files

  • Ensure the necessary CSS files are properly linked in your HTML document. Add the following <link> tags within the <head> section to import the CSS styles and the necessary icons:
    <link rel="stylesheet" href="styles.css">
    <link rel="stylesheet" href="https://unicons.iconscout.com/release/v4.0.0/css/line.css">

Step 3: Customize and Make it Yours

  • Personalize the navbar to match your website's branding and functionality. Adjust the CSS styles to modify the navbar's appearance, colors, and icons. Experiment with different fonts and sizes to create a navigation bar that seamlessly integrates with your website's design.

By following these steps, you can implement and customize a GitHub-inspired navbar using HTML and CSS. Tailor the navbar to your specific needs and enhance user navigation and engagement on your website.

Code Explanation

HTML Code

Burger Menu Icon (<svg onclick="document.body.classList.toggle('open')" class="burger" ...>):

  • This SVG element serves as a toggle button (onclick="document.body.classList.toggle('open')") to open or close a menu or sidebar ('open' class is toggled on the body element).
  • Attributes include width="50", height="50", fill="#e8e8e8" (fills the SVG with a light gray color), and viewBox="0 0 24 24" (defines the coordinate system for the SVG).

Logo (<svg width="800px" height="800px" ...>):

  • Another SVG element, used here possibly as a logo or decorative element.
  • viewBox="0 0 16 16" defines its coordinate system.
  • fill="#ffffff" fills the path with white color.
  • fill-rule="evenodd" specifies the fill rule for the path.
  • The d attribute in the <path> tag contains the path data for the SVG shape.

Menu Items (<div class="menu-items">):

  • Container for various menu-related elements.

Search Bar (<div class="search">):

  • Contains an <input> element with an initial value of "Search or jump to..." and a <button> element.

Left Menu (<div class="menu menu-left">):

  • Contains links (<a> tags) likely used for navigation purposes.
  • Links are placeholders (href="#") and typically would be replaced with actual URLs.

Right Menu (<div class="menu menu-right">):

  • Contains additional menu items, including:
  • <span class="badge"></span>: A badge element, possibly for notifications or alerts.
  • Two SVG icons:
    • First SVG (<svg width="48" height="48" ...>): Contains a single path (<path>) that defines an icon.
    • Second SVG (<svg width="48" height="48" ...>): Also contains a single path (<path>) that defines a different icon.
  • <img src="https://www.frontendcomponent.com/favicon.ico" />: An image element displaying a favicon.

CSS Code

General Styles
  • * { box-sizing: border-box; }: Applies border-box box sizing to all elements, ensuring padding and border are included in the element's total width and height.
  • html, body, .wrapper { height: 100%; }: Sets the height of html, body, and .wrapper to 100%, ensuring the content takes up the full viewport height.
  • body { margin: 0; background: #0d1117; font-family: system-ui, -apple-system, BlinkMacSystemFont; }: Styles the body element with no margin, a dark background (#0d1117), and a system font stack.
  • nav { display: flex; align-items: center; justify-content: space-between; gap: 20px; height: 60px; padding: 0 20px; background: #161b22; }: Styles the nav element as a flex container with items spaced evenly. It has a height of 60px, padding around its content (20px), and a dark background (#161b22).
Navigation Elements and Menu Items
  • .burger { display: none; cursor: pointer; }: Styles a burger menu icon (svg) initially hidden (display: none) with a pointer cursor.
  • .menu-items, .menu { display: flex; gap: 16px; }: Styles .menu-items and .menu as flex containers with a gap of 16px between their child elements.
  • .menu-right { position: relative; margin-left: auto; gap: 6px; }: Styles .menu-right as a flex container aligned to the right (margin-left: auto), with child elements spaced 6px apart.
  • .menu-right svg, .menu-right img { width: 30px; height: 30px; padding: 5px; }: Sets the width and height of svg and img elements within .menu-right, with additional padding.
  • .menu-right .badge { position: absolute; top: 0; left: 14px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #161b22; background: linear-gradient(#54a3ff, #006eed); }: Styles a badge element within .menu-right with absolute positioning, a circular shape (border-radius: 50%), and a gradient background.
  • a, a:is(:visited, :active) { color: #ffffff; text-decoration: none; line-height: 24px; }: Styles anchor (a) tags and visited/active states with white color (#ffffff), no underlining (text-decoration: none), and a specific line height (24px).
Responsive Design (Media Queries)
  • @media (width <= 580px) { ... }: Applies styles for screens narrower than or equal to 580px.
  • .menu-right img:nth-child(n + 3) { display: none; }: Hides images within .menu-right starting from the third child element.
  • .menu-items { ... }: Styles .menu-items for smaller screens:
    • Displays it as a flex column with a full width, positioned beneath the nav (top: 60px).
    • Uses a dark background (#161b22) and includes padding.
  • .menu-left { ... }: Styles .menu-left for smaller screens as a flex column with reduced spacing.
  • .burger { display: block; }: Makes the burger menu icon visible for smaller screens.
  • body.open .menu-items { display: flex; }: Displays .menu-items when the body has the class .open, facilitating the display of hidden navigation items when toggled.