In this project you will build a complete blog article page: a travel guide to Sylhet in the monsoon. It brings together the newest techniques from this part of the series. Cascade layers organise the CSS, grid areas build the layout, and logical properties handle spacing. aspect-ratio frames the photo, and clip-path shapes the header. Counters number the sections, a data attribute adds a label, and good typography keeps the text easy to read. A print stylesheet makes it look right on paper too.
In this project you will
- Structure an article with semantic HTML
- Organise CSS into cascade layers
- Build a responsive layout with named grid areas
- Number sections automatically and add a sticky table of contents
- Add print styles
You should know semantic HTML, grid template areas, cascade layers and web typography.
The Finished Page
Result
Scroll inside the frame to see the whole article. On a narrow screen, the table of contents moves above the article.
The Complete Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Monsoon in Sylhet: A Weekend Travel Guide</title>
<style>
@layer base, layout, components, utilities;
@layer base {
* { box-sizing: border-box; }
:root { --accent: #00796b; --muted: #5f6b6d; --paper: #fdfcf8; }
body { margin: 0; font-family: system-ui, "Segoe UI", Roboto, sans-serif;
color: #222; background: var(--paper); line-height: 1.6; }
h1, h2 { line-height: 1.2; text-wrap: balance; }
a { color: var(--accent); }
img { max-inline-size: 100%; display: block; }
}
@layer layout {
.site {
display: grid;
grid-template-columns: 1fr minmax(0, 60ch) 200px 1fr;
grid-template-areas:
"hero hero hero hero"
". main aside .";
column-gap: 28px;
}
.hero { grid-area: hero; }
main { grid-area: main; counter-reset: section; }
aside { grid-area: aside; }
@media (max-width: 720px) {
.site { grid-template-columns: 1fr; grid-template-areas: "hero" "aside" "main"; padding-inline: 16px; }
}
}
@layer components {
.hero {
background: linear-gradient(120deg, #00796b, #26a69a 60%, #80cbc4);
color: white; padding-block: 40px 70px; padding-inline: 24px; text-align: center;
clip-path: polygon(0 0, 100% 0, 100% 80%, 0 100%);
}
.hero h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); margin: 0 auto 8px; max-inline-size: 22ch; }
.meta { color: #e0f2f1; font-size: 0.9rem; }
main h2 { counter-increment: section; font-size: 1.25rem; margin-block: 1.6em 0.4em; }
main h2::before { content: counter(section) ". "; color: var(--accent); }
.photo { aspect-ratio: 16 / 9; inline-size: 100%; object-fit: cover; border-radius: 10px;
background: #a5d6a7; }
figcaption { color: var(--muted); font-size: 0.85rem; margin-block-start: 4px; }
.tip { border-inline-start: 4px solid var(--accent); padding: 8px 14px;
background: #e0f2f1; border-radius: 0 8px 8px 0; margin-block: 1em; }
.toc { position: sticky; top: 12px; font-size: 0.9rem; padding-block-start: 1.6em; }
.toc ol { padding-inline-start: 20px; margin: 0; }
.toc li::marker { color: var(--accent); font-weight: bold; }
.tag { display: inline-block; font-size: 0.75rem; padding: 2px 10px; margin-inline-end: 4px;
border-radius: 999px; background: #fff; color: var(--accent); }
.tag[data-level="easy"]::after { content: " · " attr(data-level); }
}
@layer utilities {
.visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
}
@media print {
.hero { clip-path: none; background: none; color: black; }
aside { display: none; }
a::after { content: " (" attr(href) ")"; font-size: 0.8em; }
}
</style>
</head>
<body>
<div class="site">
<header class="hero">
<h1>Monsoon in Sylhet: A Weekend Travel Guide</h1>
<p class="meta">By Tania Rahman · <time datetime="2026-07-14">14 July 2026</time> · 6 min read</p>
<span class="tag">Travel</span><span class="tag" data-level="easy">Hiking</span>
</header>
<aside class="toc" aria-labelledby="toc-title">
<h2 id="toc-title" class="visually-hidden">Contents</h2>
<strong>On this page</strong>
<ol>
<li><a href="#go">Getting there</a></li>
<li><a href="#see">What to see</a></li>
<li><a href="#pack">What to pack</a></li>
</ol>
</aside>
<main>
<article>
<p>When the rains arrive, Sylhet's tea gardens turn a brighter green and the waterfalls come back to life. This guide covers a relaxed two-day trip.</p>
<h2 id="go">Getting there</h2>
<p>Trains and buses run from Dhaka every day. The train takes longer but the views are worth it.</p>
<h2 id="see">What to see</h2>
<figure>
<img class="photo" alt="Rows of tea bushes on green hills under a cloudy sky"
src="hills.jpg">
<figcaption>Tea gardens near Srimangal after the rain.</figcaption>
</figure>
<p>Walk through a tea estate in the morning, then visit a waterfall in the afternoon when the light is softer.</p>
<p class="tip"><strong>Tip:</strong> paths get slippery in the monsoon. Wear sandals with a good grip.</p>
<h2 id="pack">What to pack</h2>
<p>An umbrella, a light rain jacket, insect repellent and a dry bag for your phone.</p>
</article>
</main>
</div>
</body>
</html>
How It Works
- Layers:
@layer base, layout, components, utilities;fixes the order of the four groups. A utility class can always override a component, with no specificity battles. - Variables: the accent colour, muted text colour and paper colour are custom properties in
:root, so the whole theme can change in one place. - Layout: the grid has four columns: two flexible margins, a reading column of up to 60ch and a 200px sidebar.
grid-template-areasputs the hero across all four and the article and sidebar side by side. Below 720px the map is redrawn as a single column, with the contents list above the article. - Header: a gradient hero with a
clip-pathpolygon gives a slanted bottom edge. The title usesclamp()for fluid size,max-inline-size: 22chandtext-wrap: balanceso it breaks neatly. - Numbering:
mainresets asectioncounter; eachh2increases it and shows the number with::before. The table of contents is an ordered list whose::markeruses the accent colour. - Sticky sidebar:
position: sticky; top: 12pxkeeps the contents in view while the reader scrolls through a long article. - Photo:
aspect-ratio: 16 / 9withobject-fit: coverkeeps the picture’s shape at any width, and thealttext describes it for screen readers. - Logical properties: spacing uses
padding-block,padding-inline,margin-blockandborder-inline-start, so the page would flip correctly if translated into a right-to-left language. - Data attribute: the hiking tag has
data-level="easy", and CSS adds ” · easy” withattr(). - Accessibility: the sidebar is labelled by a heading that is hidden visually but still read by screen readers, using the
.visually-hiddenutility. The date uses<time datetime>so machines can read it. - Print: the
@media printblock removes the coloured header shape and the sidebar, and prints each link’s address after its text, so a paper copy still shows where links go.
Ideas to Extend the Project
- Add a dark mode by changing the custom properties inside
@media (prefers-color-scheme: dark). - Add an author box at the end with a round photo made with
aspect-ratio: 1andborder-radius: 50%. - Add a comment form with built-in validation.
- Add Open Graph and description meta tags so the article looks good when shared.
- Highlight the current section in the table of contents with a little JavaScript and an Intersection Observer.
Common Mistakes
- A reading column with no maximum width, giving very long lines on large screens.
- Typing section numbers into headings by hand, which go wrong as soon as a section is added. Let counters do it.
- Forgetting
minmax(0, 60ch): with plain60ch, a long word or wide image can push the column wider than the screen. - Images without
alttext, which leaves screen-reader users with nothing.
Practice Exercises
Exercise 1. Add a “Note” box style that uses a different accent colour, written in the components layer and using logical properties.
Show answer
@layer components {
.note {
border-inline-start: 4px solid #f9a825;
background: #fff8e1;
padding-block: 8px;
padding-inline: 14px;
margin-block: 1em;
}
}
Exercise 2. Change the layout so the sidebar appears on the left on wide screens.
Show answer
.site {
grid-template-columns: 1fr 200px minmax(0, 60ch) 1fr;
grid-template-areas:
"hero hero hero hero"
". aside main .";
}
Only the column sizes and the area map change; the HTML stays the same.
Frequently Asked Questions
Why use cascade layers on a single page?
Even on one page, layers make the stylesheet easier to grow. When the site later gets more pages, a library or a theme, the order of the groups is already clear, and new rules do not need ever more specific selectors.
How can I check the print styles?
Open the browser’s print preview (Ctrl+P), or in Chrome’s developer tools open the Rendering panel and set “Emulate CSS media type” to print.
Summary
- Semantic HTML gives the article a clear structure for browsers, search engines and screen readers.
- Cascade layers and custom properties keep the CSS organised and easy to change.
- Grid areas, logical properties,
aspect-ratioandclip-pathbuild a responsive, modern layout. - Counters, a sticky contents list and print styles finish a professional reading experience.
Back to the start of the series: HTML Introduction.
