Share layout, metadata and styling
Give every page the same navigation and footer while keeping each page’s title and content its own.
Allow 15–25 minutes. This is an editorial estimate. Continue in the same my-site folder; do not create another starter.
Read
Start at L02. Home, About and Contact work, and the local image loads. Keep the dev server running. We will edit six files in this same project; the image and optional JavaScript file stay as they are.
A page is the content reached by a URL. A layout is the shared HTML document around that page. Your starter already selected a layout; now you will make it yours. Its <slot/> marks where the page content goes.
Use one assignment convention in both application.what and page <what> blocks: name = "value". Quote text values. In HTML, #name# prints that value. Metadata is not a programming expression: title = "My website" names a value; <title>#title#</title> puts it in the document.
Change
1. Set directory defaults. Replace site/application.what. These settings apply to the pages in site/ and its child folders. A page can override them. The layout path starts at your project folder, so it includes components/.
layout = "components/layout.html"
title = "My website"
description = "Ideas, projects and useful things, one page at a time."
2. Make the shared document. Replace components/layout.html. It owns the one document, head, navigation, main landmark and footer. The skip link lets a keyboard user move past navigation to the main content.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="#description#">
<title>#title#</title>
<link rel="stylesheet" href="/static/styles.css">
</head>
<body class="site-body">
<a class="skip-link" href="#main-content">Skip to content</a>
<header class="site-header">
<a class="site-name" href="/">My website</a>
<nav class="site-nav" aria-label="Main navigation">
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
</nav>
</header>
<main id="main-content" class="site-main" tabindex="-1">
<slot/>
</main>
<footer class="site-footer">
<p>Made one page at a time.</p>
</footer>
</body>
</html>
3. Keep only page-specific content in each page. Replace the three page files. Remove their repeated navigation and <main> wrappers because the layout now supplies those.
<what>
description = "Welcome to my small place for ideas, projects and useful things."
</what>
<h1>My website</h1>
<p>I am building my own website.</p>
<p>A small place for ideas, projects and useful things.</p>
<figure>
<img src="/static/images/site-image.svg" width="640" height="360"
alt="An open notebook and a green plant on a sunlit desk"
class="site-image">
<figcaption>A little space to make something of your own.</figcaption>
</figure>
<what>
title = "About | My website"
description = "Why I am building this website and what I plan to share."
</what>
<h1>About this website</h1>
<p>This is a place to share what I am learning and making.</p>
<p>I started with one page. Now every new page has a home.</p>
<what>
title = "Contact | My website"
</what>
<h1>Contact</h1>
<p>Have a question or an idea to share?</p>
<p>This sample page is ready for your contact details. Replace this paragraph with the way you prefer people to reach you.</p>
Home inherits title from application.what. About overrides both title and description. Contact overrides its title and inherits the default description. The large <h1> heading is ordinary page content, separate from the browser-tab title.
A nested folder can have its own application.what to override inherited settings for that section. We do not need another folder or layout yet. Keep one shared layout until your site actually needs another.
4. Style your site. Replace static/styles.css. What supplies framework CSS automatically; this is your project's additional stylesheet, linked by the layout. The site- class names keep these rules focused on your site.
/* Framework styles are supplied automatically. These rules style our site. */
.site-body {
margin: 0;
color: #26372c;
background: #faf8f2;
font-family: system-ui, sans-serif;
line-height: 1.65;
}
.site-header, .site-main, .site-footer {
width: min(100% - 2rem, 48rem);
margin-inline: auto;
}
.site-header {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 1rem;
padding-block: 1.5rem;
border-bottom: 1px solid #c9cec4;
}
.site-name { font-size: 1.2rem; font-weight: 750; }
.site-nav { display: flex; flex-wrap: wrap; gap: 1rem; }
.site-body a { color: #315f40; text-underline-offset: 0.2em; }
.site-body a:focus-visible {
outline: 3px solid #825414;
outline-offset: 4px;
}
.site-main { padding-block: 2.5rem; }
.site-main h1 { font-size: clamp(2rem, 7vw, 3rem); line-height: 1.15; }
.site-main p { max-width: 65ch; }
.site-main figure { margin: 2rem 0; }
.site-image { display: block; max-width: 100%; height: auto; border-radius: 1rem; }
.site-main figcaption { margin-top: 0.6rem; color: #4b594e; }
.site-footer { border-top: 1px solid #c9cec4; padding-block: 1.5rem; }
.skip-link {
position: absolute;
top: -10rem;
left: 1rem;
padding: 0.6rem 1rem;
background: #fff;
z-index: 10;
}
.skip-link:focus { top: 1rem; }
Check
- Open all three pages. Each should have the same header and “Made one page at a time.” footer, with one main heading and one main content area.
- Check the browser tabs: “My website,” “About | My website,” and “Contact | My website.” In browser page source, find one
<html>, one<head>and one<body>. The description should match each page's override or directory default. - Temporarily change the footer sentence in
components/layout.html. Confirm the change on all three pages, then restore the sentence. You should not edit the page files to change the footer. - Narrow the browser to a phone-sized width. Navigation can wrap; content should not need horizontal scrolling. Press Tab from the top: “Skip to content” should become visible. Follow it to move focus to the main content. Reload, then tab through the navigation links to check visible focus.
Do not continue until titles, inherited defaults and shared content all match.
Recover
These are anticipated mistakes to diagnose before replacing any files:
- A title is wrong: check the page's
<what>block first, thensite/application.what. The page wins when it supplies the same setting. Use=and quote the complete text. - Navigation or main content is duplicated: compare your page with the complete source above. Only the layout contains the shared navigation,
<main>, and document tags. - The shared layout or styles are absent: check the exact layout path and
/static/styles.css. Read any terminal diagnostic with its filename, line number and suggested fix. The dev server stays running while you correct the file; a build rejects malformed configuration. Save the corrected file and refresh.
If you need a clean comparison, download the L02 source checkpoint for this lesson. It is a copy of the project at this point, not a separately installed template. It contains source files and a checksum manifest; it excludes sessions and runtime databases. Keep your project and extract into a new folder. For example, after placing that archive in Downloads, stop your dev server and run these commands from the folder that contains my-site:
mkdir my-site-recovery-L02 && unzip -n "$HOME/Downloads/L02.zip" -d my-site-recovery-L02
If the folder already exists, the first command fails and extraction does not run. Pick another new name; do not empty an existing folder. After successful extraction:
cd my-site-recovery-L02
run-what dev
Reapply this lesson there. Optional exercises are not part of the required checkpoint; keep your own variations in your original project.
Try
Optional: add a “Back to top” link to the shared footer. Give its target a matching HTML id, then check the link on all three pages. You should only need to edit the layout. Extra exercise content is not needed for the next checkpoint.
Continue
You can now maintain a whole site's frame and defaults in one place. Next, build a reusable card to share smaller pieces of content inside a page.