HTML • Chapter 2 • Foundations to Production
Creating a Complete HTML Document
Each topic contains substantial explanation, ten focused teaching examples, its own HTML code example, code reasoning, expected browser result, and practice.
2.1 DOCTYPE
DOCTYPE is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
For DOCTYPE, examine the element's permitted content, relevant attributes, semantic meaning, accessibility effect, and how it behaves when CSS or JavaScript is unavailable. In creating a complete html document, the markup should remain understandable as a document before presentation is added.
In Chapter 2, a reliable way to learn DOCTYPE is to write a small valid fragment, inspect the browser result and document outline, then test one incorrect or missing attribute. This makes the reason for each piece of markup visible instead of treating HTML as a collection of tags to memorize.
Concept in plain language
DOCTYPE is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
10 teaching examples
Example 1: Minimal markup
Create the smallest valid dashboard shell example that demonstrates DOCTYPE. Identify which part carries meaning and which parts are only supporting structure. This is Chapter 2, topic 1, example 1.
Example 2: Content variation
Change the text or resource used by DOCTYPE in the language page. Confirm that the markup still describes the new content correctly instead of depending on the old wording. This is Chapter 2, topic 1, example 2.
Example 3: Missing-information test
Remove one important attribute or related element from the booking page example using DOCTYPE. Explain what meaning, accessibility, navigation, or browser behavior is lost. This is Chapter 2, topic 1, example 3.
Example 4: Accessibility review
Read the media page example using the semantics of DOCTYPE. Check names, labels, landmarks, alternatives, focus behavior, and whether the content still makes sense without styling. This is Chapter 2, topic 1, example 4.
Example 5: Mobile review
Open the school page markup containing DOCTYPE on a narrow screen. Ensure embedded content, long text, controls, and translated labels do not force the page wider than the viewport. This is Chapter 2, topic 1, example 5.
Example 6: RTL review
Translate the course lesson into Arabic or Persian. Keep document text RTL where appropriate while URLs, code samples, numbers, and intentionally LTR fragments remain readable. This is Chapter 2, topic 1, example 6.
Example 7: Validation exercise
Run the news article fragment using DOCTYPE through an HTML validator. Fix invalid nesting, duplicate IDs, missing required attributes, or obsolete markup before adding extra features. This is Chapter 2, topic 1, example 7.
Example 8: Progressive-enhancement check
Use DOCTYPE in the contact page so the core content remains useful before CSS and JavaScript load. Add enhancement only after the document structure is complete. This is Chapter 2, topic 1, example 8.
Example 9: SEO and semantics review
Inspect how DOCTYPE contributes to the meaning of the product description. Keep headings, links, metadata, and document regions consistent so crawlers and users receive the same primary content. This is Chapter 2, topic 1, example 9.
Example 10: Production review
Review DOCTYPE in the profile page for validity, accessibility, security-related attributes, performance hints, responsive behavior, localization, and maintainability. This is Chapter 2, topic 1, example 10.
HTML code example
<!doctype html>
<html lang="en">
<head><meta charset="utf-8"><title>Lesson</title></head>
<body><main><h1>Lesson title</h1></main></body>
</html>Step-by-step code explanation
- Identify the element or attribute responsible for DOCTYPE.
- Read the markup from the outer document structure inward and verify that each child is allowed in its parent context.
- Check the semantic meaning and any accessibility relationship such as labels, alternatives, headings, captions, or landmarks.
- Open the fragment in a browser and compare the rendered result with the source instead of assuming visual appearance proves validity.
- Validate the markup and test responsive, RTL, and no-JavaScript behavior where they apply.
Expected browser result: The browser displays or exposes the structure appropriate for DOCTYPE while preserving the semantic relationships expressed by the markup.
Practice exercise
Write a fresh HTML fragment for DOCTYPE in Chapter 2. Validate it, remove one important attribute or related element to observe the difference, then restore the correct markup. Test the result with keyboard navigation when interactive, on a narrow screen, and in Arabic or Persian when the content can be translated.
2.2 html Element
html Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
For html Element, examine the element's permitted content, relevant attributes, semantic meaning, accessibility effect, and how it behaves when CSS or JavaScript is unavailable. In creating a complete html document, the markup should remain understandable as a document before presentation is added.
In Chapter 2, a reliable way to learn html Element is to write a small valid fragment, inspect the browser result and document outline, then test one incorrect or missing attribute. This makes the reason for each piece of markup visible instead of treating HTML as a collection of tags to memorize.
Concept in plain language
html Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
10 teaching examples
Example 1: Minimal markup
Create the smallest valid booking page example that demonstrates html Element. Identify which part carries meaning and which parts are only supporting structure. This is Chapter 2, topic 2, example 1.
Example 2: Content variation
Change the text or resource used by html Element in the media page. Confirm that the markup still describes the new content correctly instead of depending on the old wording. This is Chapter 2, topic 2, example 2.
Example 3: Missing-information test
Remove one important attribute or related element from the school page example using html Element. Explain what meaning, accessibility, navigation, or browser behavior is lost. This is Chapter 2, topic 2, example 3.
Example 4: Accessibility review
Read the course lesson example using the semantics of html Element. Check names, labels, landmarks, alternatives, focus behavior, and whether the content still makes sense without styling. This is Chapter 2, topic 2, example 4.
Example 5: Mobile review
Open the news article markup containing html Element on a narrow screen. Ensure embedded content, long text, controls, and translated labels do not force the page wider than the viewport. This is Chapter 2, topic 2, example 5.
Example 6: RTL review
Translate the contact page into Arabic or Persian. Keep document text RTL where appropriate while URLs, code samples, numbers, and intentionally LTR fragments remain readable. This is Chapter 2, topic 2, example 6.
Example 7: Validation exercise
Run the product description fragment using html Element through an HTML validator. Fix invalid nesting, duplicate IDs, missing required attributes, or obsolete markup before adding extra features. This is Chapter 2, topic 2, example 7.
Example 8: Progressive-enhancement check
Use html Element in the profile page so the core content remains useful before CSS and JavaScript load. Add enhancement only after the document structure is complete. This is Chapter 2, topic 2, example 8.
Example 9: SEO and semantics review
Inspect how html Element contributes to the meaning of the documentation page. Keep headings, links, metadata, and document regions consistent so crawlers and users receive the same primary content. This is Chapter 2, topic 2, example 9.
Example 10: Production review
Review html Element in the event page for validity, accessibility, security-related attributes, performance hints, responsive behavior, localization, and maintainability. This is Chapter 2, topic 2, example 10.
HTML code example
<html lang="en" dir="ltr">
<head><title>Page title</title></head>
<body><main>Page content</main></body>
</html>Step-by-step code explanation
- Identify the element or attribute responsible for html Element.
- Read the markup from the outer document structure inward and verify that each child is allowed in its parent context.
- Check the semantic meaning and any accessibility relationship such as labels, alternatives, headings, captions, or landmarks.
- Open the fragment in a browser and compare the rendered result with the source instead of assuming visual appearance proves validity.
- Validate the markup and test responsive, RTL, and no-JavaScript behavior where they apply.
Expected browser result: The browser displays or exposes the structure appropriate for html Element while preserving the semantic relationships expressed by the markup.
Practice exercise
Write a fresh HTML fragment for html Element in Chapter 2. Validate it, remove one important attribute or related element to observe the difference, then restore the correct markup. Test the result with keyboard navigation when interactive, on a narrow screen, and in Arabic or Persian when the content can be translated.
2.3 head Element
head Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
For head Element, examine the element's permitted content, relevant attributes, semantic meaning, accessibility effect, and how it behaves when CSS or JavaScript is unavailable. In creating a complete html document, the markup should remain understandable as a document before presentation is added.
In Chapter 2, a reliable way to learn head Element is to write a small valid fragment, inspect the browser result and document outline, then test one incorrect or missing attribute. This makes the reason for each piece of markup visible instead of treating HTML as a collection of tags to memorize.
Concept in plain language
head Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
10 teaching examples
Example 1: Minimal markup
Create the smallest valid school page example that demonstrates head Element. Identify which part carries meaning and which parts are only supporting structure. This is Chapter 2, topic 3, example 1.
Example 2: Content variation
Change the text or resource used by head Element in the course lesson. Confirm that the markup still describes the new content correctly instead of depending on the old wording. This is Chapter 2, topic 3, example 2.
Example 3: Missing-information test
Remove one important attribute or related element from the news article example using head Element. Explain what meaning, accessibility, navigation, or browser behavior is lost. This is Chapter 2, topic 3, example 3.
Example 4: Accessibility review
Read the contact page example using the semantics of head Element. Check names, labels, landmarks, alternatives, focus behavior, and whether the content still makes sense without styling. This is Chapter 2, topic 3, example 4.
Example 5: Mobile review
Open the product description markup containing head Element on a narrow screen. Ensure embedded content, long text, controls, and translated labels do not force the page wider than the viewport. This is Chapter 2, topic 3, example 5.
Example 6: RTL review
Translate the profile page into Arabic or Persian. Keep document text RTL where appropriate while URLs, code samples, numbers, and intentionally LTR fragments remain readable. This is Chapter 2, topic 3, example 6.
Example 7: Validation exercise
Run the documentation page fragment using head Element through an HTML validator. Fix invalid nesting, duplicate IDs, missing required attributes, or obsolete markup before adding extra features. This is Chapter 2, topic 3, example 7.
Example 8: Progressive-enhancement check
Use head Element in the event page so the core content remains useful before CSS and JavaScript load. Add enhancement only after the document structure is complete. This is Chapter 2, topic 3, example 8.
Example 9: SEO and semantics review
Inspect how head Element contributes to the meaning of the FAQ page. Keep headings, links, metadata, and document regions consistent so crawlers and users receive the same primary content. This is Chapter 2, topic 3, example 9.
Example 10: Production review
Review head Element in the photo story for validity, accessibility, security-related attributes, performance hints, responsive behavior, localization, and maintainability. This is Chapter 2, topic 3, example 10.
HTML code example
<section id="head-element">
<h2>head Element</h2>
<p>This HTML fragment demonstrates the document structure for head Element.</p>
</section>Step-by-step code explanation
- Identify the element or attribute responsible for head Element.
- Read the markup from the outer document structure inward and verify that each child is allowed in its parent context.
- Check the semantic meaning and any accessibility relationship such as labels, alternatives, headings, captions, or landmarks.
- Open the fragment in a browser and compare the rendered result with the source instead of assuming visual appearance proves validity.
- Validate the markup and test responsive, RTL, and no-JavaScript behavior where they apply.
Expected browser result: The browser displays or exposes the structure appropriate for head Element while preserving the semantic relationships expressed by the markup.
Practice exercise
Write a fresh HTML fragment for head Element in Chapter 2. Validate it, remove one important attribute or related element to observe the difference, then restore the correct markup. Test the result with keyboard navigation when interactive, on a narrow screen, and in Arabic or Persian when the content can be translated.
2.4 body Element
body Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
For body Element, examine the element's permitted content, relevant attributes, semantic meaning, accessibility effect, and how it behaves when CSS or JavaScript is unavailable. In creating a complete html document, the markup should remain understandable as a document before presentation is added.
In Chapter 2, a reliable way to learn body Element is to write a small valid fragment, inspect the browser result and document outline, then test one incorrect or missing attribute. This makes the reason for each piece of markup visible instead of treating HTML as a collection of tags to memorize.
Concept in plain language
body Element is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
10 teaching examples
Example 1: Minimal markup
Create the smallest valid news article example that demonstrates body Element. Identify which part carries meaning and which parts are only supporting structure. This is Chapter 2, topic 4, example 1.
Example 2: Content variation
Change the text or resource used by body Element in the contact page. Confirm that the markup still describes the new content correctly instead of depending on the old wording. This is Chapter 2, topic 4, example 2.
Example 3: Missing-information test
Remove one important attribute or related element from the product description example using body Element. Explain what meaning, accessibility, navigation, or browser behavior is lost. This is Chapter 2, topic 4, example 3.
Example 4: Accessibility review
Read the profile page example using the semantics of body Element. Check names, labels, landmarks, alternatives, focus behavior, and whether the content still makes sense without styling. This is Chapter 2, topic 4, example 4.
Example 5: Mobile review
Open the documentation page markup containing body Element on a narrow screen. Ensure embedded content, long text, controls, and translated labels do not force the page wider than the viewport. This is Chapter 2, topic 4, example 5.
Example 6: RTL review
Translate the event page into Arabic or Persian. Keep document text RTL where appropriate while URLs, code samples, numbers, and intentionally LTR fragments remain readable. This is Chapter 2, topic 4, example 6.
Example 7: Validation exercise
Run the FAQ page fragment using body Element through an HTML validator. Fix invalid nesting, duplicate IDs, missing required attributes, or obsolete markup before adding extra features. This is Chapter 2, topic 4, example 7.
Example 8: Progressive-enhancement check
Use body Element in the photo story so the core content remains useful before CSS and JavaScript load. Add enhancement only after the document structure is complete. This is Chapter 2, topic 4, example 8.
Example 9: SEO and semantics review
Inspect how body Element contributes to the meaning of the support page. Keep headings, links, metadata, and document regions consistent so crawlers and users receive the same primary content. This is Chapter 2, topic 4, example 9.
Example 10: Production review
Review body Element in the dashboard shell for validity, accessibility, security-related attributes, performance hints, responsive behavior, localization, and maintainability. This is Chapter 2, topic 4, example 10.
HTML code example
<section id="body-element">
<h2>body Element</h2>
<p>This HTML fragment demonstrates the document structure for body Element.</p>
</section>Step-by-step code explanation
- Identify the element or attribute responsible for body Element.
- Read the markup from the outer document structure inward and verify that each child is allowed in its parent context.
- Check the semantic meaning and any accessibility relationship such as labels, alternatives, headings, captions, or landmarks.
- Open the fragment in a browser and compare the rendered result with the source instead of assuming visual appearance proves validity.
- Validate the markup and test responsive, RTL, and no-JavaScript behavior where they apply.
Expected browser result: The browser displays or exposes the structure appropriate for body Element while preserving the semantic relationships expressed by the markup.
Practice exercise
Write a fresh HTML fragment for body Element in Chapter 2. Validate it, remove one important attribute or related element to observe the difference, then restore the correct markup. Test the result with keyboard navigation when interactive, on a narrow screen, and in Arabic or Persian when the content can be translated.
2.5 Document Nesting Rules
Document Nesting Rules is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
For Document Nesting Rules, examine the element's permitted content, relevant attributes, semantic meaning, accessibility effect, and how it behaves when CSS or JavaScript is unavailable. In creating a complete html document, the markup should remain understandable as a document before presentation is added.
In Chapter 2, a reliable way to learn Document Nesting Rules is to write a small valid fragment, inspect the browser result and document outline, then test one incorrect or missing attribute. This makes the reason for each piece of markup visible instead of treating HTML as a collection of tags to memorize.
Concept in plain language
Document Nesting Rules is part of the HTML structure covered in Chapter 2. HTML communicates meaning and document relationships to browsers, search engines, assistive technology, and other tools, so the choice of element or attribute should match the content rather than only its visual appearance.
10 teaching examples
Example 1: Minimal markup
Create the smallest valid product description example that demonstrates Document Nesting Rules. Identify which part carries meaning and which parts are only supporting structure. This is Chapter 2, topic 5, example 1.
Example 2: Content variation
Change the text or resource used by Document Nesting Rules in the profile page. Confirm that the markup still describes the new content correctly instead of depending on the old wording. This is Chapter 2, topic 5, example 2.
Example 3: Missing-information test
Remove one important attribute or related element from the documentation page example using Document Nesting Rules. Explain what meaning, accessibility, navigation, or browser behavior is lost. This is Chapter 2, topic 5, example 3.
Example 4: Accessibility review
Read the event page example using the semantics of Document Nesting Rules. Check names, labels, landmarks, alternatives, focus behavior, and whether the content still makes sense without styling. This is Chapter 2, topic 5, example 4.
Example 5: Mobile review
Open the FAQ page markup containing Document Nesting Rules on a narrow screen. Ensure embedded content, long text, controls, and translated labels do not force the page wider than the viewport. This is Chapter 2, topic 5, example 5.
Example 6: RTL review
Translate the photo story into Arabic or Persian. Keep document text RTL where appropriate while URLs, code samples, numbers, and intentionally LTR fragments remain readable. This is Chapter 2, topic 5, example 6.
Example 7: Validation exercise
Run the support page fragment using Document Nesting Rules through an HTML validator. Fix invalid nesting, duplicate IDs, missing required attributes, or obsolete markup before adding extra features. This is Chapter 2, topic 5, example 7.
Example 8: Progressive-enhancement check
Use Document Nesting Rules in the dashboard shell so the core content remains useful before CSS and JavaScript load. Add enhancement only after the document structure is complete. This is Chapter 2, topic 5, example 8.
Example 9: SEO and semantics review
Inspect how Document Nesting Rules contributes to the meaning of the language page. Keep headings, links, metadata, and document regions consistent so crawlers and users receive the same primary content. This is Chapter 2, topic 5, example 9.
Example 10: Production review
Review Document Nesting Rules in the booking page for validity, accessibility, security-related attributes, performance hints, responsive behavior, localization, and maintainability. This is Chapter 2, topic 5, example 10.
HTML code example
<section id="document-nesting-rules">
<h2>Document Nesting Rules</h2>
<p>This HTML fragment demonstrates the document structure for Document Nesting Rules.</p>
</section>Step-by-step code explanation
- Identify the element or attribute responsible for Document Nesting Rules.
- Read the markup from the outer document structure inward and verify that each child is allowed in its parent context.
- Check the semantic meaning and any accessibility relationship such as labels, alternatives, headings, captions, or landmarks.
- Open the fragment in a browser and compare the rendered result with the source instead of assuming visual appearance proves validity.
- Validate the markup and test responsive, RTL, and no-JavaScript behavior where they apply.
Expected browser result: The browser displays or exposes the structure appropriate for Document Nesting Rules while preserving the semantic relationships expressed by the markup.
Practice exercise
Write a fresh HTML fragment for Document Nesting Rules in Chapter 2. Validate it, remove one important attribute or related element to observe the difference, then restore the correct markup. Test the result with keyboard navigation when interactive, on a narrow screen, and in Arabic or Persian when the content can be translated.
Chapter 2 review — 10 questions and answers
1. What should you check first when using DOCTYPE?
Answer: Check that the markup for DOCTYPE matches the meaning of the content, is valid in its context, and does not depend on visual styling to communicate essential information.
2. How do you review DOCTYPE before publishing?
Answer: Validate the HTML, inspect accessibility and keyboard behavior where relevant, test narrow screens and translated text, and confirm that DOCTYPE adds real document meaning or browser behavior.
3. What should you check first when using html Element?
Answer: Check that the markup for html Element matches the meaning of the content, is valid in its context, and does not depend on visual styling to communicate essential information.
4. How do you review html Element before publishing?
Answer: Validate the HTML, inspect accessibility and keyboard behavior where relevant, test narrow screens and translated text, and confirm that html Element adds real document meaning or browser behavior.
5. What should you check first when using head Element?
Answer: Check that the markup for head Element matches the meaning of the content, is valid in its context, and does not depend on visual styling to communicate essential information.
6. How do you review head Element before publishing?
Answer: Validate the HTML, inspect accessibility and keyboard behavior where relevant, test narrow screens and translated text, and confirm that head Element adds real document meaning or browser behavior.
7. What should you check first when using body Element?
Answer: Check that the markup for body Element matches the meaning of the content, is valid in its context, and does not depend on visual styling to communicate essential information.
8. How do you review body Element before publishing?
Answer: Validate the HTML, inspect accessibility and keyboard behavior where relevant, test narrow screens and translated text, and confirm that body Element adds real document meaning or browser behavior.
9. What should you check first when using Document Nesting Rules?
Answer: Check that the markup for Document Nesting Rules matches the meaning of the content, is valid in its context, and does not depend on visual styling to communicate essential information.
10. How do you review Document Nesting Rules before publishing?
Answer: Validate the HTML, inspect accessibility and keyboard behavior where relevant, test narrow screens and translated text, and confirm that Document Nesting Rules adds real document meaning or browser behavior.