Home Notes Login
HTML Basics & Advanced (Chapter: 3) | EduNotes

HTML

Complete HTML Notes – Rajat Pathak

1 Introduction to HTML

HTML stands for HyperText Markup Language. It is the basic building block of all websites.

Think of HTML like the bones of a body — it gives structure to a webpage. Without HTML, webpages would just be blank.

When you open any website, HTML is telling the browser:

  • "Hey! This is a heading!"
  • "This is a paragraph!"
  • "This is an image!"
  • "This is a button!"

What is HyperText?

"Hyper" means linked or connected. Text that links to other text or pages is called Hypertext.

Example: If you click a blue word "Click Here" and it takes you to another page — that's hypertext.

What is Markup Language?

"Markup" means adding extra instructions to text so the browser knows how to display it. It's like giving instructions to a computer:

  • Make this bold
  • Make this heading big
  • Make this red

Together = HTML helps browsers understand what and how to show stuff.

2 History & Versions of HTML

  • 1991 — Sir Tim Berners-Lee (the father of the web!) invented HTML. Very simple, only a few tags.
  • 1995 — HTML 2.0 came — a little more polished.
  • Then 3.2, 4.0, and 4.01 versions arrived as websites needed to become smarter and prettier.
  • 2014 — HTML5 came — a complete superhero version with video, audio, games, canvas, animations etc. directly inside HTML!
VersionYearKey Highlights
HTML 1.01991Basic text, links
HTML 2.01995Forms introduced
HTML 3.21997Tables, scripting
HTML 4.011999CSS support, better structure
XHTML2000Strict rules (XML + HTML)
HTML52014Multimedia, mobile-friendly, modern APIs

3 HTML Tags, Elements & Document Structure

What is a Tag?

A tag is a command inside < > brackets that tells the browser what to do.

<p>This is a paragraph.</p>
  <p>  → Opening tag
  </p> → Closing tag

Types of Tags

TypeDescriptionExample
Container TagHas both opening and closing tag. Wraps content inside.<b>Bold</b>
Empty TagNo closing tag. Single tag that works alone.<br>  <img>  <hr>

What is an Element?

Element = Opening tag + Content + Closing tag

<h1>Hello World</h1>
  ↑               ↑              ↑
Opening tag    Content    Closing tag
Together they make one complete ELEMENT.

Basic HTML Document Structure

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
  </head>
  <body>
    Page content here
  </body>
</html>
PartPurpose
<!DOCTYPE html>Tells browser this is HTML5
<html>Root element — wraps everything
<head>Invisible stuff — title, CSS, metadata
<body>Visible stuff — text, images, videos

How to Write HTML in Notepad

  1. Open Notepad (basic text editor)
  2. Write your HTML code
  3. Save the file with a .html extension (Example: mypage.html)
  4. Double-click the file — it opens in a browser!

4 Head Section Elements

The <head> section stores page information — it is not visible to users. Elements inside <head>:

1. <title>

Sets the title shown on the browser tab.

<title>My First Web Page</title>

2. <meta>

Provides metadata (info about the page) to browsers and search engines.

<meta charset="UTF-8">
<meta name="description" content="Free Web tutorials">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
AttributeMeaning
charsetCharacter encoding (UTF-8 for all languages)
nameType of metadata (keywords, description, viewport)
contentThe value for the name attribute
http-equivHTTP header (like refresh, content-type)

3. <link>

Connects external files like CSS to the HTML page.

<link rel="stylesheet" href="style.css">
AttributeMeaning
relRelationship — stylesheet, icon, etc.
hrefURL of linked file
typeFile type — text/css, etc.

4. <base>

Sets a default URL or target for all links/images in the page.

<base href="https://example.com/" target="_blank">
AttributeMeaning
hrefBase URL for relative links
targetHow links open — _blank, _self

5. <isindex> (Old / Obsolete)

⚠️ This tag is now obsolete. Do NOT use it. Use <input> and <form> instead.

Was used for a search box on the page.

<isindex prompt="Search Here:">

Attribute: prompt = Text displayed inside the search box.

6. <style>

Write CSS (Cascading Style Sheets) directly inside HTML to style the page.

<style>
  body { background-color: lightyellow; }
</style>
AttributeMeaning
typeStyle type (text/css) — optional now
mediaDevices for the styles — screen, print

7. <script>

Runs JavaScript inside HTML.

<script src="script.js"></script>
AttributeMeaning
srcURL of the external script file
typeType of script (text/javascript)
asyncLoad script asynchronously
deferLoad script after HTML parsing

8. <noscript>

Shows alternative content if the browser doesn't support JavaScript.

<noscript>Your browser does not support JavaScript!</noscript>

No specific attributes — just plain content inside.

5 HTML Body Attributes & Comments

<body> Tag

All visible content goes inside <body>. The following attributes are from old HTML4 style:

AttributePurpose
bgcolorBackground color of the page
backgroundImage as page background
textColor of all text
linkColor of unvisited links
vlinkColor of visited links
alinkColor of active (clicked) links
<body bgcolor="lightblue" text="black">

What is a Comment in HTML?

A comment is a note written inside the code — it is only for developers to read and understand. Browsers ignore comments — they do NOT show up on the webpage.

Why use comments?

  • To explain your code
  • To remind yourself why you wrote something
  • To hide parts of code during testing

Syntax

<!-- This is a comment -->

<p>Hello World</p> <!-- This is a simple paragraph -->

The comment <!-- ... --> is completely ignored by the browser.

6 Full Sample HTML Page (Basics)

<!DOCTYPE html>
<html>
<head>
  <title>My First Sample Page</title>
  <meta charset="UTF-8">
  <meta name="description" content="Learning HTML Basics">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>

<body bgcolor="lightyellow" text="black">

  <!-- Main heading -->
  <h1>Welcome to My Web Page</h1>

  <!-- Paragraph -->
  <p>This is my first webpage using HTML. I am learning it step-by-step.</p>

  <!-- Hypertext link -->
  <a href="https://www.google.com">Visit Google</a>

  <!-- Image -->
  <p><img src="logo.png" alt="Logo Image" width="200"></p>

  <!-- Horizontal line -->
  <hr>

  <!-- Line break -->
  <p>First line.<br>Second line after break.</p>

</body>
</html>
Part UsedExplanation
<!DOCTYPE html>Tells browser we are using HTML5
<html>Root element of the page
<head>Contains metadata, styles, scripts
<title>Name shown on browser tab
<meta>Info for browser/search engines
<body>Page visible content
<h1>, <p>, <a>, <img>, <br>, <hr>Basic content elements
<!-- comment -->Developer notes, ignored by browser
<noscript>Message if JavaScript not supported

7 Text Formatting Tags

Block-level Tags

TagNameUse / Description
<h1> to <h6>HeadingsCreates headings — <h1> is biggest, <h6> is smallest
<p>ParagraphWrites a paragraph of text
<div>DivisionBlock container — divides page into sections
<br>Line BreakBreaks the line, moves next content to new line (empty tag)
<hr>Horizontal RuleDraws a horizontal line across the page (empty tag)
<pre>PreformattedKeeps spaces and line breaks exactly as typed — good for poems, code
<blockquote>Block QuotationQuotes a large block of text from another source — indents the text
<address>AddressShows contact info or postal address — usually shown in italic

Inline Formatting Tags

TagNameUse / Description
<b>BoldMakes text bold (dark and thick) — visual only
<strong>StrongBold + semantically important (preferred over <b>)
<i>ItalicMakes text slanted — visual only
<em>EmphasisItalic + meaningful emphasis — search engines treat it differently
<u>UnderlineUnderlines the text
<mark>MarkHighlights text with yellow background — inline element
<del>DeletedStrikethrough — shows removed text
<ins>InsertedUnderline — shows newly added text
<sub>SubscriptSmaller text below normal line — e.g., H₂O
<sup>SuperscriptSmaller text above normal line — e.g., a²
<span>SpanGroups inline content — does NOT break the line
<q>Short QuoteShort inline quotation — browser auto-adds " " marks
<abbr>AbbreviationShows abbreviation; full meaning appears on hover via title
<dfn>DefinitionDefines a new term — browser may italicize it
<code>CodeDisplays computer code in a special monospace font
<cite>CitationCites a book, work, website — usually shown in italic

Practical Examples

<!-- Bold and Italic -->
<p><b>This is bold</b> and <i>this is italic</i></p>

<!-- Subscript and Superscript -->
<p>Water is H<sub>2</sub>O</p>
<p>Area = a<sup>2</sup></p>

<!-- Deleted and Inserted -->
<p>Price: <del>₹500</del> <ins>₹400</ins></p>

<!-- Abbreviation -->
<p><abbr title="World Health Organization">WHO</abbr> works for public health.</p>

<!-- Mark (highlight) -->
<p>Read the <mark>important</mark> instructions carefully.</p>

<!-- Short Quote -->
<p>He said, <q>Knowledge is power.</q></p>

<!-- Preformatted -->
<pre>Roses are red,
Violets are blue.</pre>

<!-- Code -->
<code>print("Hello World")</code>

<!-- Definition -->
<p><dfn>HTML</dfn> stands for HyperText Markup Language.</p>

<!-- Citation -->
<p><cite>Ramayana</cite> is an ancient Indian epic.</p>

<!-- Span -->
<p>My name is <span style="color: red;">Rajat</span>.</p>

8 HTML Links — Anchor Tag <a>

The <a> tag creates hyperlinks that connect one page to another. Links are the soul of the web!

<a href="URL">Link Text</a>

Types of Hyperlinks

  • Internal link — links to same page or same website
  • External link — links to another website
  • Email link (mailto:) — opens the email app
  • Download link — link to download files
  • Anchor link — jumps to a specific section on the same page

Attributes of <a> Tag

AttributePurpose
hrefURL of the page/file to link to
targetOpens link in same tab (_self) or new tab (_blank)
titleTooltip text shown on hover
nameUsed for internal page navigation anchors (old method)
downloadForces the link to download a file
mailto:Opens the default email app to compose mail

Examples

<!-- Basic external link -->
<a href="https://www.google.com">Visit Google</a>

<!-- Open in new tab -->
<a href="https://kcsdocs.in/" target="_blank">Visit Website</a>

<!-- Email link -->
<a href="mailto:info@example.com">Send Email</a>

<!-- Download link -->
<a href="file.pdf" download>Download PDF</a>

<!-- Jump to anchor (same page) -->
<a href="#bottom">Jump to Bottom</a>
<h2 id="bottom">This is the bottom!</h2>
Tag / ValuePurpose
<a href="URL">Link to another page
<a href="mailto:email">Open email app
<a href="#id">Jump to anchor on same page
target="_blank"Open in new tab
target="_self"Open in same tab (default)

9 Mark Tag & Font Element

<mark> Tag

Used to highlight text. Default background is yellow. It is an inline element.

Great for showing search results or key points!

<!-- Syntax -->
<mark>Highlighted text</mark>

<!-- Example -->
<p>Read the <mark>important</mark> instructions carefully.</p>

<font> Element (Old HTML)

⚠️ The <font> tag is NOT supported in HTML5. Use it only for learning. For modern websites, always use CSS for styling.

The <font> tag was used in older HTML to change how text looks — colour, size, and font style.

<!-- Syntax -->
<font size="5" color="blue" face="Arial">This is styled text</font>

<!-- Example -->
<font size="6" color="green" face="Comic Sans MS">Welcome to HTML class!</font>
AttributeMeaningValues
colorChanges text colorred, green, blue, #hex
sizeSets text size (1–7, default = 3)1 to 7
faceChanges font style/familyArial, Times New Roman, Comic Sans MS

10 HTML Lists

HTML provides 3 main types of lists:

1. Unordered List — <ul>

Items appear with bullet points.

<ul>
  <li>Apples</li>
  <li>Bananas</li>
  <li>Cherries</li>
</ul>

2. Ordered List — <ol>

Items appear in numbered order.

<ol>
  <li>Wake up</li>
  <li>Brush teeth</li>
  <li>Have breakfast</li>
</ol>

3. Definition List — <dl>

Used for terms and their meanings. Uses <dt> (term) and <dd> (description).

<dl>
  <dt>HTML</dt>
  <dd>HyperText Markup Language</dd>

  <dt>CSS</dt>
  <dd>Cascading Style Sheets</dd>
</dl>

4. Nested Lists — List inside a List

<ul>
  <li>Fruits
    <ul>
      <li>Mango</li>
      <li>Apple</li>
    </ul>
  </li>
  <li>Vegetables
    <ul>
      <li>Carrot</li>
      <li>Potato</li>
    </ul>
  </li>
</ul>
TagFull NamePurpose
<ul>Unordered ListBullet-point list
<ol>Ordered ListNumbered list
<dl>Definition ListTerm + description list
<li>List ItemEach item in ul or ol
<dt>Definition TermThe term in a dl
<dd>Definition DescriptionMeaning of the term in dl

11 Image Element — <img>

The <img> tag adds images to a webpage. It is a self-closing / empty tag — no closing tag needed.

<!-- Syntax -->
<img src="image.jpg" width="200" height="150" alt="A sample image">

<!-- Full Example -->
<img src="logo.jpg" height="120" width="150" border="2"
     hspace="10" vspace="10" align="right" alt="Website Logo">
AttributeMeaning
srcPath or URL of the image file (required)
altAlternative text shown if image fails to load (required for accessibility)
heightImage height in pixels
widthImage width in pixels
borderBorder thickness around image (in px)
hspaceHorizontal space — on left and right of image
vspaceVertical space — on top and bottom of image
alignPosition image beside text: left, right, top, bottom

12 HTML Tables

HTML tables display data in rows and columns — like a spreadsheet.

Basic Table Tags

TagFull FormDescription
<table>TableCreates a table
<tr>Table RowStarts a new row
<th>Table HeaderBold, centered heading cell
<td>Table DataNormal data cell
<caption>CaptionTitle that appears above the table
<colgroup>Column GroupGroups one or more columns for styling
<col>ColumnSingle column definition inside colgroup

Table Tag Attributes

AttributeMeaningExample
borderAdds a border to table and cells<table border="1">
cellpaddingSpace between cell content and cell wall<table cellpadding="10">
cellspacingSpace between individual cells<table cellspacing="5">
widthTable width in % or px<table width="100%">
alignAligns table on page<table align="center">
bgcolorBackground color of table<table bgcolor="lightblue">

Full Table Example

<table border="1" width="100%" cellpadding="8">
  <caption>Student Information</caption>
  <colgroup>
    <col style="background-color: lightyellow">
    <col style="background-color: lightblue">
  </colgroup>
  <tr>
    <th>Name</th>
    <th>Class</th>
  </tr>
  <tr>
    <td>Rina</td>
    <td>10th</td>
  </tr>
  <tr>
    <td>Rekha</td>
    <td>9th</td>
  </tr>
</table>

Col Tag with span

Use span to apply the same style to multiple columns at once:

<col span="2" style="background-color: #f2f2f2">

13 Marquee Element

The <marquee> tag creates scrolling text or images. Not a modern standard, but still works in browsers.

<marquee>Welcome to Chaitanya Kendra!</marquee>

Types of Scroll (behavior attribute)

<marquee behavior="scroll">Scrolling across</marquee>
<marquee behavior="slide">Slides once and stops</marquee>
<marquee behavior="alternate">Bounces back and forth</marquee>

Marquee Attributes

AttributePurposeExample Value
behaviorType of scroll effectscroll / slide / alternate
directionDirection of movementleft / right / up / down
scrollamountSpeed (higher = faster)scrollamount="10"
scrolldelayDelay in ms between each movescrolldelay="100"
loopHow many times to repeat (-1 = infinite)loop="3"
bgcolorBackground color of marquee areabgcolor="yellow"
width / heightSize of the marquee boxwidth="300" height="50"

Full Example

<marquee behavior="alternate" direction="right" scrollamount="8" bgcolor="lightgreen">
  🎉 Admission Open - Join Today! 🎉
</marquee>

14 HTML Frames & iFrame

1. HTML Frames — <frameset>

Frames divide the browser window into different sections — each section loads its own webpage. Like watching multiple web pages side-by-side.

Why was it used?

  • Keep the menu bar on the left and change content on the right
  • Avoid reloading the whole page — only part of the page updates
⚠️ Frames are now OBSOLETE — not supported in HTML5. They caused problems with bookmarking, navigation, search engine indexing, and mobile layouts. Use <div>, CSS, and JavaScript frameworks like React instead.
<!DOCTYPE html>
<html>
  <frameset cols="30%, 70%" border="10" bordercolor="blue" framespacing="5">
    <frame src="menu.html" name="menu" scrolling="auto" noresize>
    <frame src="content.html" name="content">
  </frameset>
</html>
Attribute / TagExplanation
cols="30%,70%"Divides screen vertically into two parts
border, bordercolorCustomize appearance of frame borders
framespacingSpace between frames
<frame src="...">Loads a different HTML document in each frame
scrolling="auto"Adds scrollbar if content overflows
noresizePrevents user from resizing the frame

2. iFrame — <iframe> (Inline Frame)

<iframe> = Inline Frame — shows another web page inside your page like a mini browser window. This is still used in modern HTML.

Why use iFrame?

  • Embed YouTube videos
  • Load Google Maps
  • Show other websites without making users leave your site
<!-- Basic iFrame -->
<iframe src="https://example.com" width="600" height="400"></iframe>

<!-- Named iFrame Example -->
<!DOCTYPE html>
<html>
<head><title>Iframe Example</title></head>
<body>
  <h2>View External Site</h2>
  <iframe src="https://example.com" width="600" height="400" name="exampleFrame"></iframe>
</body>
</html>
⚠️ Some websites block embedding using X-Frame-Options. iFrames can also slow down your site if used heavily.

15 HTML Forms

Forms allow users to input data and send it to a server. Think of: login pages, signup forms, contact us forms — all made using forms!

Without forms, a website is just information. Forms let users interact and give you data.

<form action="submit.php" method="post">
  <input type="text" name="username">
  <input type="submit" value="Send">
</form>

Key Form Attributes

AttributeMeaning
actionURL where form sends data (e.g., PHP/Node.js server)
method="get"Data visible in URL (less secure)
method="post"Data hidden in request body (more secure)
enctype="multipart/form-data"Required when uploading files
autocomplete="on/off"Browser suggests previously entered values

target Attribute & Its Values for <form>

ValueBehaviour
_selfDefault — opens result in the SAME tab
_blankOpens result in a NEW tab
_topOpens result in the entire browser window, breaks out of all frames
_parentOpens result in the parent frame of the current frame
<!-- _blank example -->
<form action="submit.html" target="_blank">
  <input type="submit" value="Open in New Tab">
</form>

16 Input Types — All Types

Input Element Basics

The <input> tag is an empty element used inside a <form> to create input fields where users enter data. The type attribute determines what kind of input it is.

All Input Types with Examples

TypeSyntaxDescription
text<input type="text">Type any text — name, username, etc.
password<input type="password">Hides typed characters — for login forms
email<input type="email">Validates proper email format (abc@example.com)
number<input type="number" min="1" max="10">Only numbers — for age, quantity etc.
date<input type="date">Lets user pick a date from a calendar
tel<input type="tel">For phone numbers — no format check unless pattern used
search<input type="search">Looks like a search box — optimized for searching
color<input type="color">Lets user pick a color from a color palette
file<input type="file" multiple>Lets user upload files from their computer
radio<input type="radio" name="g" value="m">Choose ONE option only — must share same name
checkbox<input type="checkbox" name="h">Choose MULTIPLE options
url<input type="url">Must be a proper link (https://something.com)
textarea<textarea rows="4" cols="40"></textarea>For long text — feedback, messages (not input tag)

Input Tag Attributes

AttributeEasy Meaning
typeDefines the type of input (text, password, email, etc.)
nameName of the field for form submission (not visible on page)
valueDefault value or label for the input field
sizeWidth of input field in characters
maxlengthMaximum number of characters allowed
placeholderGrey hint text visible inside empty box
requiredField must be filled before submission
readonlyCan see value but cannot change it
disabledLooks grey — unclickable, value not submitted
autofocusCursor goes here automatically when page loads
autocompleteBrowser suggests previously entered values (on/off)
patternValidates input format using regular expressions

Radio Button Example

<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female"> Female

(Must share the same name so only ONE can be selected at a time)

Checkbox Example

<input type="checkbox" name="hobby1" value="Reading" checked> Reading
<input type="checkbox" name="hobby2" value="Travel"> Travel

17 Form Buttons & Common Attributes

Form Buttons

Button TypeSyntaxPurpose
Submit<input type="submit" value="Send">Sends form data to the server
Reset<input type="reset" value="Clear">Clears everything typed in the form
Image Button<input type="image" src="submit.png">A submit button with a custom image

Complete Form Example with All Input Types

<form action="submit.php" method="POST" enctype="multipart/form-data" autocomplete="on">

  <label>Name:</label>
  <input type="text" name="name" required placeholder="Enter your name" autofocus><br><br>

  <label>Password:</label>
  <input type="password" name="pass" maxlength="12"><br><br>

  <label>Email:</label>
  <input type="email" name="email"><br><br>

  <label>Phone:</label>
  <input type="tel" name="phone"><br><br>

  <label>Age:</label>
  <input type="number" name="age" min="1" max="100"><br><br>

  <label>Date of Birth:</label>
  <input type="date" name="dob"><br><br>

  <label>Upload File:</label>
  <input type="file" name="myfile" multiple><br><br>

  <label>Gender:</label>
  <input type="radio" name="gender" value="male" checked> Male
  <input type="radio" name="gender" value="female"> Female<br><br>

  <label>Hobbies:</label>
  <input type="checkbox" name="hobby1" value="Reading" checked> Reading
  <input type="checkbox" name="hobby2" value="Travel"> Travel<br><br>

  <label>Search:</label>
  <input type="search" name="search"><br><br>

  <label>Favourite Color:</label>
  <input type="color" name="color"><br><br>

  <label>Website URL:</label>
  <input type="url" name="website"><br><br>

  <label>Comments:</label><br>
  <textarea name="comments" rows="5" cols="40" placeholder="Enter comments..." required></textarea><br><br>

  <input type="submit" value="Submit">
  <input type="reset" value="Reset">

</form>

18 Select, Option, Optgroup & Datalist

<select> Tag — Drop-down List

Creates a drop-down list where a user can choose one or more options.

AttributeDescription
disabledMakes the whole list unselectable
multipleAllows selecting multiple options (hold Ctrl)
nameName of the drop-down for form submission
requiredForces user to select before submitting
sizeNumber of visible options shown at once
<label>Select Country:</label>
<select name="country" required>
  <option value="IN">India</option>
  <option value="US">USA</option>
  <option value="UK">UK</option>
</select>

<option> Tag — Items in Drop-down

Defines each individual item in a <select> or <datalist>.

AttributeDescription
disabledMakes this option unselectable
labelGives a shorter display label
selectedSets this as the default selected option
valueThe value sent to the server on submission
<select>
  <option value="delhi">Delhi</option>
  <option value="mumbai" selected>Mumbai</option>
  <option value="chennai">Chennai</option>
</select>

<optgroup> Tag — Group Options

Groups related options inside a drop-down with a label heading.

AttributeDescription
labelTitle/heading of the group (shown but not selectable)
disabledMakes the entire group unselectable
<select>
  <optgroup label="Fruits">
    <option>Apple</option>
    <option>Banana</option>
  </optgroup>
  <optgroup label="Vegetables">
    <option>Carrot</option>
    <option>Peas</option>
  </optgroup>
</select>

<datalist> Tag — Auto Suggestion List

Provides predefined suggestions to <input> fields — like autocomplete. Linked to input via list attribute.

⚠️ Not fully supported in older Safari and Internet Explorer.
<form>
  <label>Enter Country:</label>
  <input type="text" name="country" list="countries">
  <datalist id="countries">
    <option value="India">
    <option value="China">
    <option value="USA">
    <option value="Russia">
  </datalist>
</form>

19 Button, Fieldset & Legend

<button> Tag — Clickable Button

Creates a styleable button with customizable behaviour. More flexible than <input type="submit">.

AttributeDescription
nameName of the button sent with form data
typebutton (no action), submit (sends form), reset (clears form)
valueInitial value sent with form data on submission
<button type="submit" name="submitBtn" value="send">Submit</button>
<button type="reset">Clear Form</button>
<button type="button" onclick="alert('Hello!')">Click Me</button>

<fieldset> & <legend> Tags

<fieldset> draws a visible box around related form elements to group them visually. <legend> adds a title or caption to that group box.

<form>
  <fieldset>
    <legend>Personal Information</legend>
    Name: <input type="text"><br>
    Email: <input type="email">
  </fieldset>

  <fieldset>
    <legend>Login Details</legend>
    Username: <input type="text"><br>
    Password: <input type="password">
  </fieldset>
</form>
✅ Using fieldset and legend makes forms more organized and accessible for students and users.

20 HTML5 — Introduction & Semantic Tags

What is HTML5?

HTML5 is the fifth and current version of HTML used to structure and present content on the web. It includes new tags, form controls, APIs, multimedia support, and semantic elements.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>HTML5 Page</title>
</head>
<body>
  <h1>Welcome to HTML5</h1>
</body>
</html>

Semantic Tags in HTML5

Semantic tags clearly describe their meaning and purpose — both to the browser and developer.

<header>

Defines the header section of a document or section (logo, title, navigation).

<header>
  <h1>My Website</h1>
  <p>Welcome to my website!</p>
</header>

<nav>

Defines a section for navigation links.

<nav>
  <a href="home.html">Home</a>
  <a href="about.html">About</a>
</nav>

<article>

Represents a self-contained composition — like a blog post, news item, or article.

<article>
  <h2>News Headline</h2>
  <p>This is the main content of the news.</p>
</article>

<aside>

Represents content indirectly related to the main content — like a sidebar or callout box.

<aside>
  <h4>Related Links</h4>
  <p>See more news articles...</p>
</aside>

<footer>

Defines the footer section of a document — copyright, contact info, links.

<footer>
  <p>© 2025 My Website. All rights reserved.</p>
</footer>
TagPurpose
<header>Top section — logo, title, nav
<nav>Navigation menu links
<main>Main content of the page
<article>Self-contained content like blog/news
<section>Groups related content into sections
<aside>Sidebar — related but not main content
<footer>Bottom section — copyright, links
<figure>Wraps images with a caption
<figcaption>Caption for a figure element
<details>Creates an expandable/collapsible block
<summary>Visible heading for details block
<time>Represents a date/time value
<output>Displays result of a calculation
<progress>Shows a progress bar
<meter>Scalar measurement within a known range
<wbr>Word break opportunity in long strings

HTML5 Tag Examples

<!-- Details / Summary -->
<details>
  <summary>Click to read a fun fact!</summary>
  <p>The details tag helps hide/show extra info.</p>
</details>

<!-- Progress Bar -->
<progress value="70" max="100">70%</progress>

<!-- Meter -->
<meter value="6" min="0" max="10">6 out of 10</meter>

<!-- Time -->
<time datetime="2025-05-13">May 13, 2025</time>

<!-- Output -->
<output id="result">42</output>

<!-- Word Break -->
<p>ThisIsA<wbr>VeryLong<wbr>String</p>

21 HTML5 Media Tags

<audio> Tag

Embeds sound content like music or speech directly in the browser.

<audio controls>
  <source src="song.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

<video> Tag

Embeds a video player for displaying video content.

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>

<source> Tag

Specifies multiple media resources for audio/video elements. Browser picks the first one it supports.

<video controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
</video>

<embed> Tag

Embeds external resources like video, audio, or flash files.

<embed src="file.mp4" width="400" height="300">

<object> Tag

Embeds external objects like multimedia, PDFs, etc.

<object data="file.pdf" type="application/pdf" width="500" height="400"></object>

<picture> Tag

Displays different images for different screen sizes or resolutions — responsive images.

<picture>
  <source media="(min-width: 650px)" srcset="img-large.jpg">
  <source media="(min-width: 465px)" srcset="img-medium.jpg">
  <img src="img-small.jpg" alt="Responsive Image">
</picture>
TagPurpose
<audio>Embed audio/music/speech
<video>Embed video player
<source>Multiple media source options
<embed>Embed external media file
<object>Embed external objects (PDF, multimedia)
<picture>Responsive images for different screen sizes

22 SVG — Scalable Vector Graphics

The <svg> tag is used to draw vector graphics directly in HTML. SVG graphics do NOT lose quality when resized.

<svg width="100" height="100">
  <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
</svg>

SVG Shapes with Examples

1. Rectangle

<svg width="300" height="150" style="border:1px solid gray">
  <rect x="50" y="30" width="200" height="100" fill="skyblue" stroke="black" stroke-width="2"/>
</svg>

2. Circle

<svg width="200" height="200">
  <circle cx="100" cy="100" r="50" fill="orange" stroke="black" stroke-width="2"/>
</svg>

3. Ellipse

<svg width="300" height="150">
  <ellipse cx="150" cy="75" rx="100" ry="50" fill="lightgreen" stroke="black" stroke-width="2"/>
</svg>

4. Line

<svg width="300" height="150">
  <line x1="20" y1="20" x2="280" y2="130" stroke="red" stroke-width="4"/>
</svg>

5. Polygon (Multi-sided shape)

<svg width="300" height="150">
  <polygon points="50,10 90,100 10,100" fill="yellow" stroke="black" stroke-width="2"/>
</svg>

6. Polyline (Connected lines)

<svg width="300" height="150">
  <polyline points="0,40 40,40 40,80 80,80 80,120" fill="none" stroke="blue" stroke-width="2"/>
</svg>

7. Path (Custom curve or route)

<svg width="300" height="150">
  <path d="M10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80" fill="none" stroke="purple" stroke-width="2"/>
</svg>
Shape TagKey Attributes
<rect>x, y, width, height, fill, stroke
<circle>cx (center-x), cy (center-y), r (radius), fill, stroke
<ellipse>cx, cy, rx (x-radius), ry (y-radius), fill, stroke
<line>x1, y1 (start), x2, y2 (end), stroke
<polygon>points (list of x,y coordinates), fill, stroke
<polyline>points (connected), fill="none", stroke
<path>d (path data with M, C, S commands), stroke

23 HTML5 Other Important Tags

<meter> Tag

Represents a scalar measurement within a known range — like a gauge.

<meter value="6" min="0" max="10">6 out of 10</meter>

<figure> & <figcaption>

Groups images with a caption.

<figure style="text-align: center;">
  <img src="example.jpg" alt="Example" width="300">
  <figcaption>Figure: HTML5 Layout Example</figcaption>
</figure>

HTML5 Password Pattern Attribute

The pattern attribute in HTML5 forms validates input using Regular Expressions (Regex). Regex is a special sequence of characters that defines a search pattern.

24 Password Patterns — Regex in HTML5

What is a Pattern?

The pattern attribute uses Regular Expressions (Regex) to validate what the user types in an input field. If input doesn't match, the browser shows an error on submit.

Pattern 1 — Letters Only

[A-Za-z]{1,15} — Allows only uppercase or lowercase letters. Min 1, max 15 characters.

<input type="text" pattern="[A-Za-z]{1,15}" title="Only letters, max 15 chars">
<!-- Accepts: Hello, World, Abc -->
<!-- Rejects: Hello123, Abc@  -->

Pattern 2 — Letters and Numbers

[A-Za-z0-9]+ — Allows letters (A–Z, a–z) and digits (0–9) only. At least 1 character required.

<input type="text" pattern="[A-Za-z0-9]+" title="Only letters and numbers">
<!-- Accepts: abc123, John2024 -->
<!-- Rejects: abc@123, hello! -->

Pattern 3 — Digits and Decimal

[0-9.]{1,10} — Allows digits (0–9) and dot (.) only. Between 1 and 10 characters.

<input type="text" pattern="[0-9.]{1,10}" title="Only digits and decimal point">
<!-- Accepts: 123.45, 0.123 -->
<!-- Rejects: 123,45 (comma), 1.2.3 (multiple dots) -->

Pattern 4 — Letters, Digits, Underscore & @

[A-Za-z0-9_@]+ — Allows letters, digits, underscore and @ symbol.

<input type="text" pattern="[A-Za-z0-9_@]+" title="Letters, digits, _ and @">
<!-- Accepts: user_name, user@123 -->
<!-- Rejects: name!@, hello#    -->

Pattern 5 — Must Start with a Letter

[A-Za-z][A-Za-z0-9_-]{1,25} — Must start with a letter, followed by 1–25 characters (letters, digits, _ or -).

<input type="text" pattern="[A-Za-z][A-Za-z0-9_-]{1,25}" title="Start with letter, 1–25 chars">
<!-- Accepts: A1_b-2, Rajat_Kumar -->
<!-- Rejects: 1Start, -user123   -->

Pattern 6 — Positive / Negative Numbers

[0-9.+-]{1,10} — Allows digits, +, - and dot. Max 10 characters. For numeric values with signs.

<input type="text" pattern="[0-9.+-]{1,10}" title="Positive/negative numbers, max 10 digits">
<!-- Accepts: +123.45, -99.9 -->
<!-- Rejects: 123a, ++123   -->

Strong Password Pattern

Pattern: (?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).{8,}

PartMeaning
(?=.*[a-z])Must contain at least one lowercase letter (a–z)
(?=.*[A-Z])Must contain at least one uppercase letter (A–Z)
(?=.*\d)Must contain at least one digit (0–9)
(?=.*[@$!%*?&])Must contain at least one special character (@ $ ! % * ? &)
.{8,}Must be at least 8 characters long

Final Rule Summary

Your password must contain:

  • At least one lowercase letter
  • At least one uppercase letter
  • At least one digit
  • At least one special character (@ $ ! % * ? &)
  • Minimum 8 characters in length

Valid Passwords

  • Rajat@123
  • Hello2024$
  • MyPass1!

Invalid Passwords

  • rajat123 ❌ — No uppercase, no special character
  • Rajat@ ❌ — No digit
  • Rajat123 ❌ — No special character
<!-- Strong Password Input -->
<input type="password"
       pattern="(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&]).{8,}"
       title="Min 8 chars: 1 uppercase, 1 lowercase, 1 digit, 1 special char"
       required>

25 Full HTML5 Practical Page

This page combines all HTML5 semantic tags, media, form, SVG and more into one working example:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Semantic HTML5 Page</title>
</head>
<body style="font-family: Arial, sans-serif; margin: 0; padding: 0;">

  <!-- HEADER -->
  <header style="background-color: #4CAF50; color: white; padding: 20px; text-align: center;">
    <h1>My Semantic HTML5 Page</h1>
    <p>Learning HTML5 Structure</p>
  </header>

  <!-- NAVIGATION -->
  <nav style="background-color: #333; padding: 10px; text-align: center;">
    <a href="#" style="color: white; margin: 0 15px; text-decoration: none;">Home</a>
    <a href="#" style="color: white; margin: 0 15px; text-decoration: none;">Services</a>
    <a href="#" style="color: white; margin: 0 15px; text-decoration: none;">Contact</a>
  </nav>

  <!-- MAIN CONTENT -->
  <main style="padding: 20px; background-color: #f4f4f4;">

    <!-- Article -->
    <article style="background: white; padding: 15px; margin-bottom: 20px; border: 1px solid #ddd;">
      <h2>Main Article</h2>
      <p>This article covers the importance of semantic HTML tags.</p>
    </article>

    <!-- Aside -->
    <aside style="background-color: #e7f3fe; padding: 15px; margin-bottom: 20px; border-left: 5px solid #2196F3;">
      <h3>Side Info</h3>
      <p>HTML5 introduced tags like &lt;article&gt;, &lt;section&gt;, &lt;aside&gt; etc.</p>
    </aside>

    <!-- Section -->
    <section style="background: white; padding: 15px; margin-bottom: 20px; border: 1px solid #ccc;">
      <h2>Another Section</h2>
      <p>This section adds more information.</p>
    </section>

    <!-- Figure -->
    <figure style="text-align: center; margin: 20px auto;">
      <img src="example.jpg" alt="Example Image" width="300" style="border: 1px solid #ccc; padding: 5px;">
      <figcaption style="font-style: italic; color: #555;">Figure: HTML5 Layout</figcaption>
    </figure>

    <!-- Details / Summary -->
    <details style="margin-bottom: 15px;">
      <summary>Click to read a fun fact!</summary>
      <p>The details and summary tags help hide/show extra information.</p>
    </details>

    <!-- Mark -->
    <mark>This is highlighted text using the mark tag.</mark><br><br>

    <!-- Progress -->
    <progress value="70" max="100">70%</progress><br><br>

    <!-- Time -->
    <time datetime="2025-05-13">May 13, 2025</time><br><br>

    <!-- Output -->
    <output id="result">42</output><br><br>

    <!-- Meter -->
    <meter value="6" min="0" max="10">6 out of 10</meter><br><br>

    <!-- SVG Circle -->
    <svg width="100" height="100">
      <circle cx="50" cy="50" r="40" stroke="green" stroke-width="4" fill="yellow" />
    </svg><br><br>

    <!-- Video -->
    <video width="320" height="240" controls>
      <source src="movie.mp4" type="video/mp4">
      <source src="movie.ogg" type="video/ogg">
      Your browser does not support the video tag.
    </video><br><br>

    <!-- Audio -->
    <audio controls>
      <source src="song.mp3" type="audio/mpeg">
      Your browser does not support the audio element.
    </audio><br><br>

    <!-- Object (PDF) -->
    <object data="file.pdf" type="application/pdf" width="500" height="400"></object><br><br>

    <!-- Embed -->
    <embed src="file.mp4" width="400" height="300"><br><br>

    <!-- Word Break -->
    <p>ThisIsA<wbr>VeryLong<wbr>String</p>

    <!-- Form -->
    <form>
      <label for="name">Name:</label>
      <input type="text" id="name" name="name" placeholder="Enter name"><br><br>

      <label for="email">Email:</label>
      <input type="email" id="email" name="email" required><br><br>

      <label for="password">Password:</label>
      <input type="password" id="password" name="password"
             pattern="[A-Za-z0-9]{6,}"
             title="6 or more alphanumeric characters"><br><br>

      <button type="submit">Submit</button>
    </form>

  </main>

  <!-- FOOTER -->
  <footer style="background-color: #333; color: white; text-align: center; padding: 15px;">
    <p>&copy; 2025 My Website. All rights reserved.</p>
  </footer>

</body>
</html>