Master Interviews
Anywhere, Anytime
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
HTML · Complete Question Bank
Practice the complete collection of HTML interview questions including theory, coding, MCQs and real interview problems.
Questions
213
Full database
Topics
68
Categorised
Difficulty
Mixed Levels
Easy Hard
Scroll through every important HTML question asked in real interviews. Includes MCQs, subjective questions, and coding prompts.
Browse more HTML questions, explore related subjects, or practice full interview sets to strengthen your preparation.
Correct Answer: <a>
Correct Answer: id
Correct Answer: alt
<img src="small.jpg"
srcset="small.jpg 480w, medium.jpg 800w, large.jpg 1200w"
sizes="(max-width: 600px) 480px, 800px"
alt="Sample image">
Correct Answer: Hyper Text Markup Language
Correct Answer: Markup Language
Correct Answer: <html>
<html>
<head>
<!-- Meta information goes here -->
</head>
<body>
<!-- Visible content goes here -->
</body>
</html>Correct Answer: It tells the browser which version of HTML the page is written in
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<p>Content here</p>
</body>
</html>Correct Answer: <!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>HTML5 Document</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>Correct Answer: <paragraph>
<!DOCTYPE html>
<html>
<head>
<title>Correct Structure</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>This paragraph belongs in the body</p>
</body>
</html>Correct Answer: In the <body> section
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<h1>This heading is visible</h1>
<p>This paragraph is visible</p>
<img src="image.jpg" alt="This image is visible">
</body>
</html>Correct Answer: The title shown in the browser tab and search results
<!DOCTYPE html>
<html>
<head>
<title>Learn HTML Basics - Complete Guide</title>
</head>
<body>
<h1>Welcome to HTML Tutorial</h1>
</body>
</html>Correct Answer: Most HTML tags come in pairs with an opening and closing tag
<!-- Paired tags -->
<p>This is a paragraph</p>
<div>This is a division</div>
<!-- Self-closing tags -->
<img src="photo.jpg" alt="Photo">
<br>
<input type="text">
<!-- Nested tags -->
<div>
<p>Paragraph inside a div</p>
</div>Correct Answer: DOCTYPE, html, head, body
<!DOCTYPE html>
<html>
<head>
<title>Correct Order Example</title>
<meta charset="UTF-8">
</head>
<body>
<h1>Main Content</h1>
<p>Page content here</p>
</body>
</html>Correct Answer: The page may still render but it is invalid HTML
<!-- Invalid - missing closing html tag -->
<!DOCTYPE html>
<html>
<head>
<title>Missing Close Tag</title>
</head>
<body>
<p>Content</p>
</body>
<!-- Missing </html> -->
<!-- Valid - proper structure -->
<!DOCTYPE html>
<html>
<head>
<title>Proper Structure</title>
</head>
<body>
<p>Content</p>
</body>
</html>Correct Answer: Head contains metadata, body contains visible content
<!DOCTYPE html>
<html>
<head>
<!-- Metadata - Not visible on page -->
<title>My Website</title>
<meta charset="UTF-8">
<meta name="description" content="Website description">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<!-- Visible content -->
<h1>Welcome to My Website</h1>
<p>This text is visible to users</p>
<img src="logo.png" alt="Logo">
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>DOCTYPE Example</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Basic HTML Structure</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Website Header</h1>
</header>
<main>
<p>Main content goes here</p>
</main>
<footer>
<p>Copyright 2025</p>
</footer>
</body>
</html><!DOCTYPE html>
<html>
<head>
<!-- METADATA - Not visible -->
<title>Head vs Body Example</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
<script src="script.js"></script>
</head>
<body>
<!-- VISIBLE CONTENT -->
<h1>This heading is visible</h1>
<p>This paragraph is visible</p>
<button>This button is visible</button>
<img src="photo.jpg" alt="This image is visible">
</body>
</html>Correct Answer: 6
<h1>Main Heading - Most Important</h1> <h2>Sub Heading</h2> <h3>Sub Sub Heading</h3> <h4>Minor Heading</h4> <h5>Smaller Heading</h5> <h6>Smallest Heading</h6>
Correct Answer: <h1>
<h1>Welcome to My Website</h1> <p>This is the main heading of the page</p> <h2>About Us</h2> <p>This is a sub-section</p>
Correct Answer: <p>
<p>This is a paragraph of text.</p> <p>This is another paragraph.</p> <p>Each paragraph is separated automatically.</p>
Correct Answer: <strong>
<p>This is <strong>very important</strong> information.</p> <p>This is <b>just bold</b> text without emphasis.</p>
Correct Answer: <em>
<p>I <em>really</em> need to finish this project.</p> <p>The term <i>HTML</i> stands for HyperText Markup Language.</p>
Correct Answer: <br>
<p>First line of text<br>Second line of text<br>Third line of text</p> <address> John Doe<br> 123 Main Street<br> City, State 12345 </address>
Correct Answer: <hr>
<h2>Section One</h2> <p>Content for section one</p> <hr> <h2>Section Two</h2> <p>Content for section two</p>
Correct Answer: <u>
<p>This word is <u>underlined</u>.</p>
<p>Marking a <u class="spelling-error">mispelled</u> word.</p>
<!-- Better approach with CSS -->
<style>
.underlined {
text-decoration: underline;
}
</style>
<p>This uses <span class="underlined">CSS</span> instead.</p>Correct Answer: To highlight or mark text
<p>Search results for "HTML":</p> <p><mark>HTML</mark> is the standard markup language.</p> <p>Learn <mark>HTML</mark>, CSS, and JavaScript.</p> <p>This is <mark>highlighted text</mark> for reference.</p>
Correct Answer: Text with less importance or fine print
<p>Regular text size.</p> <p><small>This is smaller text, like fine print.</small></p> <footer> <p><small>Copyright 2025. All rights reserved.</small></p> <p><small>Terms and conditions apply.</small></p> </footer>
Correct Answer: <del> and <ins>
<p>The meeting is on <del>Monday</del> <ins>Tuesday</ins>.</p> <p>Price: <del>$100</del> <ins>$80</ins></p> <p> <del datetime="2025-01-15">Old information</del> <ins datetime="2025-01-20">Updated information</ins> </p>
Correct Answer: <sub> and <sup>
<!-- Subscript examples --> <p>Water formula: H<sub>2</sub>O</p> <p>Carbon dioxide: CO<sub>2</sub></p> <!-- Superscript examples --> <p>Einstein's equation: E=mc<sup>2</sup></p> <p>Area formula: A=πr<sup>2</sup></p> <p>Footnote reference<sup>1</sup></p>
Correct Answer: <!-- This is a comment -->
<!-- This is a single line comment --> <!-- This is a multi-line comment It can span multiple lines Useful for longer explanations --> <h1>Welcome</h1> <!-- TODO: Add navigation menu here --> <!-- <p>This paragraph is commented out</p> -->
<!-- Semantic importance -->
<p><strong>Warning:</strong> This action cannot be undone.</p>
<p><strong>Important:</strong> Submit by Friday.</p>
<!-- Visual styling only -->
<p><b>Product features:</b> waterproof, durable, lightweight</p>
<p><b>Chapter 1:</b> Introduction to HTML</p>
<!-- Best practice with CSS -->
<style>
.bold {
font-weight: bold;
}
</style>
<p class="bold">Styled with CSS</p><!-- Correct heading hierarchy -->
<h1>Main Title of the Page</h1>
<h2>First Major Section</h2>
<p>Content for first section</p>
<h3>Subsection of First Section</h3>
<p>Content for subsection</p>
<h3>Another Subsection</h3>
<p>More content</p>
<h2>Second Major Section</h2>
<p>Content for second section</p>
<h3>Subsection of Second Section</h3>
<p>Content here</p>
<h4>Minor point under subsection</h4>
<p>Detailed content</p><!-- Emphasis (semantic) -->
<p>I <em>really</em> need to finish this project.</p>
<p>You <em>must</em> submit the form by Friday.</p>
<p>That is <em>not</em> what I meant.</p>
<!-- Italic (stylistic) -->
<p>The term <i>HTML</i> stands for HyperText Markup Language.</p>
<p>My favorite book is <i>To Kill a Mockingbird</i>.</p>
<p>The restaurant serves <i>bon appétit</i> cuisine.</p>
<p><i>Homo sapiens</i> is the scientific name for humans.</p>
<!-- CSS approach for design -->
<style>
.italic-style {
font-style: italic;
}
</style>
<p class="italic-style">Styled with CSS</p>Correct Answer: The destination URL of the link
<!-- Absolute URL --> <a href="https://www.google.com">Google</a> <!-- Relative URL --> <a href="contact.html">Contact</a> <!-- Email link --> <a href="mailto:info@example.com">Email Us</a> <!-- Phone link --> <a href="tel:+1234567890">Call Us</a>
Correct Answer: _blank
<!-- Opens in new tab --> <a href="https://example.com" target="_blank">Visit Example</a> <!-- Opens in same tab (default) --> <a href="about.html" target="_self">About</a> <!-- Best practice with security --> <a href="https://external-site.com" target="_blank" rel="noopener noreferrer">External Link</a>
Correct Answer: _self
<!-- These two are equivalent --> <a href="page.html">Link 1</a> <a href="page.html" target="_self">Link 2</a> <!-- Both open in same tab by default -->
Correct Answer: https://www.example.com/page.html
<!-- Absolute URLs --> <a href="https://www.google.com">Google</a> <a href="https://example.com/about.html">About</a> <a href="http://website.org/page">External Site</a> <!-- Relative URLs --> <a href="contact.html">Contact</a> <a href="/images/photo.jpg">Photo</a> <a href="../index.html">Home</a>
Correct Answer: The root of the website
<!-- Root-relative URL (starts from website root) --> <a href="/about.html">About</a> <a href="/images/logo.png">Logo</a> <a href="/contact/form.html">Contact</a> <!-- Page-relative URL (relative to current page) --> <a href="about.html">About</a> <a href="images/logo.png">Logo</a> <a href="../contact.html">Contact (parent folder)</a>
Correct Answer: <a href="mailto:user@example.com">
<!-- Basic email link --> <a href="mailto:info@example.com">Email Us</a> <!-- With subject line --> <a href="mailto:support@example.com?subject=Help Request">Get Help</a> <!-- With subject and body --> <a href="mailto:sales@example.com?subject=Product Inquiry&body=I am interested in...">Contact Sales</a> <!-- With CC and BCC --> <a href="mailto:info@example.com?cc=manager@example.com&bcc=admin@example.com">Email with CC</a>
Correct Answer: <a href="#section1">
<!-- Link to section --> <a href="#about">Go to About Section</a> <a href="#contact">Go to Contact Section</a> <a href="#top">Back to Top</a> <!-- Target sections with IDs --> <section id="about"> <h2>About Us</h2> <p>Content here...</p> </section> <section id="contact"> <h2>Contact</h2> <p>Contact information...</p> </section> <div id="top"> <h1>Page Title</h1> </div>
Correct Answer: Additional information shown on hover
<!-- Link with title attribute --> <a href="https://example.com" title="Visit Example Website">Example</a> <!-- Descriptive title for external link --> <a href="document.pdf" title="Download Product Brochure (PDF, 2MB)">Brochure</a> <!-- Title for context --> <a href="/pricing" title="View our pricing plans and packages">Pricing</a>
Correct Answer: :visited
/* Link pseudo-classes in correct order */
/* Unvisited links */
a:link {
color: blue;
text-decoration: none;
}
/* Visited links */
a:visited {
color: purple;
}
/* Mouse over link */
a:hover {
color: red;
text-decoration: underline;
}
/* Active/clicked link */
a:active {
color: orange;
}Correct Answer: text-decoration: none
/* Remove underline from all links */
a {
text-decoration: none;
}
/* Remove underline but add on hover */
a {
text-decoration: none;
color: blue;
}
a:hover {
text-decoration: underline;
color: darkblue;
}
/* Style specific links */
.nav-link {
text-decoration: none;
font-weight: bold;
}Correct Answer: Prompts the browser to download the file instead of navigating to it
<!-- Download with original filename --> <a href="document.pdf" download>Download PDF</a> <!-- Download with custom filename --> <a href="report.pdf" download="Annual-Report-2024.pdf">Download Report</a> <!-- Download image --> <a href="photo.jpg" download="my-photo.jpg">Download Image</a> <!-- Must be same-origin for security --> <a href="/files/data.zip" download>Download ZIP</a>
<!-- ABSOLUTE URLs (full address) --> <a href="https://www.google.com">Google</a> <a href="https://example.com/about.html">About</a> <a href="http://website.org/page.html">External</a> <!-- RELATIVE URLs --> <!-- Page-relative (same directory) --> <a href="contact.html">Contact</a> <a href="page2.html">Page 2</a> <!-- Parent directory --> <a href="../index.html">Home</a> <a href="../../main.html">Main</a> <!-- Root-relative (from website root) --> <a href="/about.html">About</a> <a href="/images/logo.png">Logo</a> <a href="/products/item.html">Product</a> <!-- Subdirectory --> <a href="images/photo.jpg">Photo</a> <a href="docs/guide.pdf">Guide</a>
<!-- Basic new tab link (less secure) --> <a href="https://example.com" target="_blank">Visit Example</a> <!-- RECOMMENDED: Secure new tab link --> <a href="https://external-site.com" target="_blank" rel="noopener noreferrer">External Link</a> <!-- Real-world examples --> <!-- External website --> <a href="https://www.wikipedia.org" target="_blank" rel="noopener noreferrer">Wikipedia</a> <!-- PDF document --> <a href="document.pdf" target="_blank" rel="noopener noreferrer">View PDF</a> <!-- Social media --> <a href="https://twitter.com/share" target="_blank" rel="noopener noreferrer">Share on Twitter</a> <!-- Help documentation --> <a href="/help/guide.html" target="_blank" rel="noopener noreferrer">Open Help in New Tab</a>
<!-- Title provides context for brief link text --> <a href="https://example.com" title="Visit Example Company's Official Website">Example</a> <!-- Title describes file details --> <a href="report.pdf" title="Download Annual Report 2024 (PDF, 2.5 MB)" download>Download Report</a> <!-- Title for external link warning --> <a href="https://external-site.com" title="External link - Opens in new window" target="_blank" rel="noopener noreferrer">Visit Partner Site</a> <!-- Title for icon-only link --> <a href="/help" title="Help and Documentation"> <img src="help-icon.png" alt="Help"> </a> <!-- Title adds clarity --> <a href="/products" title="Browse our full product catalog">Products</a> <!-- BAD: Redundant title --> <a href="contact.html" title="Contact Us">Contact Us</a> <!-- Better: More informative --> <a href="contact.html" title="Send us a message or find our office locations">Contact Us</a>
Correct Answer: <img>
<!-- Basic image --> <img src="photo.jpg" alt="A beautiful sunset"> <!-- Image with path --> <img src="images/logo.png" alt="Company Logo"> <!-- Image with absolute URL --> <img src="https://example.com/image.jpg" alt="Description">
Correct Answer: The path or URL to the image file
<!-- Relative path --> <img src="photo.jpg" alt="Photo"> <!-- Folder path --> <img src="images/logo.png" alt="Logo"> <!-- Root-relative path --> <img src="/assets/banner.jpg" alt="Banner"> <!-- Absolute URL --> <img src="https://example.com/image.jpg" alt="External Image">
Correct Answer: To provide alternative text when image cannot be displayed
<!-- Descriptive alt text --> <img src="sunset.jpg" alt="Orange sunset over the ocean with palm trees"> <!-- Product image --> <img src="laptop.jpg" alt="Silver laptop with 15-inch screen"> <!-- Logo --> <img src="logo.png" alt="Acme Corporation logo"> <!-- Decorative image (empty alt) --> <img src="decoration.png" alt="">
Correct Answer: width and height
<!-- Fixed size in pixels -->
<img src="photo.jpg" alt="Photo" width="300" height="200">
<!-- Only width (height auto) -->
<img src="banner.jpg" alt="Banner" width="800">
<!-- Better approach with CSS -->
<style>
.responsive-img {
max-width: 100%;
height: auto;
}
</style>
<img src="photo.jpg" alt="Photo" class="responsive-img">Correct Answer: PNG and GIF
<!-- PNG with transparent background --> <img src="logo.png" alt="Company Logo"> <!-- GIF with transparency --> <img src="icon.gif" alt="Icon"> <!-- WebP with transparency (modern) --> <img src="graphic.webp" alt="Graphic"> <!-- JPG does NOT support transparency --> <img src="photo.jpg" alt="Photo with solid background">
Correct Answer: To group an image with its caption
<!-- Basic figure with caption --> <figure> <img src="sunset.jpg" alt="Sunset over mountains"> <figcaption>A beautiful sunset captured in the Himalayas</figcaption> </figure> <!-- Caption before image --> <figure> <figcaption>Company Logo Evolution</figcaption> <img src="logo-history.png" alt="Logo designs from 2010 to 2024"> </figure> <!-- Multiple images in one figure --> <figure> <img src="before.jpg" alt="Before renovation"> <img src="after.jpg" alt="After renovation"> <figcaption>Kitchen renovation before and after</figcaption> </figure>
Correct Answer: <audio>
<!-- Basic audio with controls --> <audio controls> <source src="song.mp3" type="audio/mpeg"> <source src="song.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio> <!-- Auto-play and loop --> <audio autoplay loop muted> <source src="background.mp3" type="audio/mpeg"> </audio> <!-- Multiple format support --> <audio controls> <source src="podcast.mp3" type="audio/mpeg"> <source src="podcast.ogg" type="audio/ogg"> <source src="podcast.wav" type="audio/wav"> Audio not supported </audio>
Correct Answer: controls
<!-- Basic video with controls --> <video controls width="640" height="360"> <source src="movie.mp4" type="video/mp4"> <source src="movie.webm" type="video/webm"> Your browser does not support the video tag. </video> <!-- With poster image --> <video controls poster="thumbnail.jpg"> <source src="video.mp4" type="video/mp4"> </video> <!-- Autoplay muted (for backgrounds) --> <video autoplay muted loop> <source src="background.mp4" type="video/mp4"> </video>
Correct Answer: To embed another HTML page or external content
<!-- Basic iframe --> <iframe src="https://www.example.com" width="600" height="400" title="Example Website"></iframe> <!-- YouTube video embed --> <iframe width="560" height="315" src="https://www.youtube.com/embed/VIDEO_ID" title="YouTube video" allowfullscreen></iframe> <!-- Google Maps embed --> <iframe src="https://www.google.com/maps/embed?pb=..." width="600" height="450" style="border:0;" allowfullscreen="" loading="lazy"></iframe> <!-- With sandbox for security --> <iframe src="external-content.html" sandbox="allow-scripts allow-same-origin" title="External Content"></iframe>
<!-- Good descriptive alt text --> <img src="team.jpg" alt="Five smiling team members in office"> <!-- Product image --> <img src="laptop.jpg" alt="Silver 15-inch laptop with backlit keyboard"> <!-- Informative alt text --> <img src="chart.png" alt="Bar chart showing 25% increase in sales from 2023 to 2024"> <!-- Decorative image (empty alt) --> <img src="border-decoration.png" alt=""> <!-- BAD: Too generic --> <img src="photo.jpg" alt="photo"> <!-- GOOD: Specific and descriptive --> <img src="photo.jpg" alt="Sunset over mountains with orange and pink sky">
<!-- JPG for photographs --> <img src="landscape.jpg" alt="Mountain landscape"> <img src="portrait.jpg" alt="Person smiling"> <!-- PNG for logos and transparency --> <img src="logo.png" alt="Company logo"> <img src="icon.png" alt="Menu icon"> <!-- Comparison example --> <!-- Photo: JPG is better (smaller file) --> <img src="photo.jpg" alt="Beach sunset"> <!-- 200 KB, good quality --> <!-- Logo: PNG is better (transparency + quality) --> <img src="logo.png" alt="Brand logo"> <!-- 50 KB, perfect quality, transparent background --> <!-- Modern approach: WebP with fallback --> <picture> <source srcset="image.webp" type="image/webp"> <source srcset="image.jpg" type="image/jpeg"> <img src="image.jpg" alt="Fallback image"> </picture>
<!-- Basic HTML5 video with controls -->
<video controls width="640" height="360">
<source src="movie.mp4" type="video/mp4">
<source src="movie.webm" type="video/webm">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
<!-- Video with poster and attributes -->
<video controls width="800" height="450" poster="thumbnail.jpg" preload="metadata">
<source src="tutorial.mp4" type="video/mp4">
<source src="tutorial.webm" type="video/webm">
Sorry, your browser does not support embedded videos.
</video>
<!-- Responsive video with CSS -->
<style>
.video-container {
position: relative;
padding-bottom: 56.25%; /* 16:9 aspect ratio */
height: 0;
overflow: hidden;
}
.video-container video {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
</style>
<div class="video-container">
<video controls>
<source src="video.mp4" type="video/mp4">
</video>
</div>
<!-- YouTube embed with iframe -->
<iframe width="560" height="315"
src="https://www.youtube.com/embed/VIDEO_ID"
title="YouTube video player"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen>
</iframe>
<!-- Background video (autoplay muted) -->
<video autoplay muted loop playsinline>
<source src="background.mp4" type="video/mp4">
</video>Correct Answer: <ul>
<!-- Basic unordered list --> <ul> <li>Apple</li> <li>Banana</li> <li>Orange</li> </ul> <!-- List with multiple items --> <ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> <li>React</li> </ul>
Correct Answer: <ol>
<!-- Basic ordered list --> <ol> <li>First step</li> <li>Second step</li> <li>Third step</li> </ol> <!-- List starting from 5 --> <ol start="5"> <li>Item five</li> <li>Item six</li> <li>Item seven</li> </ol> <!-- List with letters --> <ol type="A"> <li>Option A</li> <li>Option B</li> <li>Option C</li> </ol>
Correct Answer: <li>
<!-- List items in unordered list --> <ul> <li>Coffee</li> <li>Tea</li> <li>Milk</li> </ul> <!-- List items in ordered list --> <ol> <li>Wake up</li> <li>Brush teeth</li> <li>Have breakfast</li> </ol> <!-- List items with links --> <ul> <li><a href="home.html">Home</a></li> <li><a href="about.html">About</a></li> <li><a href="contact.html">Contact</a></li> </ul>
Correct Answer: <dl>
<!-- Basic description list --> <dl> <dt>HTML</dt> <dd>HyperText Markup Language</dd> <dt>CSS</dt> <dd>Cascading Style Sheets</dd> <dt>JavaScript</dt> <dd>Programming language for web interactivity</dd> </dl> <!-- Term with multiple definitions --> <dl> <dt>Python</dt> <dd>A high-level programming language</dd> <dd>A type of snake</dd> </dl>
Correct Answer: type="A"
<!-- Uppercase letters --> <ol type="A"> <li>First item</li> <li>Second item</li> <li>Third item</li> </ol> <!-- Displays: A. B. C. --> <!-- Lowercase letters --> <ol type="a"> <li>First item</li> <li>Second item</li> </ol> <!-- Displays: a. b. --> <!-- Roman numerals --> <ol type="I"> <li>Chapter One</li> <li>Chapter Two</li> </ol> <!-- Displays: I. II. --> <!-- Default numbers --> <ol type="1"> <li>Step one</li> <li>Step two</li> </ol> <!-- Displays: 1. 2. -->
Correct Answer: Specifies which number to begin counting from
<!-- Start from number 5 --> <ol start="5"> <li>Item five</li> <li>Item six</li> <li>Item seven</li> </ol> <!-- Displays: 5. 6. 7. --> <!-- Start with letter C --> <ol type="A" start="3"> <li>Third option</li> <li>Fourth option</li> </ol> <!-- Displays: C. D. --> <!-- Continue a list --> <ol> <li>First step</li> <li>Second step</li> </ol> <p>Some text in between</p> <ol start="3"> <li>Third step</li> <li>Fourth step</li> </ol>
Correct Answer: Inside an <li> element of the parent list
<!-- Correct nesting -->
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
</ul>
</li>
<li>Vegetables
<ul>
<li>Carrot</li>
<li>Broccoli</li>
</ul>
</li>
</ul>
<!-- Mixed list types -->
<ol>
<li>Main topic
<ul>
<li>Subtopic A</li>
<li>Subtopic B</li>
</ul>
</li>
<li>Another topic</li>
</ol>Correct Answer: <dt>
<!-- dt for term, dd for definition --> <dl> <dt>HTML</dt> <dd>Markup language for web pages</dd> <dt>CSS</dt> <dd>Language for styling web pages</dd> </dl> <!-- Multiple definitions for one term --> <dl> <dt>Java</dt> <dd>Programming language</dd> <dd>Type of coffee</dd> <dd>Island in Indonesia</dd> </dl> <!-- Multiple terms, one definition --> <dl> <dt>HTML</dt> <dt>HyperText Markup Language</dt> <dd>Standard language for creating web pages</dd> </dl>
Correct Answer: Numbers the list in descending order
<!-- Reversed numbering --> <ol reversed> <li>Bronze medal</li> <li>Silver medal</li> <li>Gold medal</li> </ol> <!-- Displays: 3. 2. 1. --> <!-- Reversed with start attribute --> <ol reversed start="10"> <li>Item ten</li> <li>Item nine</li> <li>Item eight</li> </ol> <!-- Displays: 10. 9. 8. --> <!-- Top 5 countdown --> <ol reversed start="5"> <li>Fifth place</li> <li>Fourth place</li> <li>Third place</li> <li>Second place</li> <li>First place</li> </ol> <!-- Displays: 5. 4. 3. 2. 1. -->
<!-- ORDERED LIST (sequence matters) --> <h3>How to Make Coffee:</h3> <ol> <li>Boil water</li> <li>Add coffee grounds to filter</li> <li>Pour hot water over grounds</li> <li>Wait 4 minutes</li> <li>Enjoy your coffee</li> </ol> <h3>Top 3 Programming Languages:</h3> <ol> <li>Python</li> <li>JavaScript</li> <li>Java</li> </ol> <!-- UNORDERED LIST (order doesn't matter) --> <h3>Programming Languages I Know:</h3> <ul> <li>Python</li> <li>JavaScript</li> <li>Java</li> <li>C++</li> </ul> <h3>Grocery List:</h3> <ul> <li>Milk</li> <li>Bread</li> <li>Eggs</li> <li>Butter</li> </ul> <h3>Website Features:</h3> <ul> <li>Responsive design</li> <li>Fast loading</li> <li>Secure checkout</li> <li>24/7 support</li> </ul>
<!-- Basic nested list -->
<ul>
<li>Fruits
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Orange</li>
</ul>
</li>
<li>Vegetables
<ul>
<li>Carrot</li>
<li>Broccoli</li>
</ul>
</li>
</ul>
<!-- Multi-level nesting -->
<ul>
<li>Programming Languages
<ul>
<li>Frontend
<ul>
<li>JavaScript</li>
<li>TypeScript</li>
</ul>
</li>
<li>Backend
<ul>
<li>Python</li>
<li>Java</li>
<li>Node.js</li>
</ul>
</li>
</ul>
</li>
</ul>
<!-- Mixed list types -->
<ol>
<li>Chapter 1: Introduction
<ul>
<li>What is HTML?</li>
<li>Why learn HTML?</li>
</ul>
</li>
<li>Chapter 2: Basics
<ul>
<li>Tags</li>
<li>Attributes</li>
<li>Elements</li>
</ul>
</li>
</ol>
<!-- Navigation menu structure -->
<ul>
<li><a href="/">Home</a></li>
<li>Products
<ul>
<li><a href="/laptops">Laptops</a></li>
<li><a href="/phones">Phones</a></li>
<li>Accessories
<ul>
<li><a href="/cases">Cases</a></li>
<li><a href="/chargers">Chargers</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="/contact">Contact</a></li>
</ul><!-- Glossary --> <dl> <dt>HTML</dt> <dd>HyperText Markup Language, used to structure web content</dd> <dt>CSS</dt> <dd>Cascading Style Sheets, used to style web pages</dd> <dt>JavaScript</dt> <dd>Programming language for web interactivity</dd> </dl> <!-- Product specifications --> <dl> <dt>Product Name</dt> <dd>Professional Laptop Pro</dd> <dt>Screen Size</dt> <dd>15.6 inches</dd> <dt>RAM</dt> <dd>16 GB</dd> <dt>Storage</dt> <dd>512 GB SSD</dd> <dt>Price</dt> <dd>$1,299</dd> </dl> <!-- FAQ format --> <dl> <dt>What is your return policy?</dt> <dd>We offer 30-day returns on all products with proof of purchase.</dd> <dt>Do you ship internationally?</dt> <dd>Yes, we ship to over 100 countries worldwide.</dd> <dt>How long does shipping take?</dt> <dd>Standard shipping takes 3-5 business days. Express shipping takes 1-2 days.</dd> </dl> <!-- Contact information --> <dl> <dt>Name</dt> <dd>John Smith</dd> <dt>Email</dt> <dd>john.smith@example.com</dd> <dt>Phone</dt> <dd>+1 (555) 123-4567</dd> <dt>Address</dt> <dd>123 Main Street, New York, NY 10001</dd> </dl> <!-- Term with multiple definitions --> <dl> <dt>Bank</dt> <dd>Financial institution that accepts deposits</dd> <dd>Land alongside a river</dd> <dd>To tilt an aircraft during a turn</dd> </dl>
Correct Answer: <table>
<!-- Basic table structure -->
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
<tr>
<td>Sarah</td>
<td>30</td>
</tr>
</table>Correct Answer: <tr>
<!-- Table with three rows -->
<table>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
</tr>
<tr>
<td>Row 3, Cell 1</td>
<td>Row 3, Cell 2</td>
</tr>
</table>Correct Answer: <td>
<!-- Table with data cells -->
<table>
<tr>
<td>Apple</td>
<td>$2.50</td>
</tr>
<tr>
<td>Banana</td>
<td>$1.80</td>
</tr>
<tr>
<td>Orange</td>
<td>$3.00</td>
</tr>
</table>Correct Answer: <th>
<!-- Table with header row -->
<table>
<tr>
<th>Product</th>
<th>Price</th>
<th>Stock</th>
</tr>
<tr>
<td>Laptop</td>
<td>$999</td>
<td>15</td>
</tr>
<tr>
<td>Mouse</td>
<td>$25</td>
<td>50</td>
</tr>
</table>Correct Answer: <caption>
<!-- Table with caption -->
<table>
<caption>Monthly Sales Report</caption>
<tr>
<th>Month</th>
<th>Sales</th>
</tr>
<tr>
<td>January</td>
<td>$5,000</td>
</tr>
<tr>
<td>February</td>
<td>$6,200</td>
</tr>
</table>
<!-- Caption with styling -->
<table>
<caption style="font-weight: bold; font-size: 1.2em;">Employee Directory</caption>
<tr>
<th>Name</th>
<th>Department</th>
</tr>
<tr>
<td>John Doe</td>
<td>Engineering</td>
</tr>
</table>Correct Answer: Makes a cell span across multiple columns
<!-- Cell spanning 2 columns -->
<table border="1">
<tr>
<th colspan="2">Full Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>25</td>
</tr>
</table>
<!-- Header spanning all columns -->
<table border="1">
<tr>
<th colspan="3">Employee Information</th>
</tr>
<tr>
<th>Name</th>
<th>Department</th>
<th>Salary</th>
</tr>
<tr>
<td>Alice</td>
<td>HR</td>
<td>$60,000</td>
</tr>
</table>Correct Answer: Makes a cell span across multiple rows
<!-- Cell spanning 2 rows -->
<table border="1">
<tr>
<td rowspan="2">Monday</td>
<td>Morning</td>
<td>Math</td>
</tr>
<tr>
<td>Afternoon</td>
<td>Science</td>
</tr>
</table>
<!-- Category spanning multiple items -->
<table border="1">
<tr>
<td rowspan="3">Fruits</td>
<td>Apple</td>
</tr>
<tr>
<td>Banana</td>
</tr>
<tr>
<td>Orange</td>
</tr>
<tr>
<td rowspan="2">Vegetables</td>
<td>Carrot</td>
</tr>
<tr>
<td>Broccoli</td>
</tr>
</table>Correct Answer: To group header content in a table
<!-- Table with thead -->
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>555-1234</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>jane@example.com</td>
<td>555-5678</td>
</tr>
</tbody>
</table>Correct Answer: <tbody>
<!-- Table with tbody -->
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Laptop</td>
<td>$999</td>
</tr>
<tr>
<td>Mouse</td>
<td>$25</td>
</tr>
<tr>
<td>Keyboard</td>
<td>$75</td>
</tr>
</tbody>
</table>
<!-- Multiple tbody for grouping -->
<table>
<tbody>
<tr>
<td colspan="2"><strong>Q1 Sales</strong></td>
</tr>
<tr>
<td>January</td>
<td>$5,000</td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="2"><strong>Q2 Sales</strong></td>
</tr>
<tr>
<td>April</td>
<td>$6,000</td>
</tr>
</tbody>
</table>Correct Answer: To group footer content like totals or summaries
<!-- Table with tfoot -->
<table>
<thead>
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>10</td>
<td>$20</td>
</tr>
<tr>
<td>Bananas</td>
<td>15</td>
<td>$30</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2">Total</td>
<td>$50</td>
</tr>
</tfoot>
</table>
<!-- Sales report with summary -->
<table>
<thead>
<tr>
<th>Month</th>
<th>Revenue</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$10,000</td>
</tr>
<tr>
<td>February</td>
<td>$12,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th>Total Revenue</th>
<td>$22,000</td>
</tr>
</tfoot>
</table>Correct Answer: border
<!-- Old HTML way (deprecated) -->
<table border="1">
<tr>
<td>Cell 1</td>
<td>Cell 2</td>
</tr>
</table>
<!-- Modern CSS way (recommended) -->
<style>
table {
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid black;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
</table>Correct Answer: To specify whether the header is for a column or row
<!-- Column headers with scope -->
<table>
<tr>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Country</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
<td>USA</td>
</tr>
</table>
<!-- Row headers with scope -->
<table>
<tr>
<th scope="row">Monday</th>
<td>9:00 AM</td>
<td>Meeting</td>
</tr>
<tr>
<th scope="row">Tuesday</th>
<td>2:00 PM</td>
<td>Workshop</td>
</tr>
</table>
<!-- Mixed headers -->
<table>
<tr>
<th></th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
</tr>
<tr>
<th scope="row">Sales</th>
<td>$10k</td>
<td>$12k</td>
</tr>
<tr>
<th scope="row">Profit</th>
<td>$2k</td>
<td>$3k</td>
</tr>
</table><!-- COLSPAN Examples -->
<!-- Header spanning multiple columns -->
<table border="1">
<tr>
<th colspan="3">Employee Information</th>
</tr>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
</tr>
<tr>
<td>John Doe</td>
<td>john@example.com</td>
<td>555-1234</td>
</tr>
</table>
<!-- Summary row with colspan -->
<table border="1">
<tr>
<th>Item</th>
<th>Quantity</th>
<th>Price</th>
</tr>
<tr>
<td>Laptop</td>
<td>2</td>
<td>$2,000</td>
</tr>
<tr>
<td>Mouse</td>
<td>5</td>
<td>$125</td>
</tr>
<tr>
<td colspan="2">Total</td>
<td>$2,125</td>
</tr>
</table>
<!-- ROWSPAN Examples -->
<!-- Category spanning multiple rows -->
<table border="1">
<tr>
<th rowspan="3">Fruits</th>
<td>Apple</td>
<td>$2</td>
</tr>
<tr>
<td>Banana</td>
<td>$1</td>
</tr>
<tr>
<td>Orange</td>
<td>$3</td>
</tr>
<tr>
<th rowspan="2">Vegetables</th>
<td>Carrot</td>
<td>$1.50</td>
</tr>
<tr>
<td>Broccoli</td>
<td>$2.50</td>
</tr>
</table>
<!-- COMBINING colspan and rowspan -->
<table border="1">
<tr>
<th colspan="2" rowspan="2">Schedule</th>
<th>Monday</th>
<th>Tuesday</th>
</tr>
<tr>
<td>Math</td>
<td>Science</td>
</tr>
<tr>
<th rowspan="2">Morning</th>
<th>9-10 AM</th>
<td>Algebra</td>
<td>Physics</td>
</tr>
<tr>
<th>10-11 AM</th>
<td>Geometry</td>
<td>Chemistry</td>
</tr>
</table><!-- Using th for headers, td for data -->
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
<th>City</th>
</tr>
<tr>
<td>John Doe</td>
<td>25</td>
<td>New York</td>
</tr>
<tr>
<td>Jane Smith</td>
<td>30</td>
<td>London</td>
</tr>
</table>
<!-- Row headers using th -->
<table border="1">
<tr>
<th>Product</th>
<td>Laptop</td>
</tr>
<tr>
<th>Price</th>
<td>$999</td>
</tr>
<tr>
<th>Stock</th>
<td>15 units</td>
</tr>
</table>
<!-- Both row and column headers -->
<table border="1">
<tr>
<th></th>
<th scope="col">Q1</th>
<th scope="col">Q2</th>
<th scope="col">Q3</th>
</tr>
<tr>
<th scope="row">Sales</th>
<td>$10,000</td>
<td>$12,000</td>
<td>$15,000</td>
</tr>
<tr>
<th scope="row">Expenses</th>
<td>$8,000</td>
<td>$9,000</td>
<td>$10,000</td>
</tr>
</table>
<!-- BAD: Using td for headers (not accessible) -->
<table border="1">
<tr>
<td><strong>Name</strong></td>
<td><strong>Age</strong></td>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
</table>
<!-- GOOD: Using th for headers (accessible) -->
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
</table><!-- Complete table with all sections -->
<table>
<caption>Quarterly Sales Report 2024</caption>
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Revenue</th>
<th scope="col">Expenses</th>
<th scope="col">Profit</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$10,000</td>
<td>$7,000</td>
<td>$3,000</td>
</tr>
<tr>
<td>February</td>
<td>$12,000</td>
<td>$8,000</td>
<td>$4,000</td>
</tr>
<tr>
<td>March</td>
<td>$15,000</td>
<td>$10,000</td>
<td>$5,000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">Total</th>
<td>$37,000</td>
<td>$25,000</td>
<td>$12,000</td>
</tr>
</tfoot>
</table>
<!-- With CSS styling -->
<style>
table {
width: 100%;
border-collapse: collapse;
}
caption {
font-size: 1.5em;
font-weight: bold;
margin-bottom: 10px;
}
thead {
background-color: #4CAF50;
color: white;
}
tbody tr:nth-child(even) {
background-color: #f2f2f2;
}
tbody tr:hover {
background-color: #ddd;
}
tfoot {
background-color: #333;
color: white;
font-weight: bold;
}
th, td {
padding: 12px;
text-align: left;
border: 1px solid #ddd;
}
</style>
<!-- Multiple tbody sections for grouping -->
<table>
<thead>
<tr>
<th>Product</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2"><strong>Electronics</strong></td>
</tr>
<tr>
<td>Laptop</td>
<td>$999</td>
</tr>
<tr>
<td>Mouse</td>
<td>$25</td>
</tr>
</tbody>
<tbody>
<tr>
<td colspan="2"><strong>Accessories</strong></td>
</tr>
<tr>
<td>Bag</td>
<td>$50</td>
</tr>
<tr>
<td>Cable</td>
<td>$10</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Total Items</td>
<td>4</td>
</tr>
</tfoot>
</table>Correct Answer: <form>
<!-- Basic form structure --> <form action="/submit" method="POST"> <label for="name">Name:</label> <input type="text" id="name" name="name"> <input type="submit" value="Submit"> </form> <!-- Form with multiple inputs --> <form action="/register" method="POST"> <input type="email" name="email" placeholder="Email"> <input type="password" name="password" placeholder="Password"> <button type="submit">Register</button> </form>
Correct Answer: The URL where form data is sent
<!-- Relative URL --> <form action="/process-form" method="POST"> <input type="text" name="username"> <input type="submit"> </form> <!-- Absolute URL --> <form action="https://api.example.com/submit" method="POST"> <input type="email" name="email"> <button type="submit">Submit</button> </form> <!-- Same page submission --> <form action="" method="POST"> <input type="text" name="search"> <input type="submit" value="Search"> </form>
Correct Answer: POST
<!-- POST for sensitive data --> <form action="/login" method="POST"> <input type="email" name="email" required> <input type="password" name="password" required> <button type="submit">Login</button> </form> <!-- GET for search (not sensitive) --> <form action="/search" method="GET"> <input type="text" name="q" placeholder="Search"> <input type="submit" value="Search"> </form> <!-- POST for registration --> <form action="/register" method="POST"> <input type="text" name="username"> <input type="email" name="email"> <input type="password" name="password"> <button type="submit">Create Account</button> </form>
Correct Answer: type="text"
<!-- Basic text input -->
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
</form>
<!-- Text input with attributes -->
<form>
<label for="name">Full Name:</label>
<input type="text"
id="name"
name="fullname"
maxlength="50"
placeholder="Enter your name"
required>
</form>
<!-- Multiple text inputs -->
<form action="/submit" method="POST">
<input type="text" name="firstname" placeholder="First Name">
<input type="text" name="lastname" placeholder="Last Name">
<input type="text" name="city" placeholder="City">
<button type="submit">Submit</button>
</form>Correct Answer: Masks the entered characters
<!-- Basic password input -->
<form action="/login" method="POST">
<label for="password">Password:</label>
<input type="password" id="password" name="password">
</form>
<!-- Login form with email and password -->
<form action="/login" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="pwd">Password:</label>
<input type="password"
id="pwd"
name="password"
minlength="8"
required>
<button type="submit">Login</button>
</form>
<!-- Registration with password confirmation -->
<form action="/register" method="POST">
<input type="password" name="password" placeholder="Password" required>
<input type="password" name="confirm" placeholder="Confirm Password" required>
<button type="submit">Register</button>
</form>Correct Answer: It provides automatic email validation
<!-- Email input with validation -->
<form action="/subscribe" method="POST">
<label for="email">Email Address:</label>
<input type="email"
id="email"
name="email"
placeholder="you@example.com"
required>
<button type="submit">Subscribe</button>
</form>
<!-- Multiple attribute for multiple emails -->
<form>
<label for="emails">Email Addresses:</label>
<input type="email"
id="emails"
name="email"
multiple
placeholder="email1@example.com, email2@example.com">
</form>
<!-- Contact form with email -->
<form action="/contact" method="POST">
<input type="text" name="name" placeholder="Your Name" required>
<input type="email" name="email" placeholder="Your Email" required>
<textarea name="message" placeholder="Message" required></textarea>
<button type="submit">Send Message</button>
</form>Correct Answer: min and max
<!-- Number input with min and max -->
<form>
<label for="age">Age:</label>
<input type="number"
id="age"
name="age"
min="18"
max="100"
required>
</form>
<!-- Quantity selector -->
<form>
<label for="quantity">Quantity:</label>
<input type="number"
id="quantity"
name="qty"
min="1"
max="99"
value="1"
step="1">
</form>
<!-- Price input with decimals -->
<form>
<label for="price">Price:</label>
<input type="number"
id="price"
name="price"
min="0"
step="0.01"
placeholder="0.00">
</form>
<!-- Rating input -->
<form>
<label for="rating">Rating (1-5):</label>
<input type="number"
id="rating"
name="rating"
min="1"
max="5"
step="1"
value="3">
</form>Correct Answer: It displays a numeric keypad on mobile devices
<!-- Basic tel input -->
<form>
<label for="phone">Phone Number:</label>
<input type="tel"
id="phone"
name="phone"
placeholder="(555) 123-4567">
</form>
<!-- Tel with pattern for US format -->
<form>
<label for="phone">Phone (US):</label>
<input type="tel"
id="phone"
name="phone"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
placeholder="123-456-7890"
required>
</form>
<!-- International phone with pattern -->
<form>
<label for="mobile">Mobile:</label>
<input type="tel"
id="mobile"
name="mobile"
pattern="\+?[0-9\s\-\(\)]+"
placeholder="+1 (555) 123-4567">
</form>
<!-- Contact form with tel -->
<form action="/contact" method="POST">
<input type="text" name="name" placeholder="Name" required>
<input type="email" name="email" placeholder="Email" required>
<input type="tel" name="phone" placeholder="Phone Number">
<button type="submit">Contact Me</button>
</form>Correct Answer: Using the for attribute on label and id on input
<!-- Explicit association (recommended) -->
<form>
<label for="username">Username:</label>
<input type="text" id="username" name="username">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
</form>
<!-- Implicit association -->
<form>
<label>
Username:
<input type="text" name="username">
</label>
</form>
<!-- Labels with checkboxes -->
<form>
<label for="terms">
<input type="checkbox" id="terms" name="terms" required>
I agree to the terms and conditions
</label>
</form>
<!-- Complete form with labels -->
<form action="/submit" method="POST">
<div>
<label for="fname">First Name:</label>
<input type="text" id="fname" name="firstname" required>
</div>
<div>
<label for="lname">Last Name:</label>
<input type="text" id="lname" name="lastname" required>
</div>
<button type="submit">Submit</button>
</form>Correct Answer: To identify the input data when submitted to the server
<!-- Inputs with name attributes -->
<form action="/submit" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Submit</button>
</form>
<!-- Server receives: -->
<!-- username=john&email=john@example.com&password=secret123 -->
<!-- Multiple inputs same name (checkboxes) -->
<form>
<label>
<input type="checkbox" name="interests" value="coding">
Coding
</label>
<label>
<input type="checkbox" name="interests" value="design">
Design
</label>
<label>
<input type="checkbox" name="interests" value="marketing">
Marketing
</label>
</form>
<!-- No name = data not sent -->
<form action="/submit" method="POST">
<input type="text" placeholder="This won't be submitted">
<input type="text" name="this_will" placeholder="This will be submitted">
<button type="submit">Submit</button>
</form>Correct Answer: Shows hint text that disappears when user starts typing
<!-- Placeholders with labels -->
<form>
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
placeholder="you@example.com">
<label for="phone">Phone:</label>
<input type="tel"
id="phone"
name="phone"
placeholder="(555) 123-4567">
</form>
<!-- Placeholder as format example -->
<form>
<label for="date">Birth Date:</label>
<input type="text"
id="date"
name="birthdate"
placeholder="MM/DD/YYYY">
</form>
<!-- BAD: Placeholder as only label (accessibility issue) -->
<form>
<input type="text" placeholder="Username">
<input type="password" placeholder="Password">
</form>
<!-- GOOD: Label plus placeholder -->
<form>
<label for="username">Username:</label>
<input type="text"
id="username"
name="username"
placeholder="Choose a unique username">
</form>Correct Answer: Sets the initial or default value
<!-- Pre-filled text input -->
<form>
<label for="country">Country:</label>
<input type="text"
id="country"
name="country"
value="United States">
</form>
<!-- Edit form with values -->
<form action="/update-profile" method="POST">
<input type="text" name="name" value="John Doe">
<input type="email" name="email" value="john@example.com">
<input type="text" name="city" value="New York">
<button type="submit">Update Profile</button>
</form>
<!-- Radio buttons with values -->
<form>
<label>
<input type="radio" name="size" value="small">
Small
</label>
<label>
<input type="radio" name="size" value="medium" checked>
Medium
</label>
<label>
<input type="radio" name="size" value="large">
Large
</label>
</form>
<!-- Hidden input with value -->
<form action="/submit" method="POST">
<input type="hidden" name="user_id" value="12345">
<input type="text" name="feedback">
<button type="submit">Send Feedback</button>
</form>Correct Answer: Prevents form submission if the field is empty
<!-- Required text inputs -->
<form action="/submit" method="POST">
<label for="name">Name (required):</label>
<input type="text"
id="name"
name="name"
required>
<label for="email">Email (required):</label>
<input type="email"
id="email"
name="email"
required>
<label for="message">Message:</label>
<input type="text" id="message" name="message">
<button type="submit">Submit</button>
</form>
<!-- Required checkbox -->
<form>
<label>
<input type="checkbox" name="terms" required>
I agree to the terms (required)
</label>
<button type="submit">Register</button>
</form>
<!-- Mix of required and optional -->
<form>
<input type="text" name="firstname" placeholder="First Name" required>
<input type="text" name="lastname" placeholder="Last Name" required>
<input type="text" name="middlename" placeholder="Middle Name (optional)">
<input type="email" name="email" placeholder="Email" required>
<input type="tel" name="phone" placeholder="Phone (optional)">
<button type="submit">Submit</button>
</form><!-- GET method example (search form) -->
<form action="/search" method="GET">
<label for="query">Search:</label>
<input type="text"
id="query"
name="q"
placeholder="Search terms">
<button type="submit">Search</button>
</form>
<!-- Submits to: /search?q=html+tutorial -->
<!-- URL is bookmarkable and shareable -->
<!-- POST method example (login form) -->
<form action="/login" method="POST">
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
required>
<label for="password">Password:</label>
<input type="password"
id="password"
name="password"
required>
<button type="submit">Login</button>
</form>
<!-- Data sent in request body, not visible in URL -->
<!-- More secure for sensitive information -->
<!-- GET for filtering (appropriate use) -->
<form action="/products" method="GET">
<select name="category">
<option value="">All Categories</option>
<option value="electronics">Electronics</option>
<option value="clothing">Clothing</option>
</select>
<input type="number" name="min_price" placeholder="Min Price">
<input type="number" name="max_price" placeholder="Max Price">
<button type="submit">Filter</button>
</form>
<!-- URL: /products?category=electronics&min_price=100&max_price=500 -->
<!-- User can bookmark this filtered view -->
<!-- POST for data modification (appropriate use) -->
<form action="/register" method="POST">
<input type="text" name="username" placeholder="Username" required>
<input type="email" name="email" placeholder="Email" required>
<input type="password" name="password" placeholder="Password" required>
<input type="password" name="confirm" placeholder="Confirm Password" required>
<button type="submit">Create Account</button>
</form>
<!-- Modifies server data, uses POST -->
<!-- Sensitive password data not in URL --><!-- Names identify data for server -->
<form action="/submit" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Submit</button>
</form>
<!-- Server receives: -->
<!-- username=john&email=john@example.com&password=secret -->
<!-- Without name, data is NOT sent -->
<form action="/submit" method="POST">
<input type="text" placeholder="This has no name">
<input type="text" name="this_has_name" placeholder="This has name">
<button type="submit">Submit</button>
</form>
<!-- Only 'this_has_name' data is sent to server -->
<!-- Radio buttons with same name -->
<form>
<label>
<input type="radio" name="size" value="small">
Small
</label>
<label>
<input type="radio" name="size" value="medium">
Medium
</label>
<label>
<input type="radio" name="size" value="large">
Large
</label>
<button type="submit">Submit</button>
</form>
<!-- Server receives: size=medium (only selected value) -->
<!-- Checkboxes with same name (array) -->
<form>
<label>
<input type="checkbox" name="interests[]" value="coding">
Coding
</label>
<label>
<input type="checkbox" name="interests[]" value="design">
Design
</label>
<label>
<input type="checkbox" name="interests[]" value="marketing">
Marketing
</label>
</form>
<!-- Server receives: interests[]=coding&interests[]=design -->
<!-- (if both are checked) -->
<!-- Name vs ID difference -->
<form action="/submit" method="POST">
<!-- ID for label association and JavaScript -->
<!-- Name for server-side data identification -->
<label for="user_email">Email:</label>
<input type="email"
id="user_email"
name="email"
placeholder="your@email.com">
</form>
<!-- Label links to id="user_email" -->
<!-- Server receives data as name="email" --><!-- Proper label usage (explicit association) -->
<form action="/submit" method="POST">
<div>
<label for="username">Username:</label>
<input type="text"
id="username"
name="username"
required>
</div>
<div>
<label for="email">Email Address:</label>
<input type="email"
id="email"
name="email"
required>
</div>
<div>
<label for="password">Password:</label>
<input type="password"
id="password"
name="password"
minlength="8"
required>
</div>
<button type="submit">Register</button>
</form>
<!-- Label makes checkbox easier to click -->
<form>
<label for="terms">
<input type="checkbox"
id="terms"
name="terms"
required>
I agree to the terms and conditions
</label>
<!-- Clicking the text checks the box -->
</form>
<!-- Radio buttons with labels -->
<form>
<fieldset>
<legend>Select your subscription:</legend>
<label for="basic">
<input type="radio"
id="basic"
name="plan"
value="basic">
Basic Plan ($10/month)
</label>
<label for="pro">
<input type="radio"
id="pro"
name="plan"
value="pro">
Pro Plan ($25/month)
</label>
<label for="enterprise">
<input type="radio"
id="enterprise"
name="plan"
value="enterprise">
Enterprise Plan ($50/month)
</label>
</fieldset>
</form>
<!-- BAD: No labels (accessibility issue) -->
<form>
<input type="text" placeholder="Username">
<input type="email" placeholder="Email">
<input type="password" placeholder="Password">
<button>Submit</button>
</form>
<!-- Screen readers cannot identify these fields properly -->
<!-- GOOD: Labels with placeholders -->
<form>
<label for="user">Username:</label>
<input type="text"
id="user"
name="username"
placeholder="Choose a unique username">
<label for="mail">Email:</label>
<input type="email"
id="mail"
name="email"
placeholder="you@example.com">
</form>
<!-- Accessible AND user-friendly -->
<!-- Implicit association (less preferred) -->
<form>
<label>
Full Name:
<input type="text" name="fullname">
</label>
</form>
<!-- Works but explicit method is clearer -->Correct Answer: type="radio"
<!-- Radio button group -->
<form>
<fieldset>
<legend>Select your gender:</legend>
<label>
<input type="radio" name="gender" value="male">
Male
</label>
<label>
<input type="radio" name="gender" value="female">
Female
</label>
<label>
<input type="radio" name="gender" value="other">
Other
</label>
</fieldset>
</form>
<!-- With default selection -->
<form>
<label>
<input type="radio" name="plan" value="basic">
Basic Plan
</label>
<label>
<input type="radio" name="plan" value="pro" checked>
Pro Plan (Selected by default)
</label>
<label>
<input type="radio" name="plan" value="enterprise">
Enterprise Plan
</label>
</form>Correct Answer: type="checkbox"
<!-- Multiple checkboxes -->
<form>
<fieldset>
<legend>Select your interests:</legend>
<label>
<input type="checkbox" name="interests" value="coding">
Coding
</label>
<label>
<input type="checkbox" name="interests" value="design">
Design
</label>
<label>
<input type="checkbox" name="interests" value="marketing">
Marketing
</label>
<label>
<input type="checkbox" name="interests" value="business">
Business
</label>
</fieldset>
</form>
<!-- Single checkbox for agreement -->
<form>
<label>
<input type="checkbox" name="terms" required>
I agree to the terms and conditions
</label>
<label>
<input type="checkbox" name="newsletter">
Subscribe to newsletter (optional)
</label>
</form>Correct Answer: <select>
<!-- Basic dropdown -->
<form>
<label for="country">Country:</label>
<select id="country" name="country">
<option value="">Select a country</option>
<option value="us">United States</option>
<option value="uk">United Kingdom</option>
<option value="ca">Canada</option>
<option value="au">Australia</option>
</select>
</form>
<!-- Dropdown with default selection -->
<form>
<label for="month">Birth Month:</label>
<select id="month" name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4" selected>April</option>
<option value="5">May</option>
</select>
</form>
<!-- Multiple selection dropdown -->
<form>
<label for="languages">Programming Languages:</label>
<select id="languages" name="languages" multiple size="4">
<option value="python">Python</option>
<option value="javascript">JavaScript</option>
<option value="java">Java</option>
<option value="cpp">C++</option>
</select>
</form>Correct Answer: To organize options into categories within a dropdown
<!-- Dropdown with grouped options -->
<form>
<label for="location">Choose location:</label>
<select id="location" name="location">
<optgroup label="North America">
<option value="us">United States</option>
<option value="ca">Canada</option>
<option value="mx">Mexico</option>
</optgroup>
<optgroup label="Europe">
<option value="uk">United Kingdom</option>
<option value="de">Germany</option>
<option value="fr">France</option>
</optgroup>
<optgroup label="Asia">
<option value="in">India</option>
<option value="jp">Japan</option>
<option value="cn">China</option>
</optgroup>
</select>
</form>
<!-- Product categories -->
<form>
<label for="product">Select Product:</label>
<select id="product" name="product">
<optgroup label="Electronics">
<option value="laptop">Laptop</option>
<option value="phone">Phone</option>
<option value="tablet">Tablet</option>
</optgroup>
<optgroup label="Clothing">
<option value="shirt">Shirt</option>
<option value="pants">Pants</option>
<option value="shoes">Shoes</option>
</optgroup>
</select>
</form>Correct Answer: <textarea>
<!-- Basic textarea -->
<form>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4" cols="50"></textarea>
</form>
<!-- Textarea with placeholder and max length -->
<form>
<label for="bio">Tell us about yourself:</label>
<textarea id="bio"
name="biography"
rows="5"
maxlength="500"
placeholder="Write your bio here (max 500 characters)"
required></textarea>
</form>
<!-- Textarea with default content -->
<form>
<label for="address">Address:</label>
<textarea id="address" name="address" rows="3">
123 Main Street
City, State 12345
Country
</textarea>
</form>
<!-- Comment box -->
<form>
<label for="comment">Leave a comment:</label>
<textarea id="comment"
name="comment"
rows="6"
placeholder="Share your thoughts..."
required></textarea>
<button type="submit">Post Comment</button>
</form>Correct Answer: type="file"
<!-- Basic file upload -->
<form action="/upload" method="POST" enctype="multipart/form-data">
<label for="file">Choose a file:</label>
<input type="file" id="file" name="document">
<button type="submit">Upload</button>
</form>
<!-- Image upload with accept -->
<form action="/upload-avatar" method="POST" enctype="multipart/form-data">
<label for="avatar">Profile Picture:</label>
<input type="file"
id="avatar"
name="avatar"
accept="image/*"
required>
<button type="submit">Upload Photo</button>
</form>
<!-- Multiple file upload -->
<form action="/upload-documents" method="POST" enctype="multipart/form-data">
<label for="files">Upload Documents:</label>
<input type="file"
id="files"
name="documents"
accept=".pdf,.doc,.docx"
multiple>
<button type="submit">Upload Files</button>
</form>
<!-- Resume upload -->
<form action="/submit-application" method="POST" enctype="multipart/form-data">
<label for="resume">Resume:</label>
<input type="file"
id="resume"
name="resume"
accept=".pdf,.doc,.docx"
required>
<button type="submit">Submit Application</button>
</form>Correct Answer: type="date"
<!-- Basic date input -->
<form>
<label for="birthday">Date of Birth:</label>
<input type="date" id="birthday" name="birthday" required>
</form>
<!-- Date with min and max -->
<form>
<label for="appointment">Select Appointment Date:</label>
<input type="date"
id="appointment"
name="appointment"
min="2024-01-01"
max="2024-12-31"
required>
</form>
<!-- Date range -->
<form>
<label for="start">Start Date:</label>
<input type="date" id="start" name="start_date">
<label for="end">End Date:</label>
<input type="date" id="end" name="end_date">
</form>
<!-- Event registration with date -->
<form>
<label for="event-date">Event Date:</label>
<input type="date"
id="event-date"
name="event_date"
value="2024-06-15"
required>
</form>Correct Answer: A slider control for selecting values
<!-- Basic range slider -->
<form>
<label for="volume">Volume:</label>
<input type="range"
id="volume"
name="volume"
min="0"
max="100"
value="50">
</form>
<!-- Price range filter -->
<form>
<label for="price">Maximum Price: $<span id="price-value">500</span></label>
<input type="range"
id="price"
name="max_price"
min="0"
max="1000"
step="50"
value="500">
</form>
<!-- Age selector -->
<form>
<label for="age">Age: <span id="age-display">25</span></label>
<input type="range"
id="age"
name="age"
min="18"
max="100"
value="25">
</form>
<!-- Rating slider -->
<form>
<label for="rating">Rate this product (1-5):</label>
<input type="range"
id="rating"
name="rating"
min="1"
max="5"
step="1"
value="3">
</form>Correct Answer: A color picker interface
<!-- Basic color picker -->
<form>
<label for="favcolor">Choose your favorite color:</label>
<input type="color"
id="favcolor"
name="favcolor"
value="#ff0000">
</form>
<!-- Theme customization -->
<form>
<label for="theme">Primary Color:</label>
<input type="color"
id="theme"
name="primary_color"
value="#007bff">
<label for="secondary">Secondary Color:</label>
<input type="color"
id="secondary"
name="secondary_color"
value="#6c757d">
</form>
<!-- Background color selector -->
<form>
<label for="bgcolor">Background Color:</label>
<input type="color"
id="bgcolor"
name="background_color"
value="#ffffff">
<button type="submit">Apply Color</button>
</form>Correct Answer: To store and send data without displaying it to users
<!-- Hidden input with user ID --> <form action="/update-profile" method="POST"> <input type="hidden" name="user_id" value="12345"> <label for="name">Name:</label> <input type="text" id="name" name="name" value="John Doe"> <label for="email">Email:</label> <input type="email" id="email" name="email" value="john@example.com"> <button type="submit">Update Profile</button> </form> <!-- Hidden timestamp --> <form action="/submit" method="POST"> <input type="hidden" name="timestamp" value="1640000000"> <input type="hidden" name="form_version" value="2.1"> <input type="text" name="feedback" placeholder="Your feedback"> <button type="submit">Submit</button> </form> <!-- CSRF token (security) --> <form action="/delete-account" method="POST"> <input type="hidden" name="csrf_token" value="abc123xyz789"> <p>Are you sure you want to delete your account?</p> <button type="submit">Confirm Delete</button> </form>
Correct Answer: type="submit"
<!-- Submit button using input -->
<form action="/submit" method="POST">
<input type="text" name="username" placeholder="Username">
<input type="submit" value="Submit">
</form>
<!-- Submit button using button element -->
<form action="/register" method="POST">
<input type="email" name="email" placeholder="Email">
<input type="password" name="password" placeholder="Password">
<button type="submit">Create Account</button>
</form>
<!-- Multiple submit buttons -->
<form action="/save" method="POST">
<textarea name="content"></textarea>
<button type="submit" name="action" value="draft">Save as Draft</button>
<button type="submit" name="action" value="publish">Publish</button>
</form>
<!-- Submit with icon -->
<form action="/search" method="GET">
<input type="text" name="q" placeholder="Search...">
<button type="submit">
🔍 Search
</button>
</form>Correct Answer: Clears all form fields to their default values
<!-- Reset button using input --> <form> <input type="text" name="firstname" value="John"> <input type="text" name="lastname" value="Doe"> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> <!-- Clicking Reset returns firstname to "John" and lastname to "Doe" --> <!-- Reset button using button element --> <form> <input type="email" name="email" placeholder="Email"> <textarea name="message"></textarea> <button type="submit">Send</button> <button type="reset">Clear Form</button> </form> <!-- Modern alternative: No reset button --> <form> <input type="text" name="name" placeholder="Name"> <input type="email" name="email" placeholder="Email"> <button type="submit">Submit</button> <!-- No reset button - users can manually clear if needed --> </form>
<!-- RADIO BUTTONS (single selection) -->
<form>
<fieldset>
<legend>Choose your payment method:</legend>
<label>
<input type="radio" name="payment" value="credit" checked>
Credit Card
</label>
<label>
<input type="radio" name="payment" value="debit">
Debit Card
</label>
<label>
<input type="radio" name="payment" value="paypal">
PayPal
</label>
</fieldset>
<!-- Only ONE payment method can be selected -->
<!-- Server receives: payment=credit -->
</form>
<!-- CHECKBOXES (multiple selections) -->
<form>
<fieldset>
<legend>Select your interests:</legend>
<label>
<input type="checkbox" name="interests" value="coding">
Coding
</label>
<label>
<input type="checkbox" name="interests" value="design">
Design
</label>
<label>
<input type="checkbox" name="interests" value="marketing">
Marketing
</label>
<label>
<input type="checkbox" name="interests" value="business">
Business
</label>
</fieldset>
<!-- Multiple interests can be selected -->
<!-- Server receives: interests=coding&interests=design&interests=business -->
</form>
<!-- COMPARISON EXAMPLE -->
<form>
<!-- Radio: Choose ONE size -->
<fieldset>
<legend>T-Shirt Size:</legend>
<label><input type="radio" name="size" value="S"> Small</label>
<label><input type="radio" name="size" value="M"> Medium</label>
<label><input type="radio" name="size" value="L"> Large</label>
</fieldset>
<!-- Checkboxes: Choose MULTIPLE toppings -->
<fieldset>
<legend>Pizza Toppings:</legend>
<label><input type="checkbox" name="toppings" value="cheese"> Cheese</label>
<label><input type="checkbox" name="toppings" value="pepperoni"> Pepperoni</label>
<label><input type="checkbox" name="toppings" value="mushrooms"> Mushrooms</label>
<label><input type="checkbox" name="toppings" value="olives"> Olives</label>
</fieldset>
</form><!-- Countries grouped by continent -->
<form>
<label for="country">Select your country:</label>
<select id="country" name="country" required>
<option value="">-- Choose a country --</option>
<optgroup label="North America">
<option value="us">United States</option>
<option value="ca">Canada</option>
<option value="mx">Mexico</option>
</optgroup>
<optgroup label="Europe">
<option value="uk">United Kingdom</option>
<option value="de">Germany</option>
<option value="fr">France</option>
<option value="es">Spain</option>
<option value="it">Italy</option>
</optgroup>
<optgroup label="Asia">
<option value="in">India</option>
<option value="cn">China</option>
<option value="jp">Japan</option>
<option value="sg">Singapore</option>
</optgroup>
<optgroup label="Oceania">
<option value="au">Australia</option>
<option value="nz">New Zealand</option>
</optgroup>
</select>
</form>
<!-- Products grouped by category -->
<form>
<label for="product">Choose a product:</label>
<select id="product" name="product">
<option value="">-- Select product --</option>
<optgroup label="Electronics">
<option value="laptop">Laptop</option>
<option value="phone">Smartphone</option>
<option value="tablet">Tablet</option>
<option value="headphones">Headphones</option>
</optgroup>
<optgroup label="Clothing">
<option value="shirt">T-Shirt</option>
<option value="jeans">Jeans</option>
<option value="jacket">Jacket</option>
<option value="shoes">Shoes</option>
</optgroup>
<optgroup label="Home & Kitchen">
<option value="cookware">Cookware</option>
<option value="furniture">Furniture</option>
<option value="decor">Home Decor</option>
</optgroup>
</select>
<button type="submit">Add to Cart</button>
</form>
<!-- Programming languages by type -->
<form>
<label for="language">Select language:</label>
<select id="language" name="language">
<option value="">-- Choose language --</option>
<optgroup label="Frontend">
<option value="html">HTML</option>
<option value="css">CSS</option>
<option value="js">JavaScript</option>
<option value="ts">TypeScript</option>
</optgroup>
<optgroup label="Backend">
<option value="python">Python</option>
<option value="java">Java</option>
<option value="node">Node.js</option>
<option value="php">PHP</option>
</optgroup>
<optgroup label="Mobile">
<option value="swift">Swift</option>
<option value="kotlin">Kotlin</option>
<option value="flutter">Flutter</option>
</optgroup>
</select>
</form><!-- SUBMIT BUTTON (submits form) --> <form action="/register" method="POST"> <input type="text" name="username" placeholder="Username"> <input type="email" name="email" placeholder="Email"> <!-- Using input element --> <input type="submit" value="Create Account"> <!-- Using button element (more flexible) --> <button type="submit">Create Account with Icon 🚀</button> </form> <!-- RESET BUTTON (clears form) --> <form> <input type="text" name="name" value="John Doe"> <input type="email" name="email" value="john@example.com"> <!-- Clicking reset returns fields to default values --> <input type="reset" value="Clear Form"> <button type="reset">Reset All Fields</button> </form> <!-- BUTTON TYPE (no default action) --> <form> <input type="text" id="quantity" name="quantity" value="1"> <input type="text" id="price" name="price" value="10"> <input type="text" id="total" name="total" readonly> <!-- Button that calculates without submitting --> <button type="button" onclick="calculateTotal()">Calculate Total</button> <!-- Button that adds fields without submitting --> <button type="button" onclick="addField()">Add Another Item</button> <!-- Submit button at the end --> <button type="submit">Place Order</button> </form> <!-- MULTIPLE SUBMIT BUTTONS --> <form action="/save-article" method="POST"> <input type="text" name="title" placeholder="Article Title"> <textarea name="content" placeholder="Article content"></textarea> <!-- Different submit buttons with different actions --> <button type="submit" name="action" value="draft">Save as Draft</button> <button type="submit" name="action" value="publish">Publish Now</button> <button type="submit" name="action" value="schedule">Schedule Publication</button> </form> <!-- REAL-WORLD EXAMPLE --> <form action="/checkout" method="POST"> <input type="text" name="cardnumber" placeholder="Card Number"> <input type="text" name="cvv" placeholder="CVV"> <!-- Button to validate card (doesn't submit) --> <button type="button" onclick="validateCard()">Validate Card</button> <!-- Button to apply coupon (doesn't submit) --> <button type="button" onclick="applyCoupon()">Apply Coupon</button> <!-- Clear button (less common, but better than reset) --> <button type="button" onclick="confirmClear()">Clear Form</button> <!-- Final submit --> <button type="submit">Complete Purchase</button> </form>
Correct Answer: required
<!-- Required text input -->
<form>
<label for="name">Name (required):</label>
<input type="text"
id="name"
name="name"
required>
<button type="submit">Submit</button>
</form>
<!-- Required email -->
<form>
<input type="email"
name="email"
placeholder="Email"
required>
<button type="submit">Subscribe</button>
</form>
<!-- Required checkbox -->
<form>
<label>
<input type="checkbox"
name="terms"
required>
I agree to terms (required)
</label>
<button type="submit">Register</button>
</form>
<!-- Required select -->
<form>
<select name="country" required>
<option value="">Choose country</option>
<option value="us">USA</option>
<option value="uk">UK</option>
</select>
<button type="submit">Continue</button>
</form>Correct Answer: pattern
<!-- US phone number pattern -->
<form>
<label for="phone">Phone (XXX-XXX-XXXX):</label>
<input type="tel"
id="phone"
name="phone"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
title="Format: 123-456-7890"
required>
</form>
<!-- Zip code pattern -->
<form>
<label for="zip">ZIP Code:</label>
<input type="text"
id="zip"
name="zip"
pattern="[0-9]{5}"
title="5-digit ZIP code"
required>
</form>
<!-- Username pattern (letters and numbers only) -->
<form>
<label for="username">Username:</label>
<input type="text"
id="username"
name="username"
pattern="[A-Za-z0-9]+"
title="Only letters and numbers allowed"
minlength="3"
required>
</form>
<!-- Custom format pattern -->
<form>
<label for="code">Product Code (ABC-123):</label>
<input type="text"
id="code"
name="code"
pattern="[A-Z]{3}-[0-9]{3}"
title="Format: ABC-123"
required>
</form>Correct Answer: min and max
<!-- Age with min and max -->
<form>
<label for="age">Age (18-100):</label>
<input type="number"
id="age"
name="age"
min="18"
max="100"
required>
</form>
<!-- Date range -->
<form>
<label for="appointment">Appointment Date:</label>
<input type="date"
id="appointment"
name="date"
min="2024-01-01"
max="2024-12-31"
required>
</form>
<!-- Quantity selector -->
<form>
<label for="qty">Quantity (1-10):</label>
<input type="number"
id="qty"
name="quantity"
min="1"
max="10"
value="1"
required>
</form>
<!-- Price range -->
<form>
<label for="price">Price ($10-$1000):</label>
<input type="number"
id="price"
name="price"
min="10"
max="1000"
step="0.01"
required>
</form>Correct Answer: maxlength
<!-- Username with maxlength -->
<form>
<label for="username">Username (max 15 chars):</label>
<input type="text"
id="username"
name="username"
maxlength="15"
required>
</form>
<!-- Tweet-like input -->
<form>
<label for="tweet">Message (max 280 chars):</label>
<textarea id="tweet"
name="message"
maxlength="280"
rows="4"></textarea>
<p id="char-count">0 / 280</p>
</form>
<!-- Password with min and max length -->
<form>
<label for="password">Password:</label>
<input type="password"
id="password"
name="password"
minlength="8"
maxlength="50"
required>
<small>8-50 characters required</small>
</form>
<!-- Phone number -->
<form>
<label for="phone">Phone (10 digits):</label>
<input type="tel"
id="phone"
name="phone"
maxlength="10"
pattern="[0-9]{10}"
required>
</form>Correct Answer: Prevents editing but allows form submission
<!-- Readonly input with pre-filled data -->
<form action="/update-profile" method="POST">
<label for="userid">User ID:</label>
<input type="text"
id="userid"
name="user_id"
value="12345"
readonly>
<label for="email">Email (can edit):</label>
<input type="email"
id="email"
name="email"
value="john@example.com">
<button type="submit">Update</button>
</form>
<!-- User ID is readonly but will be submitted -->
<!-- Order summary with readonly totals -->
<form>
<label for="subtotal">Subtotal:</label>
<input type="text"
id="subtotal"
name="subtotal"
value="$100.00"
readonly>
<label for="tax">Tax:</label>
<input type="text"
id="tax"
name="tax"
value="$10.00"
readonly>
<label for="total">Total:</label>
<input type="text"
id="total"
name="total"
value="$110.00"
readonly>
</form>Correct Answer: Its value is not sent to the server
<!-- Disabled input (value NOT submitted) -->
<form action="/submit" method="POST">
<label for="name">Name:</label>
<input type="text"
id="name"
name="name"
value="John Doe">
<label for="inactive">Inactive Field:</label>
<input type="text"
id="inactive"
name="inactive_field"
value="This will NOT be submitted"
disabled>
<button type="submit">Submit</button>
</form>
<!-- Only "name" will be submitted, "inactive_field" is ignored -->
<!-- Conditional disabling -->
<form>
<label>
<input type="checkbox"
id="shipping"
name="same_address"
onchange="toggleShipping()">
Shipping same as billing
</label>
<input type="text"
id="ship-address"
name="shipping_address"
placeholder="Shipping Address"
disabled>
</form>
<!-- Disabled submit button -->
<form>
<input type="email"
name="email"
required>
<button type="submit" disabled id="submit-btn">
Submit (Fill all fields first)
</button>
</form>Correct Answer: Focuses the input when the page loads
<!-- Search box with autofocus -->
<form action="/search" method="GET">
<label for="search">Search:</label>
<input type="text"
id="search"
name="q"
autofocus>
<button type="submit">Search</button>
</form>
<!-- Cursor automatically appears in search box -->
<!-- Login form with autofocus on username -->
<form action="/login" method="POST">
<label for="username">Username:</label>
<input type="text"
id="username"
name="username"
autofocus
required>
<label for="password">Password:</label>
<input type="password"
id="password"
name="password"
required>
<button type="submit">Login</button>
</form>
<!-- Modal dialog with autofocus -->
<dialog>
<form method="dialog">
<label for="confirm">Are you sure?</label>
<button type="submit" value="yes" autofocus>Yes</button>
<button type="submit" value="no">No</button>
</form>
</dialog>Correct Answer: Disables browser auto-fill suggestions
<!-- Disable autocomplete for sensitive field -->
<form>
<label for="credit-card">Credit Card:</label>
<input type="text"
id="credit-card"
name="cc"
autocomplete="off"
required>
<label for="cvv">CVV:</label>
<input type="text"
id="cvv"
name="cvv"
autocomplete="off"
maxlength="3"
required>
</form>
<!-- Enable autocomplete with hints -->
<form autocomplete="on">
<label for="name">Full Name:</label>
<input type="text"
id="name"
name="name"
autocomplete="name"
required>
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
autocomplete="email"
required>
<label for="tel">Phone:</label>
<input type="tel"
id="tel"
name="phone"
autocomplete="tel"
required>
</form>
<!-- New password (no suggestions) -->
<form>
<label for="new-pass">New Password:</label>
<input type="password"
id="new-pass"
name="password"
autocomplete="new-password"
required>
</form>Correct Answer: Disables HTML5 form validation
<!-- Form without validation -->
<form action="/submit" method="POST" novalidate>
<input type="email"
name="email"
required>
<!-- Required is ignored, form submits without checking -->
<input type="number"
name="age"
min="18"
required>
<!-- Min and required are ignored -->
<button type="submit">Submit</button>
</form>
<!-- Different buttons with different validation -->
<form action="/save" method="POST">
<input type="text"
name="title"
required>
<textarea name="content"
required></textarea>
<!-- Save draft without validation -->
<button type="submit"
name="action"
value="draft"
formnovalidate>
Save Draft
</button>
<!-- Publish with validation -->
<button type="submit"
name="action"
value="publish">
Publish
</button>
</form>Correct Answer: Overrides the form's action URL for that specific button
<!-- Multiple submit buttons with different actions -->
<form action="/default" method="POST">
<input type="text" name="data" required>
<!-- Submit to /save -->
<button type="submit"
formaction="/save">
Save
</button>
<!-- Submit to /delete -->
<button type="submit"
formaction="/delete"
formmethod="DELETE">
Delete
</button>
<!-- Submit to /archive -->
<button type="submit"
formaction="/archive">
Archive
</button>
</form>
<!-- Article editor with multiple actions -->
<form action="/articles" method="POST">
<input type="text" name="title" placeholder="Title" required>
<textarea name="content" required></textarea>
<button type="submit"
formaction="/articles/draft">
Save Draft
</button>
<button type="submit"
formaction="/articles/publish">
Publish
</button>
<button type="submit"
formaction="/articles/preview"
formmethod="GET"
formtarget="_blank">
Preview
</button>
</form><!-- EMAIL VALIDATION -->
<form>
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
required>
<!-- Validates email format automatically -->
<button type="submit">Subscribe</button>
</form>
<!-- PATTERN VALIDATION -->
<form>
<label for="phone">Phone (XXX-XXX-XXXX):</label>
<input type="tel"
id="phone"
name="phone"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
title="Format: 123-456-7890"
required>
<button type="submit">Submit</button>
</form>
<!-- MIN/MAX VALIDATION -->
<form>
<label for="age">Age (18-100):</label>
<input type="number"
id="age"
name="age"
min="18"
max="100"
required>
<label for="date">Appointment (next 30 days):</label>
<input type="date"
id="date"
name="date"
min="2024-01-01"
max="2024-01-31"
required>
<button type="submit">Book</button>
</form>
<!-- LENGTH VALIDATION -->
<form>
<label for="username">Username (3-15 chars):</label>
<input type="text"
id="username"
name="username"
minlength="3"
maxlength="15"
pattern="[A-Za-z0-9]+"
title="Letters and numbers only"
required>
<label for="password">Password (8+ chars):</label>
<input type="password"
id="password"
name="password"
minlength="8"
required>
<button type="submit">Register</button>
</form>
<!-- COMPREHENSIVE VALIDATION EXAMPLE -->
<form action="/register" method="POST">
<!-- Required text with pattern -->
<label for="user">Username:</label>
<input type="text"
id="user"
name="username"
pattern="[A-Za-z0-9_]{3,15}"
title="3-15 characters, letters, numbers, underscore only"
required>
<!-- Email validation -->
<label for="mail">Email:</label>
<input type="email"
id="mail"
name="email"
required>
<!-- URL validation -->
<label for="website">Website:</label>
<input type="url"
id="website"
name="website"
placeholder="https://example.com">
<!-- Number with range -->
<label for="years">Years of Experience:</label>
<input type="number"
id="years"
name="experience"
min="0"
max="50"
required>
<!-- Password with length -->
<label for="pwd">Password:</label>
<input type="password"
id="pwd"
name="password"
minlength="8"
maxlength="50"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
title="Must contain at least one number, one uppercase and lowercase letter, and at least 8 characters"
required>
<!-- Required checkbox -->
<label>
<input type="checkbox"
name="terms"
required>
I agree to terms
</label>
<button type="submit">Register</button>
</form><!-- READONLY EXAMPLES -->
<form action="/update" method="POST">
<!-- Readonly: Value IS submitted -->
<label for="orderid">Order ID:</label>
<input type="text"
id="orderid"
name="order_id"
value="ORD-12345"
readonly>
<!-- User can see and copy, but not edit -->
<!-- Value "ORD-12345" will be sent to server -->
<label for="email">Email:</label>
<input type="email"
id="email"
name="email"
value="john@example.com">
<!-- This CAN be edited -->
<button type="submit">Update</button>
</form>
<!-- DISABLED EXAMPLES -->
<form action="/submit" method="POST">
<!-- Disabled: Value is NOT submitted -->
<label for="inactive">Inactive Field:</label>
<input type="text"
id="inactive"
name="inactive_field"
value="This will NOT be sent"
disabled>
<!-- Field appears grayed out -->
<!-- Value will NOT be sent to server -->
<label for="name">Name:</label>
<input type="text"
id="name"
name="name"
value="John Doe">
<!-- This will be sent -->
<button type="submit">Submit</button>
</form>
<!-- Server only receives name=John Doe -->
<!-- inactive_field is completely ignored -->
<!-- PRACTICAL COMPARISON -->
<form action="/checkout" method="POST">
<!-- Readonly subtotal (calculated, needs to submit) -->
<label for="subtotal">Subtotal:</label>
<input type="text"
id="subtotal"
name="subtotal"
value="$100.00"
readonly>
<!-- Readonly: shown and submitted -->
<!-- Disabled shipping (not needed if same as billing) -->
<label>
<input type="checkbox"
id="same-address"
onchange="toggleShipping()">
Shipping same as billing
</label>
<input type="text"
id="shipping"
name="shipping_address"
placeholder="Shipping Address"
disabled>
<!-- Disabled: completely removed from submission -->
<button type="submit">Complete Purchase</button>
</form>
<!-- CONDITIONAL ENABLING -->
<form>
<label>
<input type="radio"
name="account_type"
value="personal"
checked
onchange="updateFields()">
Personal
</label>
<label>
<input type="radio"
name="account_type"
value="business"
onchange="updateFields()">
Business
</label>
<!-- Disabled when Personal is selected -->
<input type="text"
id="company"
name="company_name"
placeholder="Company Name"
disabled>
<!-- Always readonly -->
<input type="text"
name="user_id"
value="USR-789"
readonly>
</form><!-- US PHONE NUMBER -->
<form>
<label for="phone">Phone Number:</label>
<input type="tel"
id="phone"
name="phone"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
title="Format: 123-456-7890"
placeholder="123-456-7890"
required>
<button type="submit">Submit</button>
</form>
<!-- USERNAME (alphanumeric + underscore, 3-15 chars) -->
<form>
<label for="username">Username:</label>
<input type="text"
id="username"
name="username"
pattern="[A-Za-z0-9_]{3,15}"
title="3-15 characters: letters, numbers, underscore only"
required>
</form>
<!-- ZIP CODE (5 or 9 digits) -->
<form>
<label for="zip">ZIP Code:</label>
<input type="text"
id="zip"
name="zip"
pattern="[0-9]{5}(-[0-9]{4})?"
title="5 digits or 5+4 format (12345 or 12345-6789)"
placeholder="12345 or 12345-6789"
required>
</form>
<!-- PASSWORD (min 8 chars, 1 uppercase, 1 lowercase, 1 number) -->
<form>
<label for="password">Password:</label>
<input type="password"
id="password"
name="password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
title="At least 8 characters with 1 uppercase, 1 lowercase, and 1 number"
minlength="8"
required>
</form>
<!-- EMAIL (custom pattern) -->
<form>
<label for="email">Work Email:</label>
<input type="text"
id="email"
name="email"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
title="Valid email address"
required>
</form>
<!-- CREDIT CARD (16 digits) -->
<form>
<label for="cc">Credit Card:</label>
<input type="text"
id="cc"
name="card"
pattern="[0-9]{16}"
title="16-digit card number"
placeholder="1234567890123456"
maxlength="16"
required>
</form>
<!-- PRODUCT CODE (format: ABC-123) -->
<form>
<label for="code">Product Code:</label>
<input type="text"
id="code"
name="product_code"
pattern="[A-Z]{3}-[0-9]{3}"
title="Format: ABC-123 (3 uppercase letters, hyphen, 3 digits)"
placeholder="ABC-123"
required>
</form>
<!-- HEX COLOR -->
<form>
<label for="color">Color Code:</label>
<input type="text"
id="color"
name="color"
pattern="#[0-9A-Fa-f]{6}"
title="Hex color code (e.g., #FF5733)"
placeholder="#FF5733"
maxlength="7"
required>
</form>
<!-- COMPREHENSIVE REGISTRATION FORM -->
<form action="/register" method="POST">
<!-- Username pattern -->
<input type="text"
name="username"
pattern="[A-Za-z0-9_]{3,15}"
title="3-15 characters"
required>
<!-- Email (using type=email + pattern) -->
<input type="email"
name="email"
pattern="[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$"
title="Valid email"
required>
<!-- Phone pattern -->
<input type="tel"
name="phone"
pattern="[0-9]{3}-[0-9]{3}-[0-9]{4}"
title="123-456-7890"
required>
<!-- Strong password pattern -->
<input type="password"
name="password"
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*]).{8,}"
title="Min 8 chars with uppercase, lowercase, number, special char"
required>
<button type="submit">Register</button>
</form>Correct Answer: Elements whose names clearly describe their meaning and purpose
<!-- Semantic HTML (clear meaning) -->
<header>
<h1>Website Title</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<article>
<h2>Article Title</h2>
<p>Article content...</p>
</article>
</main>
<footer>
<p>© 2024 Company</p>
</footer>
<!-- Non-semantic (no clear meaning) -->
<div class="header">
<div class="title">Website Title</div>
<div class="navigation">
<a href="/">Home</a>
</div>
</div>Correct Answer: For introductory content or navigational links
<!-- Page header -->
<header>
<img src="logo.png" alt="Company Logo">
<h1>My Website</h1>
<nav>
<a href="/">Home</a>
<a href="/about">About</a>
<a href="/contact">Contact</a>
</nav>
</header>
<!-- Article header -->
<article>
<header>
<h2>Article Title</h2>
<p>By John Doe | Published: Jan 15, 2024</p>
</header>
<p>Article content...</p>
</article>
<!-- Section header -->
<section>
<header>
<h2>Section Title</h2>
<p>Introduction to this section</p>
</header>
<p>Section content...</p>
</section>Correct Answer: To define a section of navigation links
<!-- Main navigation -->
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/products">Products</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>
<!-- Breadcrumb navigation -->
<nav aria-label="Breadcrumb">
<a href="/">Home</a> >
<a href="/products">Products</a> >
<span>Laptop</span>
</nav>
<!-- Table of contents -->
<nav aria-label="Table of Contents">
<h2>Contents</h2>
<ul>
<li><a href="#intro">Introduction</a></li>
<li><a href="#methods">Methods</a></li>
<li><a href="#results">Results</a></li>
</ul>
</nav>Correct Answer: Only one visible main element
<!-- Correct usage: one main -->
<!DOCTYPE html>
<html>
<head><title>Page Title</title></head>
<body>
<header>
<h1>Site Header</h1>
<nav>Navigation</nav>
</header>
<main>
<h2>Main Content</h2>
<p>This is the primary content...</p>
<article>
<h3>Article Title</h3>
<p>Article content...</p>
</article>
</main>
<aside>Sidebar content</aside>
<footer>Footer content</footer>
</body>
</html>
<!-- Skip to main content link -->
<a href="#main-content" class="skip-link">
Skip to main content
</a>
<header>Header...</header>
<nav>Navigation...</nav>
<main id="main-content">
<!-- Main content here -->
</main>Correct Answer: Content that is self-contained and independently distributable
<!-- Blog post article -->
<article>
<header>
<h2>Understanding Semantic HTML</h2>
<p>By Jane Smith | Published: Jan 15, 2024</p>
</header>
<p>Semantic HTML is important because...</p>
<p>More content...</p>
<footer>
<p>Tags: HTML, Web Development</p>
</footer>
</article>
<!-- News article -->
<article>
<h2>Tech Company Launches New Product</h2>
<p>Date: January 15, 2024</p>
<p>Article content...</p>
</article>
<!-- Product card -->
<article class="product-card">
<img src="laptop.jpg" alt="Laptop">
<h3>Professional Laptop</h3>
<p>$999</p>
<button>Add to Cart</button>
</article>
<!-- Blog post with comments (nested articles) -->
<article>
<h2>Main Blog Post</h2>
<p>Post content...</p>
<section>
<h3>Comments</h3>
<article>
<p>Comment by User1...</p>
</article>
<article>
<p>Comment by User2...</p>
</article>
</section>
</article>Correct Answer: When you need a thematic grouping with a heading
<!-- Appropriate section usage -->
<article>
<h1>Complete Guide to HTML</h1>
<section>
<h2>Introduction</h2>
<p>HTML is...</p>
</section>
<section>
<h2>Basic Tags</h2>
<p>The basic tags include...</p>
</section>
<section>
<h2>Advanced Concepts</h2>
<p>Advanced HTML includes...</p>
</section>
</article>
<!-- Use div when no semantic meaning -->
<div class="container">
<!-- Just for styling/layout -->
<div class="row">
<div class="column">Content</div>
</div>
</div>
<!-- Sections with clear themes -->
<main>
<section>
<h2>Features</h2>
<p>Our product features...</p>
</section>
<section>
<h2>Pricing</h2>
<p>Our pricing plans...</p>
</section>
<section>
<h2>Testimonials</h2>
<p>What customers say...</p>
</section>
</main>Correct Answer: Content tangentially related to surrounding content
<!-- Sidebar aside -->
<main>
<article>
<h2>Main Article</h2>
<p>Article content...</p>
</article>
<aside>
<h3>Related Articles</h3>
<ul>
<li><a href="#">Related Post 1</a></li>
<li><a href="#">Related Post 2</a></li>
</ul>
</aside>
</main>
<!-- Aside within article -->
<article>
<h2>Understanding JavaScript</h2>
<p>JavaScript is a programming language...</p>
<aside>
<h3>Did you know?</h3>
<p>JavaScript was created in just 10 days!</p>
</aside>
<p>More content...</p>
</article>
<!-- Pull quote aside -->
<article>
<p>Content before quote...</p>
<aside>
<blockquote>
"Semantic HTML makes the web better for everyone."
</blockquote>
</aside>
<p>Content after quote...</p>
</article>Correct Answer: Author info, copyright, related links, or contact details
<!-- Page footer -->
<footer>
<p>© 2024 Company Name. All rights reserved.</p>
<nav>
<a href="/privacy">Privacy Policy</a>
<a href="/terms">Terms of Service</a>
<a href="/contact">Contact</a>
</nav>
<div class="social-media">
<a href="#">Facebook</a>
<a href="#">Twitter</a>
</div>
</footer>
<!-- Article footer -->
<article>
<h2>Article Title</h2>
<p>Article content...</p>
<footer>
<p>Written by John Doe</p>
<p>Published: January 15, 2024</p>
<p>Tags: HTML, Web Development</p>
</footer>
</article>
<!-- Section footer -->
<section>
<h2>Product Features</h2>
<p>Features content...</p>
<footer>
<p><a href="/features">View all features</a></p>
</footer>
</section>Correct Answer: Figcaption provides a caption for content in figure
<!-- Image with caption -->
<figure>
<img src="sunset.jpg" alt="Beautiful sunset">
<figcaption>Sunset over the ocean, January 2024</figcaption>
</figure>
<!-- Code listing with caption -->
<figure>
<figcaption>Example of a JavaScript function</figcaption>
<pre><code>
function greet(name) {
return `Hello, ${name}!`;
}
</code></pre>
</figure>
<!-- Diagram with caption -->
<figure>
<img src="architecture-diagram.png"
alt="System architecture">
<figcaption>
Figure 1: Microservices architecture overview
</figcaption>
</figure>
<!-- Multiple images in one figure -->
<figure>
<img src="photo1.jpg" alt="Photo 1">
<img src="photo2.jpg" alt="Photo 2">
<img src="photo3.jpg" alt="Photo 3">
<figcaption>Photo gallery from our trip</figcaption>
</figure>Correct Answer: To represent dates and times in machine-readable format
<!-- Publication date -->
<article>
<h2>Article Title</h2>
<p>Published on
<time datetime="2024-01-15">January 15, 2024</time>
</p>
</article>
<!-- Date and time -->
<p>The event starts at
<time datetime="2024-03-20T19:00:00">
7:00 PM on March 20, 2024
</time>
</p>
<!-- Duration -->
<p>The video is
<time datetime="PT2M30S">2 minutes 30 seconds</time> long
</p>
<!-- Relative time -->
<p>Posted
<time datetime="2024-01-15T10:30:00"
title="January 15, 2024 at 10:30 AM">
2 hours ago
</time>
</p>
<!-- Just a year -->
<p>Copyright <time datetime="2024">2024</time></p>Correct Answer: Highlights text for reference or notation
<!-- Search results highlighting --> <p>We found results for <mark>JavaScript</mark>:</p> <article> <h2>Learning <mark>JavaScript</mark></h2> <p><mark>JavaScript</mark> is a programming language...</p> </article> <!-- Highlighting in quoted text --> <blockquote> <p>To be or not to be, <mark>that is the question</mark>.</p> </blockquote> <!-- Indicating relevance --> <p>Important dates: <mark>January 15</mark> - Registration deadline </p> <!-- Document comparison --> <p>Original: The product costs $100</p> <p>Updated: The product costs <mark>$89</mark></p>
Correct Answer: Completion progress of a task
<!-- Determinate progress (known completion) -->
<label for="file">Upload progress:</label>
<progress id="file" value="70" max="100">70%</progress>
<!-- Indeterminate progress (unknown time) -->
<p>Loading...</p>
<progress></progress>
<!-- Form completion -->
<p>Form completion:</p>
<progress value="2" max="5">Step 2 of 5</progress>
<!-- Download progress -->
<p>Downloading file:</p>
<progress id="download" value="0" max="100">0%</progress>
<p id="percent">0%</p>
<script>
// Update progress with JavaScript
let progress = 0;
const progressBar = document.getElementById('download');
const percentText = document.getElementById('percent');
setInterval(() => {
if (progress < 100) {
progress += 10;
progressBar.value = progress;
percentText.textContent = progress + '%';
}
}, 500);
</script><!-- SEMANTIC HTML EXAMPLE -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Blog</title>
</head>
<body>
<!-- Header with navigation -->
<header>
<h1>My Tech Blog</h1>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/articles">Articles</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<!-- Main content area -->
<main>
<!-- Independent article -->
<article>
<header>
<h2>Understanding Semantic HTML</h2>
<p>
Published on
<time datetime="2024-01-15">January 15, 2024</time>
</p>
</header>
<section>
<h3>What is Semantic HTML?</h3>
<p>Semantic HTML uses <mark>meaningful tags</mark>...</p>
</section>
<section>
<h3>Benefits</h3>
<p>Benefits include improved accessibility...</p>
</section>
<figure>
<img src="semantic-html.png" alt="Semantic HTML diagram">
<figcaption>Figure 1: Semantic HTML structure</figcaption>
</figure>
<footer>
<p>Tags: HTML, Web Development, Accessibility</p>
</footer>
</article>
</main>
<!-- Supplementary content -->
<aside>
<h3>Related Articles</h3>
<ul>
<li><a href="#">HTML5 Features</a></li>
<li><a href="#">Accessibility Guide</a></li>
</ul>
</aside>
<!-- Page footer -->
<footer>
<p>© 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>
<!-- NON-SEMANTIC (BAD PRACTICE) -->
<div class="header">
<div class="title">My Blog</div>
<div class="navigation">
<div class="nav-item">Home</div>
</div>
</div>
<div class="main-content">
<div class="post">
<div class="post-title">Article Title</div>
<div class="post-content">Content...</div>
</div>
</div>
<div class="sidebar">Related content</div>
<div class="footer">Copyright info</div><!-- SEMANTIC APPROACH (Preferred) -->
<article>
<header>
<h2>Article Title</h2>
<p>Published: January 15, 2024</p>
</header>
<section>
<h3>Introduction</h3>
<p>Introductory content...</p>
</section>
<section>
<h3>Main Points</h3>
<p>Main content...</p>
</section>
<footer>
<p>Tags: HTML, Web Development</p>
</footer>
</article>
<!-- Clear semantic structure, good for accessibility and SEO -->
<!-- NON-SEMANTIC APPROACH (Less preferred) -->
<div class="article">
<div class="article-header">
<h2>Article Title</h2>
<p>Published: January 15, 2024</p>
</div>
<div class="article-section">
<h3>Introduction</h3>
<p>Introductory content...</p>
</div>
<div class="article-section">
<h3>Main Points</h3>
<p>Main content...</p>
</div>
<div class="article-footer">
<p>Tags: HTML, Web Development</p>
</div>
</div>
<!-- No semantic meaning, relies only on class names -->
<!-- WHEN TO USE DIV (Layout/Styling) -->
<div class="container">
<!-- Layout wrapper -->
<div class="row">
<!-- Grid row -->
<div class="col-6">
<!-- Grid column -->
<section>
<!-- Semantic content inside layout div -->
<h2>Content Title</h2>
<p>Content...</p>
</section>
</div>
</div>
</div>
<!-- WHEN TO USE SECTION (Semantic Meaning) -->
<main>
<section>
<h2>Our Features</h2>
<p>Feature descriptions...</p>
</section>
<section>
<h2>Pricing</h2>
<p>Pricing information...</p>
</section>
<section>
<h2>Contact Us</h2>
<p>Contact details...</p>
</section>
</main>
<!-- COMBINING BOTH APPROPRIATELY -->
<div class="page-wrapper">
<!-- Layout div -->
<header>
<!-- Semantic header -->
<div class="logo-container">
<!-- Layout div for logo -->
<img src="logo.png" alt="Company Logo">
</div>
<nav>
<!-- Semantic nav -->
<ul>...</ul>
</nav>
</header>
<main>
<!-- Semantic main -->
<div class="content-grid">
<!-- Layout div for grid -->
<article>...</article>
<aside>...</aside>
</div>
</main>
</div><!-- SEO-FRIENDLY SEMANTIC STRUCTURE -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="Learn semantic HTML">
<title>Semantic HTML Guide</title>
</head>
<body>
<!-- Clear header for crawlers -->
<header>
<h1>Complete Guide to Semantic HTML</h1>
<nav aria-label="Main navigation">
<ul>
<li><a href="/">Home</a></li>
<li><a href="/tutorials">Tutorials</a></li>
</ul>
</nav>
</header>
<!-- Main content clearly marked -->
<main>
<!-- Article marked for distribution/indexing -->
<article>
<header>
<h2>Understanding Semantic HTML</h2>
<p>
Published:
<time datetime="2024-01-15T10:00:00">
January 15, 2024
</time>
</p>
</header>
<!-- Clear content sections -->
<section>
<h3>What is Semantic HTML?</h3>
<p>Semantic HTML uses meaningful tags...</p>
</section>
<section>
<h3>Benefits for SEO</h3>
<p>Search engines understand <mark>semantic structure</mark>...</p>
</section>
<!-- Properly marked figure -->
<figure>
<img src="semantic-html-diagram.png"
alt="Diagram showing semantic HTML structure">
<figcaption>
Figure 1: Semantic HTML element hierarchy
</figcaption>
</figure>
<footer>
<p>Author: Jane Developer</p>
<p>Categories: HTML, Web Development, SEO</p>
</footer>
</article>
<!-- Related content sidebar -->
<aside>
<h3>Related Articles</h3>
<nav aria-label="Related articles">
<ul>
<li><a href="#">HTML5 Features</a></li>
<li><a href="#">Accessibility Best Practices</a></li>
</ul>
</nav>
</aside>
</main>
<!-- Footer with site information -->
<footer>
<nav aria-label="Footer navigation">
<a href="/privacy">Privacy</a>
<a href="/terms">Terms</a>
</nav>
<p>© 2024 Web Development Tutorial</p>
</footer>
</body>
</html>
<!-- ACCESSIBILITY FEATURES DEMONSTRATED -->
<!-- Skip link for keyboard users -->
<a href="#main-content" class="skip-link">
Skip to main content
</a>
<!-- Landmarks for screen readers -->
<header role="banner">
<!-- Site header -->
</header>
<nav role="navigation" aria-label="Main">
<!-- Primary navigation -->
</nav>
<main id="main-content" role="main">
<!-- Main content - screen readers can jump here -->
<article>
<h2>Article with Clear Structure</h2>
<!-- Content users came for -->
</article>
</main>
<aside role="complementary">
<!-- Supplementary content - users can skip -->
</aside>
<footer role="contentinfo">
<!-- Footer information -->
</footer>
<!-- Proper heading hierarchy -->
<h1>Main Page Title</h1>
<h2>Major Section</h2>
<h3>Subsection</h3>
<h3>Another Subsection</h3>
<h2>Another Major Section</h2>
<h3>Its Subsection</h3>Correct Answer: <article>, <section>, <nav>, <header>
<!-- Example of new HTML5 semantic elements -->
<header>
<h1>HTML5 Features</h1>
</header>
<nav>
<a href="/">Home</a> | <a href="/about">About</a>
</nav>
<main>
<article>
<section>
<h2>Introduction</h2>
<p>HTML5 introduced many new semantic elements.</p>
</section>
</article>
</main>Correct Answer: To draw graphics, animations, or games using JavaScript
<!-- Basic Canvas Example -->
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000;"></canvas>
<script>
const c = document.getElementById('myCanvas');
const ctx = c.getContext('2d');
ctx.fillStyle = 'blue';
ctx.fillRect(20, 20, 150, 50);
ctx.fillStyle = 'white';
ctx.font = '16px Arial';
ctx.fillText('Canvas Demo', 40, 50);
</script>Correct Answer: SVG is vector-based, Canvas is raster-based
<!-- Simple SVG Example --> <svg width="200" height="100"> <rect width="200" height="100" fill="lightblue" stroke="black"/> <circle cx="100" cy="50" r="30" fill="orange"/> <text x="60" y="55" font-size="16" fill="black">SVG</text> </svg>
Correct Answer: Geolocation API
<!-- Basic Geolocation Example -->
<button onclick="getLocation()">Get Location</button>
<p id="output"></p>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
document.getElementById('output').textContent = 'Geolocation not supported.';
}
}
function showPosition(position) {
document.getElementById('output').textContent =
`Latitude: ${position.coords.latitude}, Longitude: ${position.coords.longitude}`;
}
</script>Correct Answer: It stores data permanently until explicitly deleted
<!-- Example using localStorage -->
<script>
localStorage.setItem('username', 'John');
const user = localStorage.getItem('username');
console.log('Welcome, ' + user);
</script>Correct Answer: localStorage data persists after browser close, sessionStorage does not
<!-- sessionStorage Example -->
<script>
sessionStorage.setItem('theme', 'dark');
console.log(sessionStorage.getItem('theme'));
</script>Correct Answer: ondrop
<!-- Simple Drag and Drop Example -->
<div id="drag" draggable="true" style="width:100px;height:50px;background:red;">Drag me</div>
<div id="drop" style="width:200px;height:100px;border:2px dashed black;margin-top:10px;">Drop here</div>
<script>
const drag = document.getElementById('drag');
const drop = document.getElementById('drop');
drop.ondragover = e => e.preventDefault();
drop.ondrop = () => drop.textContent = 'Dropped!';
</script>Correct Answer: To store custom data private to the page or app
<!-- Example using data-* attributes -->
<button data-user-id="123" data-role="admin">Show Details</button>
<script>
const btn = document.querySelector('button');
console.log(btn.dataset.userId); // 123
console.log(btn.dataset.role); // admin
</script>Correct Answer: Makes text editable directly in the browser
<!-- Example --> <div contenteditable="true" style="border:1px solid #ccc; padding:5px;"> Edit this text directly. </div>
Correct Answer: src, controls, autoplay, loop
<video src="demo.mp4" controls autoplay loop width="400"></video>
Correct Answer: Service Workers
<!-- Register a service worker -->
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js').then(() => {
console.log('Service Worker registered');
});
}
</script>Correct Answer: color, date, email, range
<!-- Example HTML5 inputs --> <form> <input type="email" placeholder="Enter your email"> <input type="date"> <input type="color"> <input type="range" min="0" max="100"> </form>
<!-- Example summarizing HTML5 features --> <header><h1>HTML5 Features</h1></header> <main> <video controls src="intro.mp4"></video> <canvas id="chart"></canvas> <script>/* draw chart code */</script> </main>
<!-- Dark Mode Example -->
<script>
const toggle = document.getElementById('toggle');
toggle.onclick = () => {
document.body.classList.toggle('dark');
localStorage.setItem('theme', document.body.classList.contains('dark') ? 'dark' : 'light');
};
if (localStorage.getItem('theme') === 'dark') {
document.body.classList.add('dark');
}
</script><!-- Comparing Canvas and SVG --> <canvas id="chart" width="200" height="100"></canvas> <svg width="200" height="100"> <circle cx="100" cy="50" r="40" fill="blue" /> </svg>
Correct Answer: To provide metadata about the webpage
<head> <meta name="description" content="Learn HTML meta tags and SEO optimization"> <meta name="author" content="Web Dev Academy"> </head>
Correct Answer: The character encoding for the HTML document
<meta charset="UTF-8">
Correct Answer: It adjusts layout based on device width and scaling
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Correct Answer: Search result snippets and click-through rate
<meta name="description" content="Comprehensive guide to meta tags and SEO.">
Correct Answer: No, most search engines ignore them
<meta name="keywords" content="HTML, meta tags, SEO, web development">
Correct Answer: Facebook
<meta property="og:title" content="Learn Meta Tags"> <meta property="og:description" content="A complete guide to HTML meta tags and SEO."> <meta property="og:image" content="https://example.com/preview.jpg">
Correct Answer: To control how content appears when shared on Twitter
<meta name="twitter:card" content="summary_large_image"> <meta name="twitter:title" content="Meta Tags Guide"> <meta name="twitter:description" content="Understand SEO and social tags."> <meta name="twitter:image" content="https://example.com/preview.jpg">
Correct Answer: To tell search engines whether to index a page and follow its links
<meta name="robots" content="noindex, nofollow">
Correct Answer: To indicate the preferred URL when multiple pages have similar content
<link rel="canonical" href="https://example.com/original-page">
Correct Answer: The small icon displayed in the browser tab or bookmarks
<link rel="icon" type="image/png" href="/favicon.png">
Correct Answer: <meta http-equiv="refresh" content="5">
<meta http-equiv="refresh" content="5; url=https://example.com/new-page">
Correct Answer: author and content-language
<meta name="author" content="Jane Developer"> <meta http-equiv="content-language" content="en">
Correct Answer: Open Graph and Twitter Card tags
<meta property="og:image" content="preview.jpg"> <meta name="twitter:card" content="summary_large_image">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="Learn Meta Tags"> <meta property="og:description" content="Boost SEO with Open Graph."> <meta property="og:image" content="/images/og-preview.png">
<head> <title>Meta Tags and SEO</title> <meta name="description" content="Learn how meta tags improve SEO and ranking."> <link rel="canonical" href="https://example.com/meta-seo"> </head>
Correct Answer: It helps detect syntax errors and ensures standard compliance
<!-- Validate your HTML --> <p>Use the W3C Markup Validation Service at https://validator.w3.org/</p>
Correct Answer: Using consistent indentation and lowercase tags
<!-- Well-formatted HTML example -->
<main>
<section>
<h2>Good Formatting</h2>
<p>This is an example of well-indented HTML.</p>
</section>
</main>Correct Answer: Use lowercase letters, hyphens, or underscores
<!-- Example of consistent naming --> <div id="main-header" class="user-profile"> <h1>Welcome</h1> </div>
Correct Answer: They help developers understand code structure and intent
<!-- This section contains the main navigation --> <nav>...</nav>
Correct Answer: Using vendor-specific CSS prefixes when necessary
/* Example: cross-browser prefixes */
.box {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}Correct Answer: Starting design and development with mobile devices in mind first
@media (min-width: 768px) {
/* Enhance layout for larger screens */
}Correct Answer: Starting with basic functionality, then adding enhancements for capable browsers
<!-- Basic HTML -->
<button>Submit</button>
<!-- Enhanced with JavaScript -->
<script>
document.querySelector('button').addEventListener('click', () => alert('Form submitted!'));
</script>Correct Answer: Invisible
<!-- Example: adding alt text for accessibility --> <img src="logo.png" alt="Company logo">
Correct Answer: Leaving unclosed tags or incorrect nesting
<!-- Incorrect --> <p><strong>Bold text<p></strong> <!-- Correct --> <p><strong>Bold text</strong></p>
Correct Answer: Minimizing HTTP requests and optimizing images
<!-- Example: optimized image --> <img src="image.webp" alt="Optimized image" loading="lazy">
Correct Answer: W3C (World Wide Web Consortium)
<!-- W3C Validation Link --> <a href="https://validator.w3.org/">Validate HTML</a>
<!-- Example usage --> <p>Check your code using: https://validator.w3.org/</p>
<!-- Basic form --> <form action="/submit" method="POST"> <input type="text" name="name"> <button>Submit</button> </form> <!-- Enhanced with JavaScript --> <script> // AJAX form enhancement </script>
<!-- Wrong --> <div><p>Paragraph<div></p> <!-- Correct --> <div><p>Paragraph</p></div>
Correct Answer: <!DOCTYPE html><html><head><title>Page</title></head><body></body></html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Webpage</title> </head> <body> <h1>Welcome!</h1> </body> </html>
Correct Answer: <input type="email">
<form> <label>Email:</label> <input type="email" required> <button>Register</button> </form>
Correct Answer: <nav>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav>Correct Answer: Add overflow-x: auto; to the container
<div style="overflow-x:auto;">
<table>
<tr><th>Name</th><th>Email</th></tr>
<tr><td>John</td><td>john@example.com</td></tr>
</table>
</div>Correct Answer: figure and figcaption
<figure> <img src="image.jpg" alt="Beautiful landscape"> <figcaption>Mountain View</figcaption> </figure>
Correct Answer: <input type="range">
<label>Volume:</label> <input type="range" min="0" max="100" value="50">
Correct Answer: <header><main><article></article></main><footer></footer>
<header>
<h1>My Blog</h1>
</header>
<main>
<article>
<h2>Post Title</h2>
<p>Post content...</p>
</article>
</main>
<footer>
<p>© 2025 Blog</p>
</footer><!DOCTYPE html> <html lang="en"> <head><title>Simple Page</title></head> <body> <header><h1>Website Header</h1></header> <main><p>Main content goes here.</p></main> <footer><p>© 2025 Company</p></footer> </body> </html>
<form> <label>Name:</label><input type="text" required><br> <label>Email:</label><input type="email" required><br> <label>Password:</label><input type="password" required><br> <label>Gender:</label> <input type="radio" name="gender">Male <input type="radio" name="gender">Female<br> <button>Register</button> </form>
<nav>
<ul style="list-style:none;display:flex;gap:10px;">
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
<li><a href="/contact">Contact</a></li>
</ul>
</nav><div style="overflow-x:auto;"> <table> <tr><th>Name</th><th>Email</th><th>Role</th></tr> <tr><td>John</td><td>john@example.com</td><td>Admin</td></tr> </table> </div>
<div style="display:grid;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));gap:10px;">
<figure>
<img src="img1.jpg" alt="Photo 1" style="width:100%">
<figcaption>Photo 1</figcaption>
</figure>
<figure>
<img src="img2.jpg" alt="Photo 2" style="width:100%">
<figcaption>Photo 2</figcaption>
</figure>
</div><form> <input type="text" placeholder="Name"> <input type="email" placeholder="Email"> <input type="number" placeholder="Age"> <input type="range" min="0" max="100"> <input type="color" value="#ff0000"> <button>Submit</button> </form>
<header><h1>My Tech Blog</h1></header>
<main>
<article>
<h2>Understanding HTML5</h2>
<p>Semantic HTML makes content meaningful...</p>
</article>
<aside>
<h3>Related Posts</h3>
<ul><li><a href="#">Accessibility in HTML</a></li></ul>
</aside>
</main>
<footer><p>© 2025 Blog</p></footer>