Sub topic 1
What HTML Is and How Browsers Use It
Prerequisites
Assume you can create and save a text file, open a local file in a browser, and browse websites. No prior HTML knowledge is required.
HTML and the Browser
HTML, or HyperText Markup Language, describes the structure and meaning of web content. It is a markup language, not a programming language. An HTML file contains text surrounded by markup. A browser parses that markup, builds a document tree, and uses the tree to display the page.
HTML describes structure. CSS controls presentation, and JavaScript adds behavior.
Elements, Tags, and Attributes
An element usually has a start tag, content, and an end tag:
<p>HTML describes content.</p>Here, <p> is the start tag, the sentence is the content, and </p> is the end tag. Together, they form a paragraph element.
An attribute adds information to an element. It appears inside the start tag as a name-value pair:
<a href="/about" title="About this site">About</a>The href attribute supplies the link destination. The title attribute supplies additional information. Some elements, such as img, do not wrap content and have no end tag.
The Document Skeleton
A complete document normally has this structure:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My First Page</title>
</head>
<body>
<h1>Hello, HTML</h1>
<p>This is a paragraph.</p>
</body>
</html><!DOCTYPE html> puts the browser in standards mode. The html element contains the document and declares its language. The head contains metadata, while the body contains visible page content.
Metadata in the Head
Metadata is information about the document. The title appears in the browser tab and helps identify the page. meta charset="utf-8" selects a character encoding that supports most written languages. The viewport setting helps the page fit mobile screens.
Keep metadata in head, not in body. Visible headings and paragraphs belong in body.
Headings and Paragraphs
Use headings to describe hierarchy. A page usually has one h1, followed by h2 and, when needed, h3 headings. Do not choose a heading because of its default size. Use CSS for appearance.
Use p for a paragraph. Do not use repeated line breaks to create structure.
Exercise
Where should a page's main heading and paragraphs go?
Show answer
They should go inside the body element, because body contains the document's visible content.