Sub topic 1
Start with a Valid HTML Document
Prerequisites
You should know how to use a text editor, save files, open an HTML file in a browser, and work with folders and file extensions.
Start with a valid HTML document
HTML (HyperText Markup Language) defines a page's structure. Start with a document type declaration, then add the html, head, and body elements.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Jane Doe | Web Developer</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main>
<h1>Jane Doe</h1>
</main>
</body>
</html><!DOCTYPE html> tells the browser to use modern HTML. The lang attribute identifies the document language. The viewport setting makes the layout use the device width instead of a desktop-sized virtual canvas. The title appears in the browser tab.
Structure the page with semantic elements
Semantic elements describe a region's purpose. They help browsers, search engines, and assistive technology understand the page.
A personal site commonly uses header for introductory content and navigation, main for the unique page content, section for related content groups, and footer for closing information.
flowchart TD
A[Page] --> B[header]
A --> C[main]
A --> D[footer]
C --> E[about section]
C --> F[projects section]
C --> G[contact section]Add your content: headings, text, lists, links and images
Headings create a hierarchy. Use one h1 for the page topic, then use h2 headings for major sections. Paragraphs hold prose, lists hold grouped items, and links point to destinations.
<section id="projects">
<h2>Projects</h2>
<ul>
<li>Recipe planner</li>
<li>Weather dashboard</li>
</ul>
<p>
View my <a href="https://example.com/projects">project archive</a>.
</p>
<img
src="portrait.jpg"
width="800"
height="800"
alt="Portrait of Jane Doe at her desk">
</section>An image's alt attribute provides an equivalent description. Use an empty value, alt="", only when an image is decorative.
Connect a stylesheet and write your first rules
CSS (Cascading Style Sheets) controls presentation. The link element connects styles.css to the HTML document. A CSS rule has a selector and declarations.
body {
margin: 0;
font-family: system-ui, sans-serif;
line-height: 1.6;
color: #1f2933;
background: #ffffff;
}
main {
max-width: 60rem;
margin: 0 auto;
padding: 2rem 1rem;
}The body selector targets the page body. Each declaration changes one property. Keep structure in HTML and visual decisions in CSS.
Exercise
Which element should contain the page's unique primary content?
Show answer
The main element.