Hello! Welcome back.
In our last lesson, we took a major step in optimizing your site's performance by automating the creation of responsive images. You learned how to use a Hugo Markdown Render Hook to transform simple Markdown into a sophisticated <picture> element with srcset, ensuring every user gets the perfect image size for their device. This focus on performance and user experience is something you're well-acquainted with from your deep background in SEO and Core Web Vitals.
Today, we'll complete our tour of responsive design by focusing on the most critical piece of user interaction: the site header. Our learning outcome is to adapt an AI-generated header to include a responsive mobile hamburger menu. A user who can't navigate your site on their phone is a lost user, so getting this right is non-negotiable.
The Anatomy of a Responsive Header
On a desktop screen, you have plenty of space for a full navigation bar. On a mobile device, that same navigation would be cramped and unusable. The standard solution is the "hamburger menu": a three-line icon that users can tap to reveal the navigation links.

Achieving this effect involves a partnership between three technologies you're already familiar with:
- HTML: The structure will contain both the desktop navigation links and the mobile menu. We'll also have a
<button>for the hamburger icon itself. - CSS: We'll use responsive utility classes (like those in Tailwind CSS) or media queries to show/hide the correct elements at different screen sizes. For example, the hamburger icon will be hidden on large screens, and the full navigation list will be hidden on small screens.
- JavaScript: A small script will listen for a
clickevent on the hamburger button and toggle a CSS class on the mobile menu element, which makes it appear or disappear (often with a smooth animation).
Prompting the AI for a Responsive Header
Knowing these components is the key to writing an effective prompt. Instead of a vague request like "make a header," we can be very specific. This is the essence of "vibe coding": translating your design requirements into a precise technical brief for the AI.
Let's start by reviewing the core principles of effective prompting.
Learn AI Prompting & Web Development - Bool
The guide 'Learn AI Prompting & Web Development' from Bool.com provides excellent fundamentals. We'll focus on a technique that is especially powerful for UI components: combining visual references with textual instructions.
Please read the sections titled 'Visual Prompting with Images & Screenshots' and 'Combining Visual & Text Prompts'. Pay close attention to the example prompts, like using a screenshot and asking the AI to 'make it responsive with a hamburger menu on mobile'. This is precisely the workflow we're adopting.
Drawing from these principles, a powerful prompt to generate our header would look something like this:
"Generate the code for a responsive header for a Hugo static site. The header should be a Hugo partial named
layouts/partials/header.html.Requirements:
- Use modern HTML5 tags (
<header>,<nav>).- Include a placeholder for a logo/site title on the left.
- On desktop, display a horizontal list of navigation links (e.g., Blog, Tools, About).
- On mobile, hide the horizontal links and show a hamburger menu button.
- Clicking the hamburger button should toggle a full-screen mobile menu that slides in from the right. This menu should contain the same navigation links.
- Use data attributes (e.g.,
data-menu-toggle) on the interactive elements for the JavaScript to target.- Provide the vanilla JavaScript needed to handle the click event and toggle the menu's visibility by adding/removing a CSS class."
This prompt is effective because it specifies the technology (Hugo partial), the structure (desktop vs. mobile), the behavior (slide in from right), and the implementation details (data attributes, class toggling).
Adapting AI-Generated Code: A Real-World Example
Now, let's assume the AI has generated the code based on our prompt. Your task is to understand, integrate, and adapt it. The following resource provides an excellent, production-quality example of the HTML and JavaScript for a responsive header.
Everything I learned about Hugo: Building ...
The article 'Everything I learned about Hugo' by Robin van der Knaap contains a perfect implementation of a responsive header. We will use the code from this article as our 'AI-generated' base to analyze and adapt.
Please read the section '2.4 Header' and study both the HTML and JavaScript code snippets provided. Don't worry about understanding every single Tailwind CSS class; focus on identifying the key components we discussed: the desktop nav, the hamburger button, the mobile menu div, and the JavaScript that ties them together.
Let's break down the key parts of the code you just reviewed.
The HTML Structure (header.html)
First, to use this header, you'd place it in your baseof.html file, just as you've done with partials before.

The provided HTML cleverly contains both navigation states at once:
-
Desktop Links:
<a class="hidden font-medium ... sm:block" href="/blog">Blog</a>The key here is
hidden sm:block. Using Tailwind CSS, this means the element is hidden by default but becomes ablockelement (visible) at thesm(small) breakpoint and up. -
Hamburger Button:
<button data-menu-toggle aria-label="Toggle Menu" class="sm:hidden"> <!-- SVG icon here --> </button>Conversely,
sm:hiddenmeans this button is visible by default but becomes hidden at thesmbreakpoint and up. -
Mobile Menu:
<div id="mobileMenu" class="fixed ... transform ... translate-x-full"> <!-- Mobile nav links here --> </div>This
divis the menu that slides in. Thefixedpositioning andtranslate-x-fullclass hide it off-screen to the right by default. The JavaScript will toggle this class to bring it into view.
The JavaScript Interactivity (toggle-menu.js)
The JavaScript provided in the resource is clean and efficient.
(function() {
const mobileMenu = document.getElementById('mobileMenu');
document.querySelectorAll('[data-menu-toggle]').forEach(function(menuToggle) {
menuToggle.addEventListener('click', function() {
mobileMenu.classList.toggle('translate-x-full');
mobileMenu.classList.toggle('translate-x-0');
});
});
})();
Let's dissect it:
- It selects the mobile menu
divby its ID. - It selects all elements that have the
data-menu-toggleattribute. This is great because it means the hamburger button to open the menu and the 'X' button inside the menu to close it can both use the same logic. - It adds a click listener to each of those buttons.
- When clicked, it toggles two classes on the
mobileMenu:translate-x-full(move it 100% of its width to the right, i.e., off-screen) andtranslate-x-0(move it to its default position, on-screen).
Finally, you would import this script into your main assets/js/index.js file (as we covered in the previous lesson on Hugo Pipes) so it gets bundled and included on your pages.
import './toggle-menu.js';
Test your understanding!
Imagine your designer wants to change the animation. Instead of sliding in from the right, the mobile menu should slide down from the top. Based on the JavaScript logic of toggling CSS classes, what would you need to change in the HTML/CSS to achieve this? You don't need to write the exact code, just describe the change in approach.
Show answer
You wouldn't need to touch the JavaScript at all! The JS is only responsible for toggling classes.
The change would be entirely in the CSS classes applied to the <div id="mobileMenu">. Instead of using translate-x-full to hide it horizontally, you would use a class like -translate-y-full to hide it above the viewport. The JavaScript would then toggle between -translate-y-full and translate-y-0.
This demonstrates the power of separating behavior (JS) from presentation (CSS).
Conclusion
You have successfully dissected the components of a modern, responsive header and learned how to prompt an AI to generate one. More importantly, you've practiced the crucial skill of adapting that generated code to fit your project, understanding how the HTML, CSS, and JavaScript work together to create a seamless user experience on any device.
Key Takeaways:
- A responsive header requires three parts: HTML for structure, CSS for responsive visibility, and JavaScript for interactivity.
- Writing a detailed AI prompt that specifies technical requirements (e.g., Hugo partial, data attributes, class toggling) yields far better results.
- The standard implementation uses two sets of navigation elements (one for desktop, one for mobile) and uses CSS to control which is visible at different screen sizes.
- The "hamburger" interaction is typically handled by a simple JavaScript that toggles CSS classes on the mobile menu element.
Preview of the next lesson:
In this lesson, the "AI-generated" code worked perfectly. But what happens when it doesn't? AI can sometimes produce code with subtle bugs, scope issues, or logical errors. In our next lesson, we will dive into using Hugo's debugging functions and troubleshooting common issues in AI-generated code. This will give you the confidence to not just generate code, but to truly own and debug it.