Introduction to Web Technologies (HTML, CSS, JS)

Chapter 3
HTML Documents and Semantic Structure

Diploma in Full Stack Programming
Introduction to Web Technologies (HTML, CSS, JS)   •   Diploma

HTML Documents and Semantic Structure

Introduction

HTML, or HyperText Markup Language, is the standard markup language used to structure content on the World Wide Web. It is not a programming language: HTML describes the meaning and organization of content, while CSS controls presentation and JavaScript adds behavior. A well-constructed HTML document provides a reliable foundation for accessibility, search-engine interpretation, maintainability, responsive design, and application development.

In professional web development, HTML is more than a collection of tags. It is a document model. Elements communicate relationships among headings, paragraphs, navigation links, articles, forms, images, and other content. These relationships form a semantic structure that can be interpreted by browsers, assistive technologies, search engines, content-management systems, and developers.

This chapter explains how to create valid HTML documents, add metadata, construct document hierarchies, use semantic elements and landmarks, create lists and links, and represent special characters with character references.

Learning Objectives

By the end of this chapter, you should be able to:

  • construct a valid HTML document using the HTML5 document structure;
  • explain the purpose of the head and body elements;
  • use metadata correctly, including character encoding and viewport information;
  • organize content with headings, paragraphs, lists, and links;
  • distinguish generic containers from semantic elements;
  • identify and apply common page landmarks;
  • use character entities and references safely;
  • evaluate document hierarchy for accessibility and maintainability; and
  • design a semantically structured page for a realistic web application.

1. The HTML Document Model

An HTML document is a tree of elements. Elements may contain text, other elements, or both. This nested organization is called the Document Object Model (DOM) when represented in memory by a browser.

A minimal modern HTML document is:

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Introduction to Web Technologies</title>
  </head>
  <body>
    <h1>Introduction to Web Technologies</h1>
    <p>This page introduces HTML, CSS, and JavaScript.</p>
  </body>
</html>

The <!doctype html> declaration tells the browser to use standards mode. It is a declaration rather than an HTML element. The root html element contains two major parts:

  • head: machine-readable information about the document; and
  • body: content displayed or made available to users.

The lang attribute identifies the primary language. It supports screen readers, translation tools, search engines, and pronunciation systems. The value should reflect the actual language, such as en, fr, or en-GB.

HTML elements normally have an opening tag and a closing tag:

<p>Web documents use elements to express structure.</p>

Some elements are void elements and do not have closing tags. Examples include meta, link, img, input, br, and hr:

<meta charset="utf-8">
<img src="logo.svg" alt="College logo">

HTML is generally case-insensitive in tag names, but professional code uses lowercase consistently. Attribute values should be quoted. Clear indentation makes nesting easier to inspect and maintain.

Nesting and hierarchy

Elements must be nested correctly. The following is valid:

<strong><em>Important information</em></strong>

The following is incorrectly nested because the elements overlap:

<strong><em>Important information</strong></em>

Browsers often attempt to repair malformed markup, but relying on error recovery is poor practice. Different tools may interpret invalid structure differently, and accessibility technologies may receive an unclear document tree.

2. Metadata and the Document Head

Metadata is information about a document rather than the main content presented in the page. It is placed primarily in the head element.

Character encoding

<meta charset="utf-8">

UTF-8 can represent a very broad range of writing systems and symbols. Declaring it early helps the browser decode the document correctly. Incorrect encoding can produce replacement characters or unreadable text.

The title

The title element is required in practical web pages and should describe the page clearly. It is used in browser tabs, bookmarks, browser history, search results, and assistive technology contexts.

<title>Admissions Requirements | Northbridge College</title>

A title such as Page 1 is technically possible but professionally unhelpful. A useful title identifies the page purpose and, when appropriate, the organization.

Viewport metadata

<meta name="viewport" content="width=device-width, initial-scale=1">

This helps mobile browsers map the layout viewport to the device width. It does not by itself make a page responsive; responsive behavior still requires suitable HTML, CSS, and sometimes JavaScript.

Descriptions and other metadata

A description may be included for search-engine result snippets:

<meta name="description" content="Explore diploma programmes, entry requirements, and application dates.">

Metadata should be accurate and concise. It is not a substitute for meaningful visible content. Excessive or misleading metadata can damage usability and search performance.

Linking external resources

The link element associates the document with an external resource, commonly a stylesheet or icon:

<link rel="stylesheet" href="styles/site.css">
<link rel="icon" href="images/favicon.svg" type="image/svg+xml">

A stylesheet should normally be referenced from the head. The link element does not display ordinary page content.

3. Headings and Document Hierarchy

Headings communicate the outline and organization of a page. HTML provides six heading levels, from h1 to h6.

<h1>Student Services</h1>
<h2>Library</h2>
<h3>Opening Hours</h3>
<h3>Borrowing Rules</h3>
<h2>Career Support</h2>

The h1 usually identifies the page's main subject. An h2 identifies a major subsection, and an h3 identifies a subsection within that h2 section. Heading levels should reflect logical relationships rather than visual size.

A heading should not be selected merely because its default browser styling looks attractive. CSS should control appearance:

<h2 class="display-heading">Course Overview</h2>
.display-heading {
  font-size: 2rem;
}

Do not skip levels without a structural reason, such as moving from h2 directly to h4. A skipped level can make navigation confusing for users who browse by headings. Multiple h1 elements may be valid in particular sectioning structures, but a single clear page-level h1 is usually the most understandable choice for diploma-level projects.

Headings are not the same as bold text. Use a heading when the text introduces a section. Use strong when content has strong importance within a sentence.

4. Paragraphs and Text-Level Semantics

The p element represents a paragraph:

<p>Semantic HTML describes what content means, not merely how it looks.</p>

Whitespace and line breaks in source code are generally collapsed when rendered. Use separate paragraphs for separate ideas rather than inserting repeated <br> elements.

Useful text-level elements include:

ElementMeaning or use
strongStrong importance
emEmphasis that changes meaning or stress
markText relevant in the current context
abbrAbbreviation, optionally with a title
codeShort fragment of computer code
timeA date or time, optionally machine-readable
qShort inline quotation
brA meaningful line break, not general spacing

Example:

<p>
  The <abbr title="HyperText Markup Language">HTML</abbr>
  document contains a <strong>clear structure</strong>.
  Use the <code>lang</code> attribute to identify language.
</p>
<p>The workshop begins on <time datetime="2025-09-15">15 September 2025</time>.</p>

The time element may contain a human-readable date while its datetime attribute provides a machine-readable value. This supports calendars, search tools, and data processing.

5. Lists

Lists are appropriate when items form a meaningful group. HTML offers three principal list types.

Unordered lists

Use ul when order is not significant:

<ul>
  <li>HTML</li>
  <li>CSS</li>
  <li>JavaScript</li>
</ul>

Ordered lists

Use ol when sequence or ranking matters:

<ol>
  <li>Plan the page structure.</li>
  <li>Write semantic HTML.</li>
  <li>Validate the document.</li>
</ol>

Description lists

Use dl, dt, and dd for terms and their descriptions, not merely for visually arranged data:

<dl>
  <dt>Element</dt>
  <dd>A component of an HTML document.</dd>
  <dt>Attribute</dt>
  <dd>Additional information associated with an element.</dd>
</dl>

List items must be placed inside ul, ol, or menu. Do not create lists by placing hyphens or numbers in ordinary paragraphs. Real lists provide structure to screen readers and enable consistent styling.

Lists can be nested when the relationship requires it:

<ul>
  <li>Frontend
    <ul>
      <li>HTML</li>
      <li>CSS</li>
    </ul>
  </li>
  <li>Backend</li>
</ul>

6. Links and Navigation

The anchor element creates a hyperlink when it has an href attribute:

<a href="about.html">About the programme</a>

Link text should describe the destination or action. “Read more” is weak when several links have the same wording. Prefer “Read the assessment policy” or “View the module timetable.”

Common URL forms include:

<a href="/courses/web-development">Absolute path on this site</a>
<a href="https://developer.mozilla.org/">External website</a>
<a href="#entry-requirements">Jump to a section</a>
<a href="mailto:[email protected]">Email admissions</a>

The target of a fragment link must have a matching id:

<h2 id="entry-requirements">Entry Requirements</h2>

Use target="_blank" cautiously. When opening a new tab is necessary, indicate it to users and use an appropriate relationship:

<a href="https://example.org/report" target="_blank" rel="noopener">
  Download the external report (opens in a new tab)
</a>

A button performs an action, such as submitting a form or opening a dialog. An a element navigates to a resource. Replacing one with the other harms keyboard behavior, semantics, and accessibility.

7. Semantic Elements and Landmarks

Semantic elements communicate the role of content. They are preferable to using div for every part of a page.

Common semantic elements include:

  • header: introductory content for a page or section;
  • nav: a major group of navigation links;
  • main: the dominant content of the document;
  • section: a thematic grouping, normally with a heading;
  • article: a self-contained composition that could stand alone;
  • aside: related but secondary content;
  • footer: closing information for a page or section;
  • figure and figcaption: self-contained media and its caption; and
  • address: contact information for the relevant person or organization.

These elements create landmarks that assistive technology users can navigate. A typical page may be structured as follows:

<body>
  <header>
    <a href="/">Northbridge College</a>
    <nav aria-label="Primary navigation">
      <ul>
        <li><a href="/courses">Courses</a></li>
        <li><a href="/admissions">Admissions</a></li>
        <li><a href="/contact">Contact</a></li>
      </ul>
    </nav>
  </header>

  <main>
    <h1>Diploma in Full Stack Programming</h1>
    <section>
      <h2>Programme Overview</h2>
      <p>Students learn client-side and server-side development.</p>
    </section>
    <aside>
      <h2>Related Information</h2>
      <p>Applications close on 30 June.</p>
    </aside>
  </main>

  <footer>
    <p>© 2025 Northbridge College</p>
  </footer>
</body>

A document should generally contain one main element. Repeated site-wide navigation belongs in nav, while a group of links specific to a page may also be a navigation landmark if it is a major navigation block. The aria-label distinguishes navigation regions when a page contains more than one.

section versus div

Use section for a thematic grouping, usually with a heading. Use div when a generic container is needed for styling or scripting and no more specific semantic element applies.

<section>
  <h2>Assessment</h2>
  <p>Assessment consists of practical projects and examinations.</p>
</section>

<div class="card-grid">
  <!-- Generic layout container -->
</div>

A semantic element should not be chosen merely because it sounds appropriate. Its content and role must justify its use.

article versus section

An article is independently distributable or reusable, such as a news story, blog entry, forum post, or product review. A section groups related content within a broader document. An article may contain sections, and a page may contain multiple articles.

8. Character References and Special Characters

HTML uses certain characters as syntax. The less-than sign begins a tag, and the ampersand begins a character reference. To display such characters as text, use references:

CharacterReference
<&lt;
>&gt;
&&amp;
"&quot;
non-breaking space&nbsp;
©&copy;
®&reg;
€&euro;

Example:

<p>Use &lt;h1&gt; for the main heading.</p>
<p>Northbridge College &copy; 2025</p>

Numeric references are also possible, for example &#169; or &#xA9; for ©. UTF-8 makes it possible to write many Unicode characters directly, but syntax-sensitive characters still require careful escaping in text and attribute values.

Do not use repeated &nbsp; characters to create layout. Use CSS for spacing. Be especially careful when inserting user-provided text into HTML: unescaped input can create cross-site scripting vulnerabilities. Context-sensitive output encoding and safe templating are essential security practices.

9. Accessibility and Quality Practice

Semantic HTML is a central accessibility technique. It gives browsers and assistive technologies meaningful information without requiring custom scripts.

Important practices include:

  1. Declare the document language with lang.
  2. Use a meaningful page title.
  3. Maintain a logical heading hierarchy.
  4. Provide descriptive link text.
  5. Use landmarks consistently.
  6. Ensure interactive controls are keyboard accessible.
  7. Provide alternative text for informative images.
  8. Use tables only for tabular data, with appropriate headings.
  9. Do not communicate essential information through colour alone.
  10. Validate HTML and test with keyboard navigation and assistive technologies.

For example, an informative image should have useful alternative text:

<img src="campus.jpg" alt="Students collaborating in the web development laboratory">

A decorative image should have an empty alternative attribute:

<img src="decorative-line.svg" alt="">

The alt attribute should not repeat nearby text unnecessarily. If an image is the content of a link, the alternative text should describe the link destination or action.

Validation tools can identify unclosed elements, invalid attributes, duplicate IDs, and structural errors. Validation does not guarantee that a page is usable or accessible, but it is an important quality-control step.

10. Applied Case: Structuring a College Programme Page

Background

This illustrative case concerns a college creating a public page for its Diploma in Full Stack Programming. The original page was built almost entirely from div elements. It contained headings styled with large fonts, links labelled “Click here,” and several visually distinct regions that were not identifiable to screen readers.

Problem

Users reported difficulty finding the course description and application link. Keyboard users had to move through many irrelevant elements, and search engines did not clearly identify the page's main subject. The development team also found the page difficult to maintain because layout containers and content sections were indistinguishable.

Analysis

The team mapped the intended information architecture:

  • the college identity and primary navigation belong in header and nav;
  • the course information belongs in main;
  • overview, modules, assessment, and entry requirements are thematic section elements;
  • an admissions notice is related secondary content and may be an aside;
  • the page title is the main h1; and
  • links should describe their destinations.

Approach and solution

The revised structure was:

<main>
  <h1>Diploma in Full Stack Programming</h1>

  <section>
    <h2>Programme Overview</h2>
    <p>Build practical skills in HTML, CSS, JavaScript, databases, and server development.</p>
    <p><a href="#modules">View the programme modules</a></p>
  </section>

  <section id="modules">
    <h2>Programme Modules</h2>
    <ol>
      <li>Introduction to Web Technologies</li>
      <li>Client-Side JavaScript</li>
      <li>Server-Side Programming</li>
    </ol>
  </section>

  <section>
    <h2>Entry Requirements</h2>
    <p>Applicants should have completed secondary education or equivalent study.</p>
  </section>

  <aside>
    <h2>Apply Now</h2>
    <p><a href="/apply">Start an application</a></p>
  </aside>
</main>

Outcome

The revised document offered a clearer heading outline, meaningful landmarks, more useful links, and a logical reading order. CSS could still produce the desired visual design, but the underlying structure no longer depended on visual styling. The page became easier to test, maintain, index, and navigate with assistive technology.

Learning points

Semantic HTML is an information-architecture decision. It should be planned before detailed styling. Good markup improves several outcomes simultaneously: accessibility, maintainability, search interpretation, collaboration, and resilience when CSS or JavaScript fails.

11. Limitations and Contemporary Practice

Semantic HTML does not solve every usability problem. Poor colour contrast, confusing interaction design, inaccessible custom widgets, slow performance, and unsuitable content can remain even when the markup is valid. Accessibility requires testing with real users and assistive technologies, not only automated validation.

HTML specifications evolve. Developers should consult current standards and reliable technical documentation rather than depending on outdated tag lists. Some older presentational elements, such as font and center, should not be used. Presentation belongs in CSS. Deprecated elements may continue to render in browsers, but they reduce maintainability and can encourage incorrect separation of concerns.

Web components and JavaScript frameworks can introduce custom elements, but framework abstractions do not remove the need for semantic HTML. A component should still expose correct headings, names, roles, states, focus behavior, and keyboard interaction. Where native HTML provides the required behavior, it is usually safer and more accessible than recreating it with scripts.

Best-Practice Checklist

Before publishing an HTML page, check that:

  • the doctype is present;
  • the document has html, head, and body elements;
  • lang, charset, viewport, and title are appropriate;
  • headings express a logical hierarchy;
  • the page has a clear main landmark;
  • navigation is marked with nav where appropriate;
  • sections have meaningful headings;
  • links describe their destinations;
  • lists use the correct list element;
  • special characters are represented safely;
  • IDs are unique;
  • images have suitable alternative text;
  • generic div elements are used only where no semantic element applies; and
  • the document has been validated and tested with keyboard navigation.

Chapter Summary

HTML provides the structural and semantic foundation of web pages. A valid document begins with the HTML5 doctype and contains a root html element with head and body regions. Metadata such as character encoding, viewport configuration, title, description, and stylesheet references supports correct interpretation and use of the page.

Headings establish hierarchy, paragraphs express blocks of prose, and lists represent grouped or ordered items. Links should identify their destinations and should be distinguished from buttons, which perform actions. Semantic elements such as header, nav, main, section, article, aside, and footer communicate document roles and create useful landmarks. Character references allow syntax-sensitive characters to be displayed safely.

Professional HTML development requires more than visual correctness. Logical structure, accessibility, validation, security-conscious text handling, and maintainable semantics are essential. CSS can change presentation without changing meaning, and JavaScript can enhance behavior without replacing the document's underlying structure.

Key Terms

HTML: HyperText Markup Language used to structure web documents.

Element: A structural component of an HTML document.

Tag: Markup notation used to create or identify an element.

Attribute: Additional information associated with an element.

Doctype: Declaration that places the browser in standards mode.

DOM: Document Object Model representing a document as a tree of objects.

Metadata: Information about a document, normally placed in head.

Semantic HTML: Markup that communicates the meaning and role of content.

Landmark: A region that supports navigation by assistive technologies.

Heading hierarchy: Logical organization created by h1 through h6.

Viewport: The area through which a web page is viewed.

Character reference: Notation used to represent a character in HTML.

Void element: An element that does not contain content or require a closing tag.

Hyperlink: A reference that allows navigation to another resource or location.

Fragment identifier: A URL component that targets an element with a matching id.

Alternative text: Text that communicates the purpose of an image when it cannot be perceived.

Validation: Checking markup against HTML syntax and conformance rules.

Accessibility: Designing content so that people with diverse abilities can use it.

Sectioning element: An element that groups related content and contributes to document structure.

Review Questions

Short Answer Questions

  1. What are the primary purposes of the head and body elements?
  2. Why should a document declare its language with the lang attribute?
  3. When should an ordered list be used instead of an unordered list?
  4. What is the difference between a link and a button?
  5. Why are character references needed for symbols such as < and &?

Long Answer Questions

  1. Explain the structure of a valid HTML5 document and discuss the role of its principal metadata elements.
  2. Describe how headings, sections, and landmarks work together to create an accessible document hierarchy.
  3. Compare section, article, aside, and div, giving an appropriate use case for each.
  4. Explain how semantic HTML benefits accessibility, search interpretation, maintainability, and progressive enhancement.
  5. Discuss professional practices for creating accessible links, lists, images, and text content.

Analytical / Application Questions

  1. A college page uses large styled paragraphs instead of headings and labels every navigation link “More.” Identify the structural and accessibility problems and propose a revised approach.
  2. Design the semantic structure for a news page containing a site header, primary navigation, one lead story, three related stories, a publication date, and a footer. Justify your choice of elements.
  3. Inspect a page containing several div elements, two main elements, skipped heading levels, and an external link that opens a new tab without warning. Explain the risks and provide a prioritized correction plan.

Multiple Choice Questions with Answers

Question 1

Which element contains metadata such as the document title and character encoding?

A. body

B. head

C. main

D. section

Correct Answer: B. head

Question 2

Which element normally identifies the dominant content of a page?

A. main

B. aside

C. footer

D. nav

Correct Answer: A. main

Question 3

Which list type is most appropriate when the sequence of steps matters?

A. ul

B. dl

C. ol

D. menu

Correct Answer: C. ol

Question 4

What is the primary purpose of the lang attribute on the html element?

A. To select a stylesheet

B. To identify the document language

C. To define the page title

D. To enable JavaScript

Correct Answer: B. To identify the document language

Question 5

Which element is most appropriate for a self-contained news story?

A. article

B. div

C. br

D. span

Correct Answer: A. article

Question 6

Which HTML reference displays a literal less-than sign?

A. &gt;

B. &amp;

C. &lt;

D. &quot;

Correct Answer: C. &lt;

Question 7

What should normally be used to control the visual size of a heading?

A. Choosing a heading level only for its appearance

B. CSS

C. Repeated br elements

D. Non-breaking spaces

Correct Answer: B. CSS

Question 8

Which element is intended for navigation links?

A. nav

B. address

C. figure

D. time

Correct Answer: A. nav

Question 9

What is the best link text for a link leading to an assessment policy?

A. Click here

B. More

C. Read this

D. Read the assessment policy

Correct Answer: D. Read the assessment policy

Question 10

Which element represents a generic container when no more meaningful semantic element applies?

A. div

B. article

C. main

D. header

Correct Answer: A. div

Introduction to Web Technologies (HTML, CSS, JS)
Chapter 3 of 15