πΈοΈ The History of HTML β From 1991 to the Living Web
HTML (HyperText Markup Language) is the backbone of the web. Here’s a timeline of how it evolved from a simple document structure to a powerful tool for building rich internet applications.
π 1991 β Birth of HTML
Tim Berners-Lee publishes the first HTML specification with just 18 basic tags.
π 1995 β HTML 2.0
The first standardized version by IETF. Introduced forms, basic tables, and structure.
π§© 1997 β HTML 3.2
Published by W3C. Added tables, applets, scripting support, and improved styles.
π 1999 β HTML 4.01
Introduced frames, better forms, and international language support.
π§ 2000 β XHTML 1.0
A stricter, XML-based version of HTML. More rules, cleaner code.
π οΈ 2004 β The Rise of WHATWG
A new group (WHATWG) begins working on a modern, application-friendly HTMLβHTML5.
π 2014 β HTML5 Standard Released
Introduces <video>, <audio>, <canvas>, semantic tags like <article>, <section>, and more.
π Today β HTML Living Standard
HTML is now continuously updated by WHATWG. No more versionsβjust ongoing improvements.
β Why It Matters for Web Developers
Modern HTML allows:
- Semantic SEO-friendly markup
- Native support for multimedia
- Better accessibility
- Offline and interactive web apps
π Introduction to HTML
HTML (HyperText Markup Language) is the foundation of all web pages. It provides the structure and layout for content on the internet. Every websiteβfrom simple blogs to complex web appsβstarts with HTML.
β What Youβll Learn:
- What HTML is and why it matters
- Basic HTML tags and structure
- How to write your first HTML page
π Introduction to HTML
HTML (HyperText Markup Language) is the foundation of all web pages. It provides the structure and layout for content on the internet. Every websiteβfrom simple blogs to complex web appsβstarts with HTML.
β What Youβll Learn:
- What HTML is and why it matters
- Basic HTML tags and structure
- How to write your first HTML page
π Example:
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to HTML!</h1>
<p>This is a simple webpage structure.</p>
</body>
</html>
π Tip: Use proper tags like <h1> to <h6> for headings, <p> for paragraphs, and <a> for links to keep your content structured and SEO-friendly.
πΉ What are HTML Elements?
An HTML element is everything from the opening tag to the closing tag, including the content in between. Elements are the building blocks of an HTML page.
π Syntax:
<tagname>Content goes here</tagname>
π§© Common HTML Elements
| Element | Description |
|---|---|
<h1> to <h6> | Headings (h1 = largest, h6 = smallest) |
<p> | Paragraph |
<a> | Anchor (link) |
<img> | Image |
<div> | Division/Container |
<span> | Inline container |
<ul>, <ol>, <li> | Lists (unordered, ordered, list items) |
<table> | Table structure |
<form> | Form for user input |
<input>, <button> | Input fields and buttons |
β Example:
<h2>My Favorite Tools</h2>
<ul>
<li>Visual Studio Code</li>
<li>Google Chrome</li>
<li>GitHub</li>
</ul>
π Tip: Keep your HTML semantic and clean for better accessibility and SEO.
π― What are HTML Attributes?
HTML attributes provide extra information about HTML elements. They are always added to the start tag and usually come in name=”value” pairs.
π Common HTML Attributes
| Attribute | Description | Example |
|---|---|---|
id | Unique identifier | <p id="intro"> |
class | Grouping for styling | <div class="card"> |
src | Source for images/media | <img src="image.jpg"> |
href | URL for links | <a href="https://example.com"> |
alt | Image description | <img alt="Logo"> |
title | Tooltip text | <p title="Hello!"> |
style | Inline CSS styling | <h1 style="color:blue;"> |
β Example:
<a href="https://codewithhari.dev" target="_blank" title="Visit my blog">
Visit Code With Hari
</a>
π Tip: Use alt for images to improve accessibility and SEO.
π§© What Are HTML Headings?
HTML headings are used to define the structure and hierarchy of your content. They range from <h1> (most important) to <h6> (least important).
π’ Types of HTML Headings
<h1>This is an H1 Heading</h1>
<h2>This is an H2 Heading</h2>
<h3>This is an H3 Heading</h3>
<h4>This is an H4 Heading</h4>
<h5>This is an H5 Heading</h5>
<h6>This is an H6 Heading</h6>
βοΈ HTML Paragraphs β Structure Your Content Clearly
In HTML, the <p> tag defines a paragraph. It automatically adds spacing above and below your text.
π§ͺ Example:
<p>This is a paragraph of text in HTML. It is wrapped inside <p> tags.</p>
β Avoid This:
<p>This is a paragraph
without closing tag or proper spacing</p>
Instead, use multiple <p> tags for clarity.
ποΈ HTML Text Formatting β Style Your Words with Meaning
HTML provides several tags to format and emphasize text. These tags help with styling, semantics, and accessibility.
π€ Common Formatting Tags
| Tag | Purpose | Example |
|---|---|---|
<b> | Bold (no meaning) | <b>Bold</b> β Bold |
<strong> | Bold (important) | <strong>Important</strong> β Important |
<i> | Italic (no meaning) | <i>Italic</i> β Italic |
<em> | Emphasized (semantic italic) | <em>Emphasis</em> β Emphasis |
<u> | Underline | <u>Underline</u> β Underline |
<mark> | Highlight text | <mark>Highlight</mark> β Highlight |
<small> | Smaller text | <small>Note</small> β Note |
<del> | Deleted text (strikethrough) | <del>Old</del> β Old |
<ins> | Inserted text (underlined) | <ins>New</ins> β New |
<sub> | Subscript | H<sub>2</sub>O β H2O |
<sup> | Superscript | x<sup>2</sup> β x2 |
π SEO Note:
Semantic tags like <strong> and <em> help search engines understand what content is important or emphasized.
π HTML Quotation & Citation Tags β Give Credit Where Itβs Due
HTML provides specific tags to handle quotes, citations, and referencesβgreat for blogs, articles, and academic content.
π§Ύ Quotation & Citation Tags
| Tag | Purpose | Example Output |
|---|---|---|
<blockquote> | Long/paragraph quote (with indent) |
<blockquote cite="https://example.com">
The future belongs to those who prepare for it today.
</blockquote>
β
The future belongs to those who prepare for it today.
| <q> | Short inline quote |
She said, <q>Hello World</q>.
β
She said, βHello Worldβ.
| <cite> | Citation for a creative work |
<cite>The Great Gatsby</cite>
β The Great Gatsby (usually italic)
| <abbr> | Abbreviation with tooltip meaning |
<abbr title="World Health Organization">WHO</abbr>
β WHO (hover shows “World Health Organization”)
| <address> | Author/contact info |
<address>Contact us at info@example.com</address>
π SEO Tip:
Tags like <cite> and <blockquote> signal credibility and authorship, which search engines value in high-quality content.
π¬ HTML Comments
HTML comments are used to leave notes inside the code. These notes are not displayed in the browser.
π§ Syntax
<!-- This is a comment -->
π§ͺ Example
<p>This is visible content.</p>
<!-- <p>This paragraph is hidden and won't be rendered.</p> -->
Only the first paragraph will be shown in the browser.
β Use Cases
- To describe the structure of your HTML
- To temporarily hide parts of code
- To leave reminders or notes for yourself or other developers
β οΈ Important
- Comments are visible in page source, so avoid placing sensitive information in them.
- Browsers completely ignore comment content during rendering.
Hereβs a concise explanation of HTML Images for your blog post:
πΌοΈ HTML Images β Displaying Pictures on Web Pages
To display images in HTML, use the <img> tag. It is a self-closing tag and requires the src and alt attributes.
π§ Syntax
<img src="path-to-image.jpg" alt="Description of image">
β Attributes
src: The path or URL to the image filealt: Alternative text shown if the image fails to load or for screen readers
π§ͺ Example
<img src="sunset.jpg" alt="A beautiful sunset over the hills">
π Optional Attributes
widthandheight: To set image size<img src="logo.png" alt="Site Logo" width="150" height="150">title: Tooltip text on hover<img src="icon.png" alt="Icon" title="Hover text">
β οΈ Best Practices
- Always use
altfor accessibility. - Use optimized image formats like
.webpor.jpegfor better performance. - Avoid stretching by keeping the aspect ratio consistent.
Hereβs a clean explanation of how to add a favicon in HTML for your blog post:
π How to Add a Favicon in HTML
A favicon is the small icon that appears in the browser tab next to your page title.
π§ Syntax (Place in <head> section)
<link rel="icon" type="image/png" href="favicon.png">
β Common Favicon Formats
.ico(classic format):<link rel="icon" href="favicon.ico">.png(modern, preferred):<link rel="icon" type="image/png" href="favicon.png">.svg(for scalable icons):<link rel="icon" type="image/svg+xml" href="favicon.svg">
π Where to Place the File
- Put the favicon file in your root folder (same as
index.html) - Or specify the correct relative path in the
href
Hereβs a concise explanation of the HTML <head> element for your blog post:
π§ HTML β The <head> Element
The <head> element is a container for metadata (data about data). It sits above the <body> and doesn’t display content directly on the webpage.
π§ Syntax
<head>
<title>My Website</title>
<meta charset="UTF-8">
<meta name="description" content="Learn HTML basics">
<link rel="stylesheet" href="styles.css">
http://script.js
</head>
π§© Common Elements Inside <head>
| Tag | Purpose |
|---|---|
<title> | Sets the page title (shown in browser tab) |
<meta> | Describes page encoding, author, viewport, SEO |
<link> | Links to external CSS or icons (e.g., favicon) |
<style> | Internal CSS styles |
<script> | JavaScript files or inline scripts |
π Why It Matters
- Improves SEO, page loading, and browser compatibility
- Required for proper rendering and functionality
π§ The HTML <head> Element β Explained with Examples
The <head> element is a container for metadataβdata about your HTML document. It is placed between <html> and <body>.
Metadata is not displayed on the page itself, but is used by browsers, search engines, and web services.
π¦ Elements Inside <head>
The <head> can contain:
<title>β Document title (shown in tab)<style>β Internal CSS<meta>β Metadata like description, keywords, charset<link>β Link to external files (like CSS)<script>β JavaScript files or inline code<base>β Base URL for all relative URLs
π·οΈ The <title> Element
Defines the page title.
<title>My Awesome Web Page</title>
β
Shown in browser tab
β
Required in all HTML docs
β
Critical for SEO β Used in search engine result titles
π¨ The <style> Element
Used to write internal CSS directly inside HTML:
<style>
body { background-color: powderblue; }
h1 { color: red; }
p { color: blue; }
</style>
π The <link> Element
Used to link external stylesheets or other resources:
<link rel="stylesheet" href="styles.css">
Common rel values:
stylesheeticon(for favicon)preload
𧬠The <meta> Element
Defines metadata. Here are common examples:
<meta charset="UTF-8">
<meta name="description" content="Learn HTML step-by-step">
<meta name="keywords" content="HTML, CSS, Web">
<meta name="author" content="Hari Mohan">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
π viewport makes your site mobile-friendly
π description improves search engine previews
π§ͺ Full Example of a <head> Section
<!DOCTYPE html>
<html>
<head>
<title>A Meaningful Page Title</title>
<meta charset="UTF-8">
<meta name="description" content="Learn HTML easily">
<meta name="keywords" content="HTML, CSS, Tutorial">
<meta name="author" content="Hari Mohan">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<style>
h1 { color: darkblue; }
</style>
http://script.js
</head>
<body>
<h1>Hello HTML!</h1>
</body>
</html>
π§± HTML Layout Elements and Techniques β Building Page Structure
HTML provides semantic layout elements and several techniques to design structured and responsive web pages.
π§© Semantic Layout Elements
These tags describe the structure of a page clearly for both developers and search engines:
| Element | Purpose |
|---|---|
<header> | Defines a page or section header |
<nav> | Contains navigation links |
<main> | The main content of the document |
<section> | A thematic grouping of content |
<article> | Independent content (e.g., blog post) |
<aside> | Sidebar or tangential content |
<footer> | Footer for a section or page |
π§ͺ Example Layout:
<body>
<header>
<h1>My Website</h1>
</header>
<nav>
<a href="#">Home</a>
<a href="#">About</a>
</nav>
<main>
<section>
<h2>Welcome</h2>
<p>This is the homepage content.</p>
</section>
<aside>
<h3>News</h3>
<p>Latest updates here.</p>
</aside>
</main>
<footer>
<p>© 2025 My Website</p>
</footer>
</body>
π οΈ Layout Techniques
| Technique | Description |
|---|---|
| CSS Flexbox | One-dimensional layout (row or column) |
| CSS Grid | Two-dimensional layout (rows + columns) |
| Media Queries | Responsive design for various screen sizes |
| Float & Clear | Older method; less common today |
| Positioning | Absolute, relative, fixed, and sticky layouts |
π Tips
- Prefer semantic elements for clarity and accessibility.
- Use CSS Grid for complex layouts and Flexbox for simpler structures.
- Combine layout tags with CSS for responsive, well-structured designs.
π± HTML Responsive Web Design β Make It Look Great on All Devices
Responsive Web Design (RWD) ensures your website looks good on desktops, tablets, and mobile phones by adapting to different screen sizes.
π§ Key Techniques in Responsive Design
β 1. Viewport Meta Tag
Tells the browser how to control the pageβs dimensions and scaling:
<meta name="viewport" content="width=device-width, initial-scale=1.0">
β 2. Responsive Images
Images that scale with screen size:
<img src="image.jpg" style="max-width: 100%; height: auto;">
Or use srcset for different resolutions:
<img src="small.jpg" srcset="large.jpg 1024w, medium.jpg 768w" alt="Responsive image">
β 3. Media Queries (CSS)
Apply different styles based on screen width:
@media (max-width: 768px) {
body {
background-color: lightblue;
}
}
β 4. CSS Flexbox & Grid
Use flex and grid layouts to rearrange content easily:
.container {
display: flex;
flex-wrap: wrap;
}
π Why It Matters
- Better user experience
- Improves SEO and performance
- Makes your site mobile-friendly, which is crucial today
π§© HTML Semantic Elements β Meaningful Page Structure
Semantic HTML uses tags that clearly describe their purpose and content, making your code easier to read and more accessible.
π·οΈ Common Semantic Elements
| Tag | Purpose |
|---|---|
<header> | Defines a page or section header |
<nav> | Navigation links |
<main> | Main content of the document |
<section> | Thematic grouping of content |
<article> | Self-contained content (e.g., blog post) |
<aside> | Sidebar or additional info |
<footer> | Footer for a page or section |
<figure> | Used with <figcaption> for images/media |
π§ͺ Example:
<body>
<header>
<h1>My Blog</h1>
</header>
<nav>
<a href="#">Home</a>
<a href="#">Articles</a>
</nav>
<main>
<article>
<h2>Semantic HTML</h2>
<p>This article explains semantic elements.</p>
</article>
<aside>
<p>Related topics: Accessibility, SEO</p>
</aside>
</main>
<footer>
<p>© 2025 My Blog</p>
</footer>
</body>
β Benefits of Semantic HTML
- Improves SEO and screen reader support
- Makes your code easier to maintain
- Enhances browser and developer tool compatibility
π HTML Tables β Organize Data in Rows and Columns
HTML tables are used to display structured data like schedules, pricing, or comparisons.
π§ Basic Table Syntax
<table>
<tr>
<th>Language</th>
<th>Type</th>
</tr>
<tr>
<td>HTML</td>
<td>Markup</td>
</tr>
<tr>
<td>JavaScript</td>
<td>Programming</td>
</tr>
</table>
π§© Tag Breakdown
| Tag | Purpose |
|---|---|
<table> | Wraps the entire table |
<tr> | Defines a row |
<th> | Header cell (bold + centered text) |
<td> | Standard cell for data |
β¨ Optional Tags
<caption>β Title for the table<thead>β Group header rows<tbody>β Group body rows<tfoot>β Group footer rows
π¨ Example with Styling
<table border="1">
<caption>Web Technologies</caption>
<thead>
<tr><th>Name</th><th>Type</th></tr>
</thead>
<tbody>
<tr><td>HTML</td><td>Markup</td></tr>
<tr><td>CSS</td><td>Style Sheet</td></tr>
</tbody>
</table>
π HTML Table Borders β Make Your Tables Visible
By default, HTML tables have no borders. You can add borders using either the border attribute or CSS.
β
1. Using the border Attribute (Old Method)
<table border="1">
<tr>
<th>Name</th>
<th>Role</th>
</tr>
<tr>
<td>Hari</td>
<td>Frontend Dev</td>
</tr>
</table>
- Quick and easy
- Not recommended for modern HTML (use CSS instead)
β 2. Using CSS (Modern Method)
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
<table>
<tr>
<th>Name</th>
<th>Role</th>
</tr>
<tr>
<td>Hari</td>
<td>Frontend Dev</td>
</tr>
</table>
border-collapse: collapse;removes double borders- More flexible and modern approach
β¨ You Can Also Style:
- Border color:
border: 1px solid blue; - Rounded corners:
border-radius: 5px; - Cell padding:
padding: 10px;
π HTML Table Sizes β Control Width and Height
You can control the size of tables using the width and height attributes (deprecated) or preferably with CSS.
β 1. Using HTML Attributes (Not recommended)
<table width="400" height="200">
<tr>
<td>Fixed size table</td>
</tr>
</table>
- Uses pixels
- Not responsive
- Deprecated in modern HTML
β 2. Using CSS (Modern Method)
<style>
table {
width: 100%;
height: auto;
}
td {
width: 50%;
height: 100px;
}
</style>
<table>
<tr>
<td>Left Cell</td>
<td>Right Cell</td>
</tr>
</table>
width: 100%makes the table responsive- Control individual cell sizes with
tdstyles
π Responsive Tip
Use % for widths and avoid fixed pixel values for mobile-friendly design.
<table style="width: 100%;">
<tr>
<td style="width: 70%;">Main Content</td>
<td style="width: 30%;">Sidebar</td>
</tr>
</table>
π§Ύ HTML Table Headers β Add Meaning to Your Data
HTML table headers are created using the <th> tag and help define the titles of columns or rows in a table.
β Basic Example
<table border="1">
<tr>
<th>Name</th>
<th>Role</th>
</tr>
<tr>
<td>Hari</td>
<td>Frontend Developer</td>
</tr>
</table>
<th>stands for table header- Text is bold and centered by default
π― Column vs. Row Headers
Column Headers (most common):
<tr>
<th>Product</th>
<th>Price</th>
</tr>
Row Headers (less common):
<tr>
<th scope="row">HTML</th>
<td>Markup Language</td>
</tr>
Use scope="col" or scope="row" for accessibility and screen readers.
π§ Summary
| Tag | Purpose | Default Style |
|---|---|---|
<th> | Table header cell | Bold & Centered |
scope | Accessibility help | col or row |
π¦ HTML Table Padding & Spacing β Improve Table Readability
Padding and spacing control the whitespace inside and between table cells, improving how your table looks.
β
1. Cell Padding (padding)
Defines space inside each cell between the content and cell border.
<style>
td, th {
padding: 10px;
}
</style>
β
2. Cell Spacing (border-spacing)
Defines space between table cells (outside the border).
<style>
table {
border-spacing: 15px;
}
</style>
β Note: border-spacing only works when border-collapse: separate; is set (default).
β 3. Collapse Borders & Remove Spacing
To make borders touch with no spacing:
<style>
table {
border-collapse: collapse;
}
th, td {
border: 1px solid black;
padding: 8px;
}
</style>
π§ Summary
| Property | What it Does |
|---|---|
padding | Space inside a cell |
border-spacing | Space between cells |
border-collapse | Makes borders collapse into one |
π HTML Table colspan & rowspan β Merge Table Cells
Use colspan and rowspan attributes in HTML tables to merge cells across columns or rows, making your data display more flexible.
πΈ colspan β Merge Columns
Joins two or more columns into a single cell.
<table border="1">
<tr>
<th colspan="2">Full Name</th>
</tr>
<tr>
<td>Hari</td>
<td>Mohan</td>
</tr>
</table>
β Result: βFull Nameβ spans both columns above “Hari” and “Mohan”.
πΉ rowspan β Merge Rows
Joins two or more rows into a single cell.
<table border="1">
<tr>
<th rowspan="2">Name</th>
<td>Frontend</td>
</tr>
<tr>
<td>Developer</td>
</tr>
</table>
β Result: βNameβ spans both rows beside “Frontend” and “Developer”.
π§ Summary
| Attribute | Purpose |
|---|---|
colspan | Merge cells horizontally (columns) |
rowspan | Merge cells vertically (rows) |
π¬ HTML Forms β Collect User Input Easily
HTML forms let users submit data to a web server β for things like login, registration, feedback, or searches.
π§© Basic Form Structure
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<br><br>
<input type="submit" value="Submit">
</form>
π§ͺ Common Form Elements
| Tag | Description |
|---|---|
<form> | Container for input fields |
<input> | User inputs (text, email, password) |
<label> | Label for input |
<textarea> | Multi-line input |
<select> | Dropdown list |
<option> | Options inside dropdown |
<button> | Clickable button |
π₯ Example with Dropdown & Textarea
<form>
<label for="feedback">Feedback:</label><br>
<textarea id="feedback" name="feedback" rows="4" cols="40"></textarea><br><br>
<label for="role">Role:</label>
<select id="role" name="role">
<option value="developer">Developer</option>
<option value="designer">Designer</option>
</select><br><br>
<button type="submit">Send</button>
</form>
β Attributes to Know
actionβ URL to submit form datamethodβGETorPOSTrequiredβ Makes a field mandatoryplaceholderβ Placeholder text inside input
π§© HTML Form Elements β Build Interactive Forms
HTML form elements are used to collect different types of user input like text, selections, files, and buttons.
π§± Common Form Elements
| Element | Purpose |
|---|---|
<input> | Basic input fields (text, email, etc.) |
<label> | Describes input field |
<textarea> | Multi-line text input |
<select> | Drop-down menu |
<option> | Items inside a <select> |
<button> | Clickable button |
<fieldset> | Group related fields |
<legend> | Title for a <fieldset> |
π§ͺ Example Form with All Elements
<form>
<fieldset>
<legend>Contact Us</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4" cols="40"></textarea><br><br>
<label for="role">Role:</label>
<select id="role" name="role">
<option value="dev">Developer</option>
<option value="design">Designer</option>
</select><br><br>
<button type="submit">Submit</button>
</fieldset>
</form>
β Tip
Combine these elements to build login forms, feedback forms, surveys, and more.
ποΈ HTML Input Types β Collect the Right Kind of Data
The <input> tag in HTML supports many type values that define the kind of data a user can enter.
π§ Common Input Types
| Type | Description | Example |
|---|---|---|
text | Single-line text | <input type="text"> |
email | Email format validation | <input type="email"> |
password | Masked text input | <input type="password"> |
number | Numeric input with step/limit options | <input type="number" min="1" max="100"> |
tel | Phone number | <input type="tel"> |
url | Website URL | <input type="url"> |
search | Search field with clear button (browser) | <input type="search"> |
checkbox | Toggle one or more options | <input type="checkbox"> |
radio | Choose one from a group | <input type="radio" name="gender"> |
date | Date picker | <input type="date"> |
time | Time picker | <input type="time"> |
range | Slider input | <input type="range" min="0" max="10"> |
color | Color picker | <input type="color"> |
file | Upload file | <input type="file"> |
submit | Submit the form | <input type="submit" value="Send"> |
reset | Reset form values | <input type="reset"> |
hidden | Invisible data for backend processing | <input type="hidden" name="userid" value="123"> |
π§ͺ Mini Example
<form>
<input type="text" placeholder="Your Name"><br>
<input type="email" placeholder="Your Email"><br>
<input type="checkbox"> Subscribe<br>
<input type="submit" value="Submit">
</form>
βοΈ HTML Input Attributes β Control Behavior & Validation
HTML input attributes allow you to customize input fields, enforce rules, and improve user experience.
π§ Common Input Attributes
| Attribute | Purpose | Example |
|---|---|---|
type | Defines the input type | type="text" |
name | Field name for form data | name="email" |
value | Pre-filled default value | value="Hari" |
placeholder | Hint text inside the input | placeholder="Enter name" |
required | Makes the field mandatory | required |
readonly | Field can’t be changed | readonly |
disabled | Field is disabled | disabled |
maxlength | Max number of characters | maxlength="20" |
min / max | Minimum/maximum value (used with number, date) | min="1" max="10" |
step | Increment step for numeric inputs | step="0.5" |
autofocus | Field is auto-focused when the page loads | autofocus |
pattern | Regex for input validation | pattern="[A-Za-z]{3,}" |
autocomplete | Suggest previously entered input | autocomplete="on" |
multiple | Allows multiple file or email inputs | multiple |
π§ͺ Example with Attributes
<input type="email" name="userEmail" placeholder="Enter your email" required autofocus>
π HTML Input form* Attributes β Connect Inputs to Forms Flexibly
HTML provides special form* attributes for <input> elements to link them to a form, even if they’re outside the actual <form> tag.
π§© Key form* Attributes for <input>
| Attribute | Purpose |
|---|---|
form | Links input to a specific <form> by its id |
formaction | URL to submit form data (overrides form’s action) |
formenctype | Data encoding type (e.g., multipart/form-data) |
formmethod | Submission method: get or post (overrides formβs method) |
formtarget | Where to open response: _self, _blank, etc. |
formnovalidate | Skip validation when this input submits the form |
π§ͺ Example: Input Outside Form Using form Attribute
<form id="mainForm" action="/submit" method="post">
<input type="text" name="username">
</form>
<!-- Input outside the form but still linked to it -->
<input type="submit" value="Submit Form" form="mainForm">
π§ͺ Example with formaction and formmethod
<form id="searchForm" action="/default" method="get">
<input type="text" name="query">
<input type="submit" value="Search Default">
</form>
<input type="submit" value="Search Alternate" form="searchForm" formaction="/alternate" formmethod="post">
β Use Cases
- When inputs/buttons are placed outside the form
- When you want different actions or methods for multiple submit buttons
π₯ HTML Media β Add Rich Content to Web Pages
HTML supports embedding multimedia like video, audio, and external content to make your web pages more interactive.
π¬ HTML Video
Use the <video> tag to embed videos directly:
<video width="640" height="360" controls>
<source src="movie.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
β
controls adds play/pause buttons
β
Supports formats: .mp4, .webm, .ogg
π§ HTML Audio
Use the <audio> tag to add sound or music:
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
β
Use for music, voiceovers, podcasts
β
Supports formats: .mp3, .ogg, .wav
π§© HTML Plug-ins (Object/Embed β Rarely Used Now)
Used to embed external content like PDFs or Flash (outdated):
http://file.pdf:
[youtube https://www.youtube.com/watch?v=dQw4w9WgXcQ&w=560&h=315]
β
Replace the src with your desired YouTube video ID
β
Fully responsive with custom CSS
π§ Summary
| Element | Use Case | Tag |
|---|---|---|
| Video | Play video content | <video> |
| Audio | Play sound/music | <audio> |
| PDF/embed | Legacy plug-ins | <embed>, <object> |
| YouTube | External video | <iframe> |
π¨ HTML Graphics β Drawing with <canvas> and SVG
HTML lets you create graphics using two main technologies: <canvas> and SVG. Both are powerful but serve different use cases.
πΌοΈ HTML <canvas> Element
The <canvas> element is used to draw graphics via JavaScriptβsuch as charts, games, or animations.
π§ Syntax
<canvas id="myCanvas" width="300" height="150"></canvas>
<script>
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.fillStyle = "blue";
ctx.fillRect(50, 50, 100, 50);
</script>
β Features
- Great for real-time rendering (games, charts, animations)
- Works only with JavaScript
- Raster-based (pixel manipulation)
π§© HTML SVG (Scalable Vector Graphics)
SVG is an XML-based language to define vector graphics directly in HTML.
π§ Syntax
<svg width="200" height="100">
<rect width="200" height="100" style="fill:orange;stroke:black;stroke-width:2" />
</svg>
β Features
- Resolution-independent (scales perfectly)
- Editable with CSS and JavaScript
- Great for icons, charts, logos, diagrams
βοΈ Canvas vs. SVG
| Feature | <canvas> | SVG |
|---|---|---|
| Type | Raster (pixel-based) | Vector (scalable) |
| Interactivity | Manual with JavaScript | Built-in with event support |
| Accessibility | Not accessible by default | More accessible & searchable |
| Use Case | Games, dynamic rendering | Static icons, logos, diagrams |