Unit II HTML5 Lecture Notes
Unit II HTML5 Lecture Notes
HTML5
Faculty Lecture Notes — Web Technologies (IT25301)
Prepared for Semester Examination Preparation (Anna University — New Regulation)
Learning Objectives
• Understand the purpose and syntax of HTML tags and the overall structure of an HTML
document.
• Create ordered, unordered, definition and nested lists, and embed images correctly.
• Use HTML5 semantic elements — section, article, aside, nav, header, footer — to structure a
page meaningfully.
• Build HTML forms using various form controls for user input.
• Understand the Document Object Model (DOM) and how a browser represents an HTML page
internally.
2.1 HTML Tags
Definition: An HTML tag is a keyword enclosed in angle brackets (< >) that tells the browser how
to treat the piece of content it wraps. Tags mark up the start and end of an HTML element.
Structure of a Tag
• Most tags come in pairs: an opening tag (e.g. <p>) and a closing tag (e.g. </p>). The content in
between is the element's content.
• Some tags are self-closing / empty elements because they have no content, e.g. <br>, <hr>,
<img>, <input>.
• HTML tags are not case-sensitive (<P> and <p> behave the same), though lowercase is the
recommended convention in modern HTML.
• Tags can carry attributes — name="value" pairs written inside the opening tag — that provide
extra information, e.g. <img src="[Link]" alt="Logo">.
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome!</h1>
<p>This is my first web page.</p>
</body>
</html>
<!DOCTYPE html>
+-------------------------------+
| <html> |
| +--------+ +----------+ |
| | <head> | --> | <body> | |
| | (title,| | (visible | |
| | meta) | | content) | |
| +--------+ +----------+ |
+-------------------------------+
Basic HTML document structure
Recommended Conventions
• Use lowercase for element names and attribute names (e.g. <p>, not <P>).
• Always close elements that require a closing tag, and close empty elements properly where
required by the doctype in use.
• Use meaningful id and class names that describe purpose, not appearance (e.g. "main-nav"
rather than "blue-box").
• Avoid deeply nested tables or unnecessary markup — keep the structure as simple as the
content allows.
• Keep a single blank line between logical sections of markup for readability.
• Always specify the character encoding (commonly UTF-8) using a <meta charset="UTF-8"> tag
inside <head>.
Remember Points
• Good coding conventions do not change how a browser renders a page — they exist purely to
help developers.
• Consistent indentation is one of the fastest ways to spot missing or unmatched closing tags.
Block-Level Elements
• Begin on a new line and push following content to the next line.
Tag Purpose
<div> A generic block-level container, commonly used for layout/grouping.
<p> A paragraph of text.
<h1>–<h6> Section headings.
<ul>, <ol>, <li> Lists and list items.
<table> A data table.
<form> A form container for user input.
• Do not start on a new line — they flow along with the surrounding text.
• Only occupy the width of their own content, not the full line.
Tag Purpose
<span> A generic inline container, commonly used for styling a portion of text.
<a> A hyperlink.
<b> / <strong> Bold text; <strong> also implies semantic importance.
<i> / <em> Italic text; <em> also implies semantic emphasis.
<img> An inline image.
<label> A caption for a form control.
Comparison: Block vs Inline
Aspect Block-Level Element Inline (Text-Level) Element
New line Always starts on a new line Stays in the flow of the current line
Width Takes full available width by default Takes only as much width as needed
Nesting Can contain block and inline Should only contain other inline
elements elements
Examples <div>, <p>, <h1>, <ul> <span>, <a>, <b>, <img>
Tag Purpose
<code> Marks up a short fragment of computer code, usually shown in a monospace
font.
<pre> Displays preformatted text exactly as typed, preserving spaces and line breaks
— commonly wraps <code> for multi-line snippets.
<kbd> Represents user keyboard input, e.g. <kbd>Ctrl+C</kbd>.
<samp> Represents sample output from a program or script.
<var> Represents a variable name in a mathematical expression or code context.
Note: Inside a <pre> element, whitespace and line breaks are preserved exactly as written — this
is different from normal HTML, where extra spaces and line breaks are collapsed.
Because the characters < and > are used to define tags, and & is used to start an entity, these
characters cannot be typed directly into page content — they must be written using their character
references.
Remember Points
• Every character reference ends with a semicolon (;) — omitting it can cause the browser to
misinterpret the following text.
• is frequently used to prevent unwanted line breaks or to add visible spacing that
normal HTML would collapse.
2.7 Lists
HTML provides three main types of lists to present grouped or related information clearly.
Used when the sequence of items matters. Each item is automatically numbered by the browser.
<ol>
<li>Open the editor</li>
<li>Write the HTML code</li>
<li>Save and open in a browser</li>
</ol>
<!-- Output:
1. Open the editor
2. Write the HTML code
3. Save and open in a browser -->
Used when the order of items does not matter. Each item is marked with a bullet by default.
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
3. Definition List (<dl>)
Used to present a list of terms and their descriptions, using <dt> (definition term) and <dd>
(definition description).
<dl>
<dt>HTML</dt>
<dd>The markup language used to structure web pages.</dd>
<dt>CSS</dt>
<dd>The style sheet language used to design web pages.</dd>
</dl>
4. Nested Lists
A list can be placed inside another list item to represent sub-items or a hierarchy.
<ul>
<li>Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li>Backend</li>
</ul>
2.8 Images
Definition: The <img> tag embeds an image into an HTML page. It is an empty (self-closing)
element — it has no separate closing tag and no text content.
Syntax
Important Attributes
Attribute Purpose
src The path (URL) to the image file — required.
Attribute Purpose
alt Alternate text shown if the image cannot load, and read aloud by screen
readers — important for accessibility.
width / height Sets the display dimensions of the image, in pixels or percentage.
title Extra descriptive text, usually shown as a tooltip on hover.
loading Can be set to "lazy" so the image loads only when it is about to enter the
viewport, improving page performance.
Remember Points
• Always include a meaningful alt attribute — it is essential for accessibility and SEO.
• Images can also act as links by wrapping the <img> tag inside an <a> tag.
<section>
Definition: The <section> element groups together a thematically related block of content,
typically with its own heading.
• Used to divide a page into logical sections, e.g. an ‘About’ section, a ‘Services’ section.
• Not meant to be used purely for styling purposes — use <div> for that instead.
<section>
<h2>About Us</h2>
<p>We build web applications for small businesses.</p>
</section>
<article>
Definition: The <article> element represents a self-contained piece of content that would make
sense on its own if distributed independently — such as a blog post, news story, or forum post.
<article>
<h2>Understanding HTML5 Semantics</h2>
<p>Published on 12 July 2026</p>
<p>Semantic elements make your markup more meaningful...</p>
</article>
<aside>
Definition: The <aside> element represents content that is tangentially related to the main
content — such as a sidebar, pull quote, or related-links widget.
<aside>
<h3>Related Articles</h3>
<ul>
<li>Intro to CSS</li>
<li>JavaScript Basics</li>
</ul>
</aside>
Definition: The <nav> element identifies a block of navigation links — the major navigation menus
of a site, such as the main menu or a table of contents.
• Not every group of links needs to be wrapped in <nav> — use it only for major navigation
blocks.
<nav>
<ul>
<li><a href="[Link]">Home</a></li>
<li><a href="[Link]">About</a></li>
<li><a href="[Link]">Contact</a></li>
</ul>
</nav>
<a> (Anchor)
Definition: The <a> element defines a hyperlink, used to navigate to another page, another part of
the same page, an email address, or a file.
Attribute Purpose
href The destination URL, path, or #id of the link — required for the link to be
clickable.
Attribute Purpose
target Where to open the linked document, e.g. "_blank" opens it in a new tab.
title Extra information shown as a tooltip on hover.
download Prompts the browser to download the linked file instead of navigating to it.
Definition: The <header> element represents introductory content for a page or a section —
typically containing a logo, site title, and/or navigation.
• A page can have one page-level <header>, and individual <article> or <section> elements can
each have their own <header> too.
<header>
<h1>My Website</h1>
<nav>...</nav>
</header>
<footer>
Definition: The <footer> element represents closing content for a page or section — typically
containing copyright information, contact details, or related links.
<footer>
<p>© 2026 My Website. All rights reserved.</p>
</footer>
+--------------------------------------+
| <header> |
+--------------------------------------+
| <nav> | <main> |
| | +----------+ +---------+ |
| | |<section> | |<aside> | |
| | |<article> | | | |
| | +----------+ +---------+ |
+--------------------------------------+
| <footer> |
+--------------------------------------+
A typical HTML5 semantic page layout
Remember Points
• header, footer, nav, section, article and aside are all semantic block-level elements
introduced/standardised in HTML5.
• They replace generic <div> tags with more meaningful names, improving accessibility, SEO, and
code readability.
<audio controls>
<source src="song.mp3" type="audio/mpeg">
<source src="[Link]" type="audio/ogg">
Your browser does not support the audio element.
</audio>
Common Attributes
Attribute Purpose
controls Displays the browser's default play/pause/volume control bar.
autoplay Starts playback automatically as soon as the media is ready (often blocked
by browsers unless muted).
loop Restarts playback automatically once it reaches the end.
muted Mutes the audio track by default.
poster (video only) Specifies an image to show before the video starts playing.
<source> Lets multiple file formats be offered; the browser plays the first format it
supports.
Remember Points
• The text placed between the opening and closing tags is fallback content shown only if the
browser does not support the element at all.
2.13 HTML Forms & Controls
Definition: An HTML form, defined with the <form> element, collects user input and typically
sends it to a server for processing.
<label for="pwd">Password:</label>
<input type="password" id="pwd" name="pwd" required><br>
<label>Gender:</label>
<input type="radio" name="gender" value="M"> Male
<input type="radio" name="gender" value="F"> Female<br>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="in">India</option>
<option value="us">USA</option>
</select><br>
Remember Points
• The name attribute of each control (not its id) is what gets sent to the server as the form field's
key.
• The <label for="..."> element should match the id of its associated control — this also lets the
user click the label to focus the control, improving accessibility.
When a browser loads an HTML page, it does not just display the raw text — it parses the markup
and builds an in-memory tree structure (the DOM tree). This tree is what scripts like JavaScript
actually interact with to read or change page content.
<html>
<body>
<h1>Title</h1>
<p>Some text</p>
</body>
</html>
document
|
<html>
|
<body>
/ \
<h1> <p>
| |
"Title" "Some text"
The HTML document represented as a DOM tree
• It gives scripting languages like JavaScript a structured way to find, read and modify page
content after the page has loaded (this is used extensively in Unit IV of this course).
• It is what enables dynamic web pages — content that changes without a full page reload.
• Browser developer tools (“Inspect Element”) display the live DOM tree of the current page,
which can differ from the original HTML source if scripts have modified it.
Remember Points
• The DOM is a representation of the document, not the HTML source code itself — the browser
builds it after parsing the HTML.
• The DOM tree is what JavaScript methods such as getElementById() or querySelector() search
through.
Unit Summary
• HTML tags mark up elements using angle brackets; most come in start/end pairs, some are self-
closing (<br>, <img>).
• Every HTML document follows a standard skeleton: DOCTYPE, <html>, <head> (metadata) and
<body> (visible content).
• Coding conventions (lowercase tags, quoted attributes, consistent indentation) keep markup
clean and maintainable.
• Block-level elements start on a new line and take full width; text-level (inline) elements flow
within a line.
• Code-related elements (<code>, <pre>, <kbd>, <samp>, <var>) display programming content
meaningfully.
• Character references (<, >, &, , ...) display reserved or special characters
safely.
• Lists (<ol>, <ul>, <dl>) and nested lists organise related items; <img> embeds pictures with the
alt attribute for accessibility.
• <audio> and <video> provide native, plug-in-free media playback with the controls, autoplay,
loop and source attributes.
• HTML forms (<form>, <input>, <select>, <textarea>) collect user input and submit it to a server
via GET or POST.
• The DOM represents an HTML document as a tree of nodes, forming the foundation for
dynamic, script-driven web pages.
Important Keywords
HTML tag, element, attribute, DOCTYPE, head, body, block-level element, inline element,
character reference / entity, ordered list, unordered list, definition list, alt attribute, section,
article, aside, nav, header, footer, semantic element, audio, video, source, form, form control,
GET/POST, label, Document Object Model (DOM), node, DOM tree.
Q.10 What is the difference between GET and POST form methods?
Ans. GET appends form data to the URL and is visible/limited in length; POST sends data in the
request body and is used for larger or sensitive data.
5-Mark Questions
• Explain the basic structure of an HTML document with a suitable example.
• Differentiate between block-level elements and text-level (inline) elements with examples.
• Explain code-related elements in HTML with examples of <code>, <pre> and <kbd>.
• What are character references? Explain with a table of commonly used entities.
• Explain the section, article and aside elements with suitable examples.
• Explain the header and footer elements with a diagram of a typical page layout.
• Explain how audio and video are embedded in HTML5, with their common attributes.
13-Mark Questions
• Explain in detail the structure of an HTML document, HTML tags, and HTML coding conventions
with suitable examples.
• Explain block-level, text-level and code-related elements in HTML with examples for each, and
compare them in a table.
• Explain HTML5 semantic elements — section, article, aside, nav, header and footer — in detail
with a diagram showing a typical page layout and suitable code examples.
• Explain HTML forms and controls in detail. Design a registration form using appropriate form
controls, and explain each control used.
• Explain the Document Object Model (DOM) in detail with a neat diagram. Discuss why the
DOM is important for building dynamic web pages.
• Write short notes on: (a) Character references (b) Lists in HTML (c) Audio and video support in
HTML5.
• Design an HTML form for user registration using various form controls. (Part B / C)
• Why must <, > and & be written using character references in page content?
• What is the difference between <b> and <strong>, and between <i> and <em>?
• What is the difference between the HTML source code and the DOM?