HTML Document Structure
An HTML document follows a standardized structure that allows
browsers to correctly parse and render content. This structure
separates metadata from visible content, ensuring clarity and
consistency across devices and browsers.
A well-structured document improves accessibility, search engine
optimization (SEO), and long-term maintainability. Browsers
process HTML from top to bottom and construct an internal
representation of the page before displaying it.
Key Points
- HTML has a predictable document structure
- Structure affects accessibility and SEO
- Poor structure can cause rendering issues
Doctype and standard mode
The <!DOCTYPE /> declaration tells the browser
to render the page using modern web standards. Without it,
browsers may switch to quirks mode, which emulates older behavior
and can break layouts.
Using the correct doctype ensures consistency and enables modern
HTML features.
Key Points
- Enables standards mode
- Prevents quirks mode
- Required for predictable layouts
Review Questions
- What is quirks mode?
- Why is standards mode important?
Browser Rendering and the DOM
Browsers parse HTML into the DOM before rendering. Invalid markup
can delay rendering and cause unpredictable behavior.
Understanding rendering helps improve performance.
Review Questions
- What is DOM
- How does invalid HTML affect rendering?
HTML Nesting and Content Hierarchy
HTML elements exist in a hierarchical structure where elements can
contain other elements. This hierarchy forms the Document Object
Model (DOM).
Correct nesting preserves meaning and ensures that browsers and
assistive technologies understand content relationships. Improper
nesting can lead to broken layouts and accessibility problems.
The <html> element contains
<head> and <body>.This
nesting helps browsers understand how content is structured.
Key Points
- Helps browsers understand how content is structured.
- Preserves content meaning
- Elements follow a parent–child hierarchy.
Review Questions
- How does incorrect nesting affect screen readers?
- Why is hierarchy important beyond visual layout?
Using Semantic Tags
Semantic tags uses meaningful elements to describe content
structure. It creates landmarks that help users navigate
efficiently.
Examples include <header>,
<nav>, <main>,
<section>, <article>, and
<footer>.
Benefits
- Improved accessibility
- Better SEO
- Easier maintenance
Headings and Document Outline
Headings
Headings define the logical outline of a document. They help users
scan content and allow assistive technologies to provide efficient
navigation. Headings should be used based on importance, not
appearance. Skipping heading levels can confuse both users and
machines.
Key Points
- One primary heading per page is recommended
- Headings should follow logical order
- Headings improve SEO and accessibility
Review Questions
- Why should headings not be chosen for styling?
- How do headings help screen reader users?
Headings and Document Outline
Text Semantics: Emphasis vs Importance
Semantic text elements communicate meaning rather than appearance.
Emphasis changes how text is read or interpreted, while importance
highlights critical information. Using semantic text correctly
improves accessibility and clarity.
Key Points
- Meaning is more important than styling
- Assistive technologies rely on semantics
Review Questions
- How is semantic emphasis different from visual styling?
- When should importance be used?
HTML Attributes
Attributes provide additional information about elements. They
influence styling, behavior, accessibility, and interactivity.
Some attributes apply globally, while others are specific to
certain elements. Incorrect or missing attributes can break
functionality and accessibility.
Example:
//id, href and class are attributes
<a id="attribute" href="example.com"></a>
In this example, id="attribute" and
href="url" are the attributes in in
the anchor(a) element. They are usually written inside the
openingtag of the element and an element can contain more than one
element.
Key Points
- Attributes modify element behavior
- Some attributes are required
- Misuse can cause invalid HTML
Review Questions
- What problems arise from missing required attributes?
- How do attributes interact with CSS and JavaScript?