rea
Reverse engineer anything with agents, from app behavior down to native binaries.
- 475k
- TypeScript
- MIT
- 12 min ago
HTML Basics ( HTML-5 )
Repo learning-zone/html-basics, read from GitHub 5 h ago. learning-zone has not joined Take My Repo.
learning-zone/html-basics is a public repo on GitHub by learning-zone. HTML Basics ( HTML-5 ). It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it. It is written mainly in HTML, has 591 stars and last changed on 2026-05-02. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Click ★ if you like the project. Your contributions are heartily ♡ welcome.
The Extensible Hypertext Markup Language, or XHTML, has two important notes for front end developers.
HTML5 semantic tags define the function and the category of your text, simplifying the work for browsers and search engines, as well as developers.
HTML5 offers new semantic elements to define different parts of a web page:
<article><aside><details><figcaption><figure><footer><header><main><mark><nav><section><summary><time>Syntax:
<!DOCTYPE html>
<html>
<head>
<meta charset = "utf-8"/>
<title>...</title>
</head>
<body>
<header>...</header>
<nav>...</nav>
<article>
<section>
...
</section>
</article>
<aside>...</aside>
<footer>...</footer>
</body>
</html>
<DOCTYPE html> do?A DOCTYPE is always associated to a DTD ( Document Type Definition ). A DTD defines how documents of a certain type should be structured (i.e. a button can contain a span but not a div), whereas a DOCTYPE declares what DTD a document supposedly respects (i.e. this document respects the HTML DTD). For webpages, the DOCTYPE declaration is required. It is used to tell user agents what version of the HTML specifications your document respects.
Once a user agent has recognized a correct DOCTYPE, it will trigger the no-quirks mode matching this DOCTYPE for reading the document. If a user agent doesn't recognize a correct DOCTYPE, it will trigger the quirks mode.
The web page is rendered in quirks mode. The web browsers engines use quirks mode to support older browsers which does not follow the W3C specifications. In quirks mode CSS class and id names are case insensitive. In standards mode they are case sensitive.
Character encoding is a method of converting bytes into characters. To validate or display an HTML document properly, a program must choose a proper character encoding. This is specified in the tag:
<meta charset="utf-8"/>
The META elements can be used to include name/value pairs describing properties of the HTML document, such as author, expiry date, a list of keywords, document author etc.
<!DOCTYPE html>
<html>
<head>
<!--Recommended Meta Tags-->
<meta charset="utf-8">
<meta name="language" content="english">
<meta http-equiv="content-type" content="text/html">
<meta name="author" content="Author Name">
<meta name="designer" content="Designer Name">
<meta name="publisher" content="Publisher Name">
<meta name="no-email-collection" content="name@email.com">
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<!--Search Engine Optimization Meta Tags-->
<meta name="description" content="Project Description">
<meta name="keywords" content="Software Engineer,Product Manager,Project Manager,Data Scientist">
<meta name="robots" content="index,follow">
<meta name="revisit-after" content="7 days">
<meta name="distribution" content="web">
<meta name="robots" content="noodp">
<!--Optional Meta Tags-->
<meta name="distribution" content="web">
<meta name="web_author" content="">
<meta name="rating" content="">
<meta name="subject" content="Personal">
<meta name="title" content=" - Official Website.">
<meta name="copyright" content="Copyright 2020">
<meta name="reply-to" content="">
<meta name="abstract" content="">
<meta name="city" content="Bangalore">
<meta name="country" content="INDIA">
<meta name="distribution" content="">
<meta name="classification" content="">
<!--Meta Tags for HTML pages on Mobile-->
<meta name="format-detection" content="telephone=yes"/>
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<!--http-equiv Tags-->
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>HTML5 Meta Tags</title>
</head>
<body>
...
</body>
</html>
1. Async:
Downloads the script file during HTML parsing and will pause the HTML parser to execute it when it has finished downloading.
Example:
<!--
With async (asynchronous), browser will continue to load the HTML
page and render it while the browser load and execute the script at the same time.
-->
<!-- Google Analytics is usually added like this -->
<script async src="https://google-analytics.com/analytics.js"></script>
2. Defer:
Defer downloads the script file during HTML parsing and will only execute it after the HTML parser has completed. Not all browsers support this.
Example:
<!--
With defer, browser will run your script when the page finished parsing.
(not necessary finishing downloading all image files. This is good.)
-->
<script defer src="myscript.js"></script>
The async attribute is used to indicate to the browser that the script file can be executed asynchronously. The HTML parser does not need to pause at the point it reaches the script tag to fetch and execute, the execution can happen whenever the script becomes ready after being fetched in parallel with the document parsing.
The defer attribute tells the browser to only execute the script file once the HTML document has been fully parsed.
Example:
<!--
Without async or defer, browser will run your script immediately,
before rendering the elements.
-->
<script src="myscript.js"></script>
Cross-Origin Resource Sharing (CORS) is a W3C spec that allows cross-domain communication from the browser. By building on top of the XMLHttpRequest object, CORS allows developers to work with the same idioms as same-domain requests. CORS gives web servers cross-domain access controls, which enable secure cross-domain data transfers.
Graceful degradation is when you initially serve the best possible user experience, with all modern functionality, but use feature detection to “gracefully degrade” parts of your application with a fallback or polyfill.
Progressive enhancement ensures a page works at the lowest expected abilities of browsers. So if you have a JavaScript web application that enhances a persons ability to send information to a database with features like ajax – at the very least you need to provide the ability for a person to send that same information without JavaScript enabled. In this case a simple form with full-page refresh will do what you need.
The DOM (Document Object Model) is a cross-platform API that treats HTML documents as a tree structure consisting of nodes. These nodes (such as elements and text nodes) are objects that can be programmatically manipulated and any visible changes made to them are reflected live in the document. In a browser, this API is available to JavaScript where DOM nodes can be manipulated to change their styles, contents, placement in the document, or interacted with through event listeners.
The DOM was designed to be independent of any particular programming language, making the structural representation of the document available from a single, consistent API.
document.getElementById() and document.querySelector() are common functions for selecting DOM nodes.
Setting the innerHTML property to a new value runs the string through the HTML parser, offering an easy way to append dynamic HTML content to a node.
In order to render content the browser has to go through a series of steps:
In Quirks mode, layout emulates nonstandard behavior in Navigator 4 and Internet Explorer 5. This is essential in order to support websites that were built before the widespread adoption of web standards. In Standards mode, the behavior is described by the HTML and CSS specifications.
For HTML documents, browsers use a <!DOCTYPE html> in the beginning of the document to decide whether to handle it in quirks mode or standards mode.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=UTF-8>
<title>Hello World!</title>
</head>
<body>
</body>
</html>
The Critical Rendering Path (CRP) is the sequence of steps the browser takes to convert HTML, CSS, and JavaScript into pixels on the screen.
The 6 steps in order:
Constructing the DOM Tree — Browser parses HTML and builds the Document Object Model (tree of nodes)
Constructing the CSSOM Tree — Browser parses CSS and builds the CSS Object Model (style rules tree)
Running JavaScript — JS is a parser-blocking resource; the browser stops HTML parsing to execute it (unless async/defer is used)
Creating the Render Tree — DOM + CSSOM are combined; only visible elements are included (e.g., display:none nodes are excluded)
Generating the Layout — Browser calculates the exact size and position of each element on the screen (also called "reflow")
Painting — Browser fills in the actual pixels — text, colors, images, borders, shadows
Why it matters: Optimizing the CRP improves page load performance. Key techniques include:
<link> stylesheets in <head> (avoid render blocking)<script> tags at bottom of <body>, or use async/deferHTML → DOM ─┐
├─→ Render Tree → Layout → Paint
CSS → CSSOM ─┘
Benefits of SSR over CSR:
Faster initial page load — The server sends fully rendered HTML, so the browser displays content immediately without waiting for JavaScript bundles to download and execute.
Better SEO — Search engine crawlers receive complete HTML content directly, making it easier to index pages accurately. CSR often sends an empty <body> that crawlers may not fully process.
No content blocking on slow networks — In CSR, users on slow connections wait for JS to load before seeing anything. With SSR, content is visible as soon as HTML is parsed.
Co-located API calls are faster — The server fetches data internally (low latency), renders it, and ships the final HTML — versus CSR where the browser must make separate API calls after JS loads.
Trade-offs to consider:
| SSR | CSR | |
|---|---|---|
| Initial load | Faster (content in HTML) | Slower (waits for JS) |
| Subsequent navigation | Slower (full page requests) | Faster (only data fetched) |
| Server load | Higher | Lower |
| SEO | Better out of the box | Requires extra effort |
| Interactivity | Requires hydration step | Immediate after JS loads |
Modern frameworks like Next.js and Nuxt.js combine both approaches — using SSR for the initial load and CSR for subsequent navigation — to get the best of both worlds.
The lang attribute specifies the language of an element's content. It is placed on the <html> tag to declare the language of the entire page, or on individual elements to override the page language.
<html lang="en"> <!-- English -->
<html lang="fr"> <!-- French -->
<html lang="ar"> <!-- Arabic -->
What it does:
:lang() pseudo-class to apply language-specific styles:p:lang(fr) {
font-style: italic;
}
Spelling & grammar checkers — Browsers and tools use it to apply the correct dictionary for spell-checking
Search engine language detection — Helps search engines understand the language of content for accurate indexing and localized results
Screen readers & accessibility — Assistive technologies use it to select the correct pronunciation and reading rules for text-to-speech
Browser behavior — Affects automatic translation prompts (e.g., Chrome's "Translate this page?")
Quotation marks — Browsers render <q> tag quotes using the correct style for the specified language
Example:
<html lang="en">
<body>
<p>This is in English.</p>
<p lang="de">Das ist auf Deutsch.</p>
<p lang="ja">これは日本語です。</p>
</body>
</html>
It is a W3C best practice to always declare lang on the <html> element for proper accessibility and SEO.
Compacted conversationThese are the last three steps in the browser's rendering pipeline after the Render Tree is built:
Layout (Reflow)
Calculates the exact size and position of every element on the screen. Because elements affect each other (e.g., a parent's width affects its children), a change to one element can trigger recalculation of the entire tree — making layout the most expensive step to trigger repeatedly.
Caused by changes to:
width,height,margin,padding,font-size,top/left, adding/removing DOM elements.
Paint
Fills in the actual pixels — text, colors, images, borders, shadows. This is done onto one or more layers (surfaces), not directly to the screen.
Caused by changes to:
color,background,box-shadow,border-color,visibility. Does not require a layout recalculation.
Compositing
Takes all the separately painted layers and draws them to the screen in the correct order. This matters for overlapping elements — getting the order wrong would render one element on top of another incorrectly.
CSS properties like
transformandopacityonly trigger compositing (skipping layout and paint entirely), which is why they're the most performant to animate.
Performance hierarchy (fastest → slowest to trigger):
| Change affects | Steps triggered |
|---|---|
transform, opacity |
Composite only |
color, background |
Paint + Composite |
width, margin, top |
Layout + Paint + Composite |
This is why CSS animations using transform: translateX() are far smoother than animating left/top — they bypass layout and paint entirely.
A layout engine (also called a rendering engine) is the core software component of a browser responsible for parsing HTML/CSS and rendering the visual output on screen.
The three active engines today:
Blink (Google, 2013 — forked from WebKit)
WebKit (Apple, 2003 — forked from KHTML)
Gecko (Mozilla, 1998)
<img src="mypic.jpg" style="visibility: hidden" alt="My photo">
<div style="display: none;">
<img src="mypic.jpg" alt="My photo">
</div>
Progressive Rendering is the technique of sequentially rendering portions of a webpage in the server and streaming it to the client in parts without waiting for the whole page to rendered.
It combines the advantages of both CSR (Client Side Rendering) and SSR (Server Side Rendering) (Server Side Rendering).
1. Client Side Rendering:
Client Side Rendering (CSR) is a technique in which content is rendered in the browser using JavaScript. Instead of getting all the content from the HTML file itself, the server sends HTML with an empty body and script tags that contain links to JavaScript bundles that the browser will use to render the content.
Typical page load behavior in CSR —
Since the all the content starts loading only after loading the initial JavaScript, it takes a longer time to show any content on the page. If the user is on a slow network, the content is blocked for an even longer time due to lower bandwidth and higher latency.
2. Server Side Rendering:
When rendering on the server side, the HTML is rendered on the server and sent to the client. The content that we need to display on the screen becomes available immediately after the HTML is parsed; hence, primary rendering of content is faster than CSR.
Typical page load behavior in SSR —
Since the APIs are usually co-located with the server, the content is loaded super fast (faster than CSR) and the HTML is sent to the browser. Initial JavaScript load doesn't block content load as the HTML sent by the server already has the content.
The lang attribute specifies the language of the element's content.
Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>HTML5 Multilanguage Page</title>
</head>
<body>
<h2>English</h2>
<p lang="en">This is demo text</p>
<h2>French</h2>
<p lang="fr">Ceci est un texte de démonstration</p>
<h2>Spanish</h2>
<p lang="es">Este es un texto de demostración</p>
</body>
</html>
HTML Specification
An HTML specification (like HTML5, maintained by the W3C and WHATWG) is a formal document that defines:
Browser Implementation
A browser implementation is the actual code (the rendering engine — Blink, WebKit, Gecko) that attempts to follow the specification. The key word is attempts.
Key Differences
| Aspect | Specification | Browser Implementation |
|---|---|---|
| Authority | Defines the standard | Interprets the standard |
| Completeness | 100% of features defined | Partial — no browser supports all of any spec |
| Consistency | Single source of truth | Varies across Chrome, Firefox, Safari, etc. |
| Invalid HTML | Defines some error-handling rules | Many edge cases left to browser discretion |
| Timing | Features defined before implemented | Implementations lag behind specs |
| Vendor prefixes | Not in spec | Browsers add -webkit-, -moz- for experimental features |
For a tech lead, ensuring consistent, maintainable HTML across a team requires tooling, documentation, and process — not just guidelines.
1. Linting with HTMLHint or html-validate:
// .htmlhintrc
{
"tagname-lowercase": true,
"attr-lowercase": true,
"attr-value-double-quotes": true,
"doctype-first": true,
"tag-pair": true,
"spec-char-escape": true,
"id-unique": true,
"src-not-empty": true,
"alt-require": true,
"title-require": true,
"head-script-disabled": true,
"style-disabled": true
}
# Run as part of CI/CD
npx htmlhint "**/*.html"
npx html-validate "src/**/*.html"
2. Prettier for consistent formatting:
// .prettierrc
{
"printWidth": 100,
"tabWidth": 2,
"htmlWhitespaceSensitivity": "css",
"singleAttributePerLine": false
}
3. Accessibility linting:
# axe-core for automated a11y checks in CI
npm install -D @axe-core/cli
npx axe http://localhost:3000 --exit
4. Code review checklist for HTML:
## HTML Code Review Checklist
### Structure
- [ ] `<!DOCTYPE html>` declared
- [ ] `<html lang="...">` with correct language code
- [ ] `<meta charset="UTF-8">` as first `<head>` child
- [ ] `<meta name="viewport" content="width=device-width, initial-scale=1">` present
- [ ] Logical heading hierarchy (`h1` → `h2` → `h3`, no skips)
- [ ] Landmark elements used (`<header>`, `<nav>`, `<main>`, `<footer>`)
### Forms
- [ ] Every input has an associated `<label>`
- [ ] `required`, `type`, and validation attributes present
- [ ] `autocomplete` tokens set correctly
### Images
- [ ] All `<img>` have `alt` (empty for decorative)
- [ ] Images have `width` and `height` attributes (prevent layout shift)
- [ ] `loading="lazy"` for below-the-fold images
### Security
- [ ] External scripts use `integrity` + `crossorigin` (SRI)
- [ ] `rel="noopener noreferrer"` on `target="_blank"` links
- [ ] No inline event handlers in templates
### Accessibility
- [ ] Color contrast passes WCAG AA (4.5:1 for text)
- [ ] Focus order is logical
- [ ] Interactive elements are keyboard-operable
- [ ] ARIA used only when native HTML is insufficient
5. Editor integration: Share .editorconfig, Prettier config, and ESLint (for inline scripts) via a shared config package in your monorepo.
Micro-frontends extend microservices thinking to the frontend — each team owns an independently deployable UI slice. HTML5 provides two primary composition mechanisms:
1. iframes — strongest isolation, simplest integration:
<!-- Shell app (host) -->
<div class="layout">
<header>
<iframe src="https://team-nav.example.com/navbar" title="Navigation"></iframe>
</header>
<main>
<iframe src="https://team-cart.example.com/app" title="Cart Application"></iframe>
</main>
</div>
2. Web Components — native browser standard:
<!-- Each team ships a custom element -->
<script src="https://team-nav.example.com/navbar.js" type="module"></script>
<script src="https://team-cart.example.com/cart.js" type="module"></script>
<body>
<team-navbar></team-navbar>
<main>
<team-cart user-id="123"></team-cart>
</main>
</body>
// team-cart/cart.js — defines the custom element
class TeamCart extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: "open" });
this.shadowRoot.innerHTML = `<cart-app></cart-app>`;
}
}
customElements.define("team-cart", TeamCart);
3. Module Federation (Webpack/Vite) — runtime composition:
<!-- host/index.html -->
<div id="nav-container"></div>
<div id="main-app"></div>
<script type="module" src="./bootstrap.js"></script>
// bootstrap.js — dynamically loads remote modules
const { NavBar } = await import("nav/NavBar"); // from remote team
const { CartApp } = await import("cart/CartApp"); // from remote team
Cross-micro-frontend communication:
// CustomEvent — fire and forget
document.dispatchEvent(new CustomEvent("user:loggedin", { detail: { userId: 123 } }));
// Listen in another micro-frontend
document.addEventListener("user:loggedin", ({ detail }) => {
loadUserCart(detail.userId);
});
// Or use BroadcastChannel for cross-tab/cross-frame
const channel = new BroadcastChannel("mfe-events");
channel.postMessage({ type: "CART_UPDATED", count: 3 });
channel.onmessage = (e) => updateCartBadge(e.data.count);
Tech lead decision guide:
| Approach | Isolation | Shared State | Complexity | Best For |
|---|---|---|---|---|
| iframe | Strongest | Hard | Low | Legacy or fully independent apps |
| Web Components | CSS isolated | Via events | Medium | Greenfield, framework-agnostic |
| Module Federation | None | Shared | High | Same-framework teams, performance critical |
A tech lead must have a clear strategy for handling browser differences — preferring detection over assumption.
Feature detection vs. User Agent sniffing:
// BAD — User Agent sniffing (brittle, breaks with new UA strings)
if (navigator.userAgent.includes("Chrome")) {
useChromePath();
}
// GOOD — Feature detection
if ("IntersectionObserver" in window) {
useLazyLoading();
} else {
loadAllImagesImmediately();
}
Modernizr-style manual detection:
const features = {
serviceWorker: "serviceWorker" in navigator,
webp: false,
webgl: !!document.createElement("canvas").getContext("webgl"),
touchscreen: "ontouchstart" in window || navigator.maxTouchPoints > 0,
};
// WebP detection (async)
const img = new Image();
img.onload = () => { features.webp = img.width === 1; };
img.onerror = () => { features.webp = false; };
img.src = "data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAgA0JZQCdAEO/gHOAAA=";
CSS @supports for feature detection in stylesheets:
/* Apply only if CSS Grid is supported */
@supports (display: grid) {
.container { display: grid; grid-template-columns: repeat(3, 1fr); }
}
/* Fallback for older browsers */
.container { display: flex; flex-wrap: wrap; }
@supports (display: grid) {
.container { display: grid; }
}
Progressive enhancement strategy:
<!-- Layer 1: Works in all browsers — semantic HTML -->
<form action="/search" method="GET">
<input type="text" name="q" placeholder="Search...">
<button type="submit">Search</button>
</form>
<!-- Layer 2: Enhanced with CSS — visual improvements -->
<link rel="stylesheet" href="search.css">
<!-- Layer 3: Enhanced with JS — async search, autocomplete -->
<script type="module" src="search-enhanced.js"></script>
Polyfills and transpilation strategy:
// browserslist config (.browserslistrc)
// > 0.5%
// last 2 versions
// not dead
// not ie 11
<!-- Differential loading: modern browsers get ES modules -->
<script type="module" src="app.modern.js"></script>
<!-- Legacy browsers get transpiled bundle -->
<script nomodule src="app.legacy.js"></script>
Key tools for a tech lead's compatibility workflow:
| Tool | Purpose |
|---|---|
| caniuse.com | Check feature browser support |
| Browserslist | Define target browsers consistently |
| Babel | Transpile modern JS for older browsers |
| PostCSS / Autoprefixer | Add CSS vendor prefixes automatically |
| Polyfill.io | Serve polyfills based on the request UA |
| BrowserStack / Percy | Cross-browser visual testing |
span tag and div tag?The primary difference between div and span tag is their default behavior. By default, a <div> is a block-level-element and a <span> is an inline element.
<div> is a block level element which means it will render it on it's own line with a width of a 100% of the parent element.<span> is an inline element which means it will render on the same line as the previous element, if it is also an inline element, and it's width will be determined by it's content.<div>Demo Text, with <span>some other</span> text.</div>
In HTML, optional closing tags are tags where the browser automatically closes them when it encounters a new tag, so the end tag is not required.
Common examples: <p>, <li>, <td>, <tr>, <th>, <html>, <body>
The full list of optional tags includes:
| Tag | Tag | Tag |
|---|---|---|
<area> |
<head> |
<option> |
<base> |
<hr> |
<p> |
<body> |
<html> |
<param> |
<br> |
<img> |
<rp> |
<caption> |
<input> |
<rt> |
<col> |
<li> |
<source> |
<colgroup> |
<link> |
<tbody> |
<dd> |
<meta> |
<td> |
<dt> |
<optgroup> |
<tfoot> |
<embed> |
<th>, <thead>, <tr>, <track>, <wbr> |
For example, both of these are valid:
<!-- With closing tag -->
<p>Hello World</p>
<p>Second paragraph</p>
<!-- Without closing tag — browser closes <p> automatically -->
<p>Hello World
<p>Second paragraph
In HTML5 it is not strictly necessary to close certain HTML tags. The tags that aren't required to have specific closing tags are called “self closing” tags.
An example of a self closing tag is something like a line break (<br />) or the meta tag (<meta>). This means that the following are both acceptable:
<meta charset="UTF-8">
...
<meta charset="UTF-8" />
<h1>, <p>, <ul>, <ol>, <li>,<span>, <a>, <strong>, <i>, <img>Semantic elements: clearly describes its meaning to both the browser and the developer.
For example: <form>, <table>, <article>, <aside>, <details>, <figcaption>, <figure>, <footer>, <header>, <main>, <mark>, <nav>, <section>, <summary>, <time> clearly defines its content.
Non-semantic elements: <div> and <span> tells nothing about its content.
main element?The HTML <main> element represents the dominant content of the <body> of a document. The main content area consists of content that is directly related to or expands upon the central topic of a document, or the central functionality of an application.
<main role="main">
<p>Geckos are a group of usually small, usually nocturnal lizards.
They are found on every continent except Australia.</p>
<p>Many species of gecko have adhesive toe pads which enable them to climb walls and even windows.</p>
</main>
Note: A document mustn't have more than one <main> element that doesn't have the hidden attribute specified.
<section>, <article>, <aside>, <nav>, <header>, <footer> and how should each be used in structuring html markup?<header> is used to contain introductory and navigational information about a section of the page. This can include the section heading, the author's name, time and date of publication, table of contents, or other navigational information.
<article> is meant to house a self-contained composition that can logically be independently recreated outside of the page without losing it's meaning. Individual blog posts or news stories are good examples.
<section> is a flexible container for holding content that shares a common informational theme or purpose.
<footer> is used to hold information that should appear at the end of a section of content and contain additional information about the section. Author's name, copyright information, and related links are typical examples of such content.
section, div or article?<section>, group of content inside is related to a single theme, and should appear as an entry in an outline of the page. It's a chunk of related content, like a subsection of a long article, a major part of the page (eg the news section on the homepage), or a page in a webapp's tabbed interface. A section normally has a heading (title) and maybe a footer too.
<article>, represents a complete, or self-contained, composition in a document, page, application, or site and that is, in principle, independently distributable or reusable, e.g. in syndication. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, an interactive widget or gadget, or any other independent item of content.
<div>, on the other hand, does not convey any meaning, aside from any found in its class, lang and title attributes.
<header> elements? What about <footer> elements?Yes, header elements can be used multiple times in documents. A <header> tag must be present for all articles, sections, and pages, although a <footer> tag is not necessary.
From W3C standards
A header element is intended to usually contain the section\'s heading (an h1–h6 element or an hgroup
element), but this is not required. The header element can also be used to wrap a section\'s table of
contents, a search form, or any relevant logos.
The footer element represents a footer for its nearest ancestor sectioning content or sectioning root
element. A footer typically contains information about its section such as who wrote it, links to related
documents, copyright data, and the like.
1. Physical Tags:
Physical tags are used to indicate how a particular character is to be formatted. Any physical style tag may contain any item allowed in text, including conventional text, images, line breaks, etc.
Example:
| Tags | Description |
|---|---|
<sup> |
Superscript is usually used for showing elements above base-line |
<sub> |
The subscript is used for alternate baseline. |
<i> |
An Italic tag is used to define a text with a special meaning. |
<big> |
Big tag increase the font size by 1 (Note: You can not use the big tag in HTML 5) |
<small> |
A small tag defines the small text, and it is used while writing copyright. |
<b> |
Bold increases the importance of the text because bold tag covert the text into bold size. |
<u> |
It is used to underline the text. |
<tt> |
Teletype text gives the default font-family which is monospace. |
<strike> |
It is an editing markup that tells the reader to ignore the text passage. |
2. Logical Tags:
Logical tags are used to tell the browser what kind of text is written inside the tags. Logical tags are also known as Structural tags because they specify the structure of the document. Logical tags are used to indicate to the visually impaired person that there is something more important in the text or to emphasize the text ie, logical tags can be used for styling purposes as well as to give special importance to text content.
Example:
| Tags | Description |
|---|---|
<abbr> |
Defines the abbreviation of text. |
<acronym> |
Defines the acronym. |
<address> |
Contact information of a person or an organization. |
<cite> |
Defines citation. It displays the text in italic format. |
<code> |
Defines the piece of computer code. |
<blockquote> |
Defines a long quotation. |
<del> |
Defines the deleted text and is used to mark a portion of text which has been deleted from the document. |
<dfn> |
Defines the definition element and is used to representing a defining instance in HTML. |
<ins> |
Defines inserted text. |
<kbd> |
Defines keyboard input text. |
<pre> |
Defines the block of preformatted text which preserves the text spaces, line breaks, tabs, and other formatting characters which are ignored by web browsers. |
<q> |
Defines the short quotation. |
<samp> |
Defines the sample output text from a computer program. |
<strong> |
Defines strong text i.e. show the importance of the text. |
<var> |
Defines the variable in a mathematical equation or in the computer program. |
The <mark> HTML element represents text which is marked or highlighted for reference or notation purposes, due to the marked passage's relevance or importance in the enclosing context.
Example:
<p>Search results for "salamander":</p>
<p>Several species of <mark>salamander</mark> inhabit the Pacific Northwest.</p>
Note:
By default, browsers render <mark> with a yellow background.
Attributes are defined by HTML. Properties are accessed from DOM (Document Object Model) nodes.
Example:
<input id="inputId" type="text" value="Hello World!" />
The value property reflects the current text-content inside the input box, whereas the value attribute contains the initial text-content of the value attribute from the HTML source code
Difference between HTML attributes and DOM properties:
| Attribute | Property |
|---|---|
| Attributes are defined by HTML. | Properties are defined by the DOM. |
| The value of an attribute is constant. | The value of a property is variable. |
| These are used to initialize the DOM properties. | No such job defined. |
An optional tag is an HTML tag whose closing (or sometimes opening) tag can be omitted because the browser automatically closes it when it encounters the next element.
Example:
<!-- Both of these are valid HTML -->
<!-- With closing tags -->
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
<!-- Without closing tags — browser auto-closes <li> -->
<ul>
<li>Item 1
<li>Item 2
</ul>
Common optional tags
| Tag | When it auto-closes |
|---|---|
<p> |
When another block element starts |
<li> |
When another <li> or parent closes |
<td>, <th> |
When another cell or row starts |
<tr> |
When another <tr> starts |
<html>, <body>, <head> |
Always optional |
Full list of optional tags
<area>, <base>, <body>, <br>, <caption>, <col>, <colgroup>, <dd>, <dt>, <embed>, <head>, <hr>, <html>, <img>, <input>, <li>, <link>, <meta>, <optgroup>, <option>, <p>, <param>, <rp>, <rt>, <source>, <tbody>, <td>, <tfoot>, <th>, <thead>, <tr>, <track>, <wbr>
Note: While omitting these tags is technically valid per the HTML spec, it's generally considered best practice to include closing tags for readability and consistency, especially in team environments.
An HTML preprocessor is a tool that lets you write HTML in an extended syntax with features like variables, loops, conditionals, and mixins — then compiles it down to standard HTML that browsers can read.
Why Use One?
Popular HTML Templating Languages
The key distinction from plain HTML is server-side rendering of dynamic data — the preprocessor fills in variables, loops through data, and outputs fully-formed HTML before it ever reaches the browser.
The default text direction in HTML is left-to-right. However, when developing web content and applications, we may need to set it to right-to-left, for instance, to cater for languages such as Arabic, Hebrew, Pashto, Persian, Urdu, and Sindhi.
We can set text direction in HTML in one of two ways:
Example:
<!-- Syntax -->
<element dir="ltr|rtl|auto">
<!-- Example -->
<textarea dir="rtl"></textarea>
Attribute Values:
| Value | Description |
|---|---|
| ltr | Default. Left-to-right text direction |
| rtl | Right-to-left text direction |
| auto | Let the browser figure out the text direction, based on the content |
The <small> HTML element represents side-comments and small print, like copyright and legal text, independent of its styled presentation. By default, it renders text within it one font-size smaller, such as from small to x-small.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Small Element</title>
</head>
<style>
small {
font-size: .7em
}
</style>
<body>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
<hr>
<p><small>The content is licensed under a W3C License.</small></p>
</body>
</html>
<section> and <div>?The <section> tag creates independent sections within a webpage having logically connected content. And the <div> tag is an empty container specifying a division or a section.
The <section> Element
According to the W3C specification, the <section> tag means that the content inside this element is grouped. In other words, the content relates to a single theme. It must be an entry in the outline of the page.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Section Tag Example</title>
</head>
<body>
<h1>W3Docs</h1>
<section>
<h2>W3Docs Sections</h2>
<ul>
<li>Books</li>
<li>Quizzes</li>
<li>Snippets</li>
</ul>
</section>
<section>
<h3>Books</h3>
<p>Learn HTML</p>
<p>Learn CSS</p>
<p>Learn Javascript</p>
</section>
</body>
</html>
The <div> Element
The <div> element only represents its child elements and doesn't have a special meaning. It can be used with the lang, title, and class attributes to add semantics that is common to a group of consecutive elements. This element can also be used in a <dl> tag and wrap groups of <dt> and <dd> elements.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Div Tag Example</title>
<style>
div {
background-color: #87f5b3
}
</style>
</head>
<body>
<h1>Example</h1>
<div>
<h2>A heading in a <div> tag.</h2>
<p>Some text in a <div> tag.</p>
</div>
<p>Here is some other text in a <p> tag.</p>
</body>
</html>
HTML events are actions or occurrences that happen in the browser — triggered by the user or by the browser itself. JavaScript can listen for these events and execute code in response.
Events can originate from:
How to handle events:
1. Inline HTML attribute (not recommended):
<button onclick="alert('Clicked!')">Click Me</button>
2. DOM property:
<button id="btn">Click Me</button>
<script>
document.getElementById("btn").onclick = function() {
alert("Clicked!");
};
</script>
3. addEventListener (recommended):
<button id="btn">Click Me</button>
<script>
document.getElementById("btn").addEventListener("click", function(event) {
console.log("Button clicked!", event);
});
</script>
addEventListener is preferred because it allows multiple listeners on the same element and provides cleaner separation of concerns.
HTML events are grouped into the following categories:
| Category | Events |
|---|---|
| Mouse Events | click, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, contextmenu |
| Keyboard Events | keydown, keyup, keypress (deprecated) |
| Form Events | submit, reset, change, input, focus, blur, focusin, focusout |
| Window / Document Events | load, DOMContentLoaded, unload, beforeunload, resize, scroll |
| Clipboard Events | copy, cut, paste |
| Drag & Drop Events | dragstart, drag, dragenter, dragover, dragleave, drop, dragend |
| Media Events | play, pause, ended, volumechange, timeupdate, canplay |
| Touch Events | touchstart, touchmove, touchend, touchcancel |
| Pointer Events | pointerdown, pointermove, pointerup, pointerenter, pointerleave |
| Animation Events | animationstart, animationend, animationiteration |
| Transition Events | transitionstart, transitionend |
When an event occurs on a nested element, it propagates through the DOM in two phases:
1. Capturing phase (top → target)
The event travels from the document root down to the target element.
2. Bubbling phase (target → top) After reaching the target, the event bubbles back up through its ancestors.
Capturing: document → html → body → div → button
Bubbling: button → div → body → html → document
Example:
<div id="parent">
<button id="child">Click Me</button>
</div>
<script>
document.getElementById("parent").addEventListener("click", () => {
console.log("Parent clicked");
});
document.getElementById("child").addEventListener("click", () => {
console.log("Child clicked");
});
// Output on button click:
// "Child clicked"
// "Parent clicked" ← bubbles up
</script>
Controlling propagation:
// Stop the event from bubbling further
event.stopPropagation();
// Stop bubbling AND prevent other listeners on the same element
event.stopImmediatePropagation();
Using capturing phase (pass true as the third argument):
element.addEventListener("click", handler, true); // capturing
element.addEventListener("click", handler, false); // bubbling (default)
Event delegation is a technique where a single event listener is attached to a parent element instead of adding listeners to each child element individually. It leverages event bubbling to handle events from child elements.
Why use it:
Example without delegation (inefficient):
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<script>
// Attaches a listener to EVERY li
document.querySelectorAll("li").forEach(li => {
li.addEventListener("click", () => console.log(li.textContent));
});
</script>
Example with delegation (efficient):
<ul id="list">
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<script>
// One listener on the parent handles all li clicks
document.getElementById("list").addEventListener("click", function(event) {
if (event.target.tagName === "LI") {
console.log(event.target.textContent);
}
});
</script>
Dynamic elements also work because the parent listener is already in place when new <li> elements are added.
event.preventDefault() and event.stopPropagation()?| Method | Purpose |
|---|---|
event.preventDefault() |
Prevents the browser's default action for the event |
event.stopPropagation() |
Prevents the event from bubbling up (or capturing down) the DOM |
preventDefault() examples:
// Prevent form submission
form.addEventListener("submit", function(event) {
event.preventDefault();
// validate before submitting
});
// Prevent link navigation
link.addEventListener("click", function(event) {
event.preventDefault();
// handle navigation manually
});
// Prevent right-click context menu
document.addEventListener("contextmenu", function(event) {
event.preventDefault();
});
stopPropagation() example:
document.getElementById("child").addEventListener("click", function(event) {
event.stopPropagation(); // parent\'s click listener will NOT fire
console.log("Child only");
});
They are independent — calling one does not affect the other. You can call both if needed.
mouseenter and mouseover events?Both fire when the mouse cursor enters an element, but they differ in how they handle child elements:
| Event | Fires on child hover? | Bubbles? |
|---|---|---|
mouseover |
Yes — re-fires when entering a child | Yes |
mouseenter |
No — fires only when entering the element itself | No |
Example:
<div id="parent" style="padding: 20px; background: lightblue;">
Parent
<span id="child" style="background: coral; padding: 5px;">Child</span>
</div>
<script>
document.getElementById("parent").addEventListener("mouseover", () => {
console.log("mouseover fired"); // fires when entering parent AND child
});
document.getElementById("parent").addEventListener("mouseenter", () => {
console.log("mouseenter fired"); // fires ONLY when entering parent
});
</script>
Moving the cursor from the parent into the child element:
mouseover fires again (because it bubbles from the child)mouseenter does not fire againSimilarly, mouseleave (no bubbling) vs mouseout (bubbles).
DOMContentLoaded and load events?| Event | Fires when |
|---|---|
DOMContentLoaded |
HTML is fully parsed and DOM is ready (CSS, images, and subframes may still be loading) |
load |
Everything on the page has fully loaded — HTML, CSS, images, scripts, iframes |
Example:
<script>
// DOM is ready — safe to query elements
document.addEventListener("DOMContentLoaded", function() {
console.log("DOM ready");
document.getElementById("btn").style.color = "red";
});
// All resources fully loaded
window.addEventListener("load", function() {
console.log("Page fully loaded");
// image dimensions are now available, etc.
});
</script>
When to use which:
DOMContentLoaded for most DOM manipulation scripts — it fires earlier, making the page feel faster.load only when you need fully loaded resources (e.g., reading image dimensions, third-party widgets).Placing
<script>tags at the bottom of<body>is an alternative toDOMContentLoadedthat achieves a similar result.
event object and what are its commonly used properties?When an event fires, the browser automatically passes an event object to the handler. It contains details about the event and the element it occurred on.
Commonly used properties:
| Property / Method | Description |
|---|---|
event.type |
The event type (e.g., "click", "keydown") |
event.target |
The element that triggered the event |
event.currentTarget |
The element the listener is attached to |
event.bubbles |
true if the event bubbles |
event.cancelable |
true if preventDefault() can stop the default action |
event.timeStamp |
Time (ms) when the event was created |
event.preventDefault() |
Cancels the default browser action |
event.stopPropagation() |
Stops event from bubbling/capturing further |
Mouse event properties:
| Property | Description |
|---|---|
event.clientX / clientY |
Cursor position relative to the viewport |
event.pageX / pageY |
Cursor position relative to the page |
event.button |
Mouse button pressed (0=left, 1=middle, 2=right) |
Keyboard event properties:
| Property | Description |
|---|---|
event.key |
The key value (e.g., "Enter", "a") |
event.code |
Physical key code (e.g., "KeyA", "ArrowUp") |
event.shiftKey / ctrlKey / altKey |
Modifier key state |
Example:
document.addEventListener("keydown", function(event) {
console.log("Key pressed:", event.key);
console.log("Ctrl held:", event.ctrlKey);
if (event.key === "Enter") {
console.log("Enter was pressed");
}
});
focus and focusin, and blur and focusout events?| Event | Bubbles? | Description |
|---|---|---|
focus |
No | Fires when an element gains focus |
focusin |
Yes | Fires when an element gains focus (bubbles) |
blur |
No | Fires when an element loses focus |
focusout |
Yes | Fires when an element loses focus (bubbles) |
Example:
<form id="form">
<input id="username" type="text" placeholder="Username">
<input id="password" type="password" placeholder="Password">
</form>
<script>
// focus/blur: attach to each input individually (does not bubble)
document.getElementById("username").addEventListener("focus", () => {
console.log("Username focused");
});
// focusin/focusout: attach to parent to catch all children (bubbles)
document.getElementById("form").addEventListener("focusin", (event) => {
console.log("Focus moved to:", event.target.id);
});
document.getElementById("form").addEventListener("focusout", (event) => {
console.log("Focus left:", event.target.id);
});
</script>
Use focusin/focusout with event delegation on a parent element; use focus/blur when listening directly on a specific element.
input and change events on form elements?| Event | Fires when |
|---|---|
input |
Immediately on every value change (each keystroke, paste, etc.) |
change |
When the element loses focus after its value has changed (or on selection for <select>) |
Example:
<input id="textbox" type="text">
<select id="dropdown">
<option value="a">Option A</option>
<option value="b">Option B</option>
</select>
<script>
const box = document.getElementById("textbox");
box.addEventListener("input", (event) => {
console.log("input:", event.target.value); // fires on every keystroke
});
box.addEventListener("change", (event) => {
console.log("change:", event.target.value); // fires on blur after change
});
// For <select>, change fires immediately on selection
document.getElementById("dropdown").addEventListener("change", (event) => {
console.log("Selected:", event.target.value);
});
</script>
Use input for real-time feedback (e.g., live search, character counters); use change for validation after the user finishes editing.
An HTML <form> element is used to collect user input and send it to a server for processing. It acts as a container for interactive controls like text fields, checkboxes, radio buttons, dropdowns, and submit buttons.
Basic structure:
<form action="/submit" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<button type="submit">Submit</button>
</form>
Key <form> attributes:
| Attribute | Description |
|---|---|
action |
URL where form data is sent on submission |
method |
HTTP method: GET (data in URL) or POST (data in body) |
enctype |
Encoding type for form data (important for file uploads) |
novalidate |
Disables browser's built-in validation |
autocomplete |
Enables/disables browser autocomplete (on/off) |
target |
Where to display the response (_self, _blank, etc.) |
GET vs POST:
GET |
POST |
|
|---|---|---|
| Data location | Appended to URL as query string | Sent in request body |
| Visibility | Visible in URL | Not visible |
| Max data size | Limited (~2000 chars) | No practical limit |
| Use case | Search, filtering | Login, registration, file upload |
| Bookmarkable | Yes | No |
HTML provides a wide range of <input> types to collect different kinds of data:
Text & Data Entry:
| Type | Description |
|---|---|
text |
Single-line plain text (default) |
password |
Masked text input |
email |
Email address (with basic format validation) |
number |
Numeric input with optional min/max/step |
tel |
Telephone number |
url |
URL with format validation |
search |
Search query field |
Date & Time:
| Type | Description |
|---|---|
date |
Date picker (yyyy-mm-dd) |
time |
Time picker (hh:mm) |
datetime-local |
Date and time (no timezone) |
month |
Month and year picker |
week |
Week picker |
Selection & Choice:
| Type | Description |
|---|---|
checkbox |
Boolean toggle (can select multiple) |
radio |
Single choice from a group |
range |
Slider for a numeric range |
color |
Color picker |
File & Action:
| Type | Description |
|---|---|
file |
File upload control |
submit |
Submits the form |
reset |
Resets all fields to default values |
button |
Generic button (no default action) |
hidden |
Hidden field (not shown to user, value sent with form) |
Example:
<input type="text" name="username" placeholder="Enter username">
<input type="email" name="email" placeholder="Enter email">
<input type="password" name="password" placeholder="Enter password">
<input type="number" name="age" min="1" max="120">
<input type="date" name="dob">
<input type="checkbox" name="agree" value="yes"> I agree
<input type="radio" name="gender" value="male"> Male
<input type="file" name="avatar" accept="image/*">
<input type="range" name="volume" min="0" max="100" step="5">
<input type="color" name="favorite_color">
<input type="hidden" name="csrf_token" value="abc123">
HTML5 provides client-side form validation without JavaScript, using built-in validation attributes. The browser checks these constraints before submitting.
Built-in validation attributes:
| Attribute | Applies to | Description |
|---|---|---|
required |
Most inputs | Field must not be empty |
minlength / maxlength |
text, email, password, etc. |
Min/max character count |
min / max |
number, date, range |
Min/max value |
step |
number, range, date |
Valid value increments |
pattern |
text, email, url, tel |
Must match a regex |
type |
<input> |
Validates format (e.g., email, url, number) |
Example:
<form>
<input type="text" name="username" required>
<input type="text" name="bio" minlength="10" maxlength="200">
<input type="number" name="age" min="18" max="100">
<!-- Pattern: 5-digit US zip code -->
<input type="text" name="zip" pattern="[0-9]{5}" title="5-digit zip code">
<input type="email" name="email">
<button type="submit">Submit</button>
</form>
CSS pseudo-classes for validation state:
input:valid { border-color: green; }
input:invalid { border-color: red; }
input:required { background: lightyellow; }
Disabling validation:
<form novalidate>...</form>
<button type="submit" formnovalidate>Save Draft</button>
Client-side validation improves UX but must never replace server-side validation — it can always be bypassed.
name and id attributes on form elements?| Attribute | Purpose | Required for forms? |
|---|---|---|
id |
Uniquely identifies the element in the DOM; used by CSS/JS and <label for=""> |
No |
name |
Identifies the field's key when form data is submitted to the server | Yes — without it, the field's value is NOT sent |
Example:
<form action="/submit" method="POST">
<label for="email">Email:</label>
<input type="email" id="email" name="user_email">
<!-- id="email" → links the <label> to this input (accessibility) -->
<!-- name="user_email" → the key sent to server: user_email=value -->
<button type="submit">Submit</button>
</form>
Submitted data: user_email=john@example.com
Key rule: id must be unique per page. Multiple elements can share the same name (e.g., radio buttons and checkboxes in a group).
<!-- Radio group: same name, different values -->
<input type="radio" name="gender" id="male" value="male">
<label for="male">Male</label>
<input type="radio" name="gender" id="female" value="female">
<label for="female">Female</label>
<label> element improve HTML forms?The <label> element provides a text description for a form control. It improves both accessibility and usability.
Two ways to associate a label with an input:
1. Using for + id (explicit — recommended):
<label for="username">Username:</label>
<input type="text" id="username" name="username">
2. Wrapping the input (implicit):
<label>
Username:
<input type="text" name="username">
</label>
Benefits:
<!-- Clicking "I agree" checks the checkbox -->
<input type="checkbox" id="agree" name="agree">
<label for="agree">I agree to the terms</label>
Always use
<label>for every form control. Placeholder text is not a substitute — it disappears when the user starts typing.
<fieldset> and <legend> element in HTML forms?<fieldset> groups related form controls together, and <legend> provides a caption for that group. They improve both structure and accessibility.
Example:
<form>
<fieldset>
<legend>Personal Information</legend>
<label for="fname">First Name:</label>
<input type="text" id="fname" name="fname" required>
<label for="lname">Last Name:</label>
<input type="text" id="lname" name="lname" required>
</fieldset>
<fieldset>
<legend>Shipping Address</legend>
<label for="street">Street:</label>
<input type="text" id="street" name="street">
<label for="city">City:</label>
<input type="text" id="city" name="city">
</fieldset>
<button type="submit">Submit</button>
</form>
Benefits:
<legend> text before each field in the group, giving context to users.disabled to <fieldset> disables all controls inside it.<fieldset disabled>
<legend>Payment (currently unavailable)</legend>
<input type="text" name="card">
</fieldset>
The <button> element has three type values that control its behavior inside a form:
| Type | Behavior |
|---|---|
type="submit" |
Submits the form (default when inside a <form>) |
type="reset" |
Resets all form fields to their initial values |
type="button" |
No default action — used with JavaScript event handlers |
Example:
<form id="myForm" action="/submit" method="POST">
<input type="text" name="username" placeholder="Username">
<button type="submit">Submit</button>
<button type="reset">Clear</button>
<button type="button" onclick="previewForm()">Preview</button>
</form>
Important: Always specify type explicitly. If type is omitted and the button is inside a <form>, it defaults to type="submit" — which can cause accidental form submissions.
<!-- This button inside a form will accidentally submit it! -->
<button onclick="toggleMenu()">Menu</button>
<!-- Fix: explicitly set type="button" -->
<button type="button" onclick="toggleMenu()">Menu</button>
autocomplete attribute in HTML forms?The autocomplete attribute controls whether the browser should automatically fill in form field values based on the user's previously entered data.
Values:
| Value | Description |
|---|---|
on |
Browser may autocomplete (default for most inputs) |
off |
Browser should not autocomplete |
| Named tokens | Tells browser what kind of data to fill in |
Example:
<!-- Disable autocomplete for entire form -->
<form autocomplete="off">
<input type="text" name="otp" placeholder="One-time code">
</form>
<!-- Enable specific autocomplete hints -->
<form autocomplete="on">
<input type="text" name="fname" autocomplete="given-name" placeholder="First name">
<input type="text" name="lname" autocomplete="family-name" placeholder="Last name">
<input type="email" name="email" autocomplete="email" placeholder="Email">
<input type="tel" name="phone" autocomplete="tel" placeholder="Phone">
<input type="text" name="address" autocomplete="street-address" placeholder="Street address">
</form>
Common autocomplete tokens:
name, given-name, family-name, email, username, new-password, current-password, tel, street-address, postal-code, country, cc-number, bday
Use
autocomplete="new-password"on password creation fields to prevent password managers from filling in the current password.
There are five new form elements in the HTML5 forms specification: <datalist>, <output>, <progress>, and <meter>.
1. Datalist Tag
Allows to attach a list of suggestions to a text input element. As soon as the user begins to type in the text field, the list of suggestions appears and the user can choose from the suggestions with the mouse.
<p>Enter your favorite browser name:</p>
<input type="text" list="browsers" name="favorite_browser">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Internet Explorer">
<option value="Opera">
<option value="Safari">
</datalist>
2. Meter Tag
Indicates a numeric value that falls within a range. The tag supports a number of attributes:
value: If you don't specify a value, the first numeric value inside the <meter></meter> pair becomes the value.
<p>Disk Usage: <meter value="0.2">20%</meter></p>
<p>Total Score: <meter value="6" min="0" max="10">6 out of 10</meter></p>
<p>Pollution Level: <meter low="60" high="80" max="100" value="85">Very High</meter></p>
3. Output Tag
It indicates a section of the page that can be modified by a script (usually JavaScript).
<form oninput="result.value=parseInt(a.value)+parseInt(b.value)">
<input type="range" id="a" value="50"> +
<input type="number" id="b" value="100"> =
<output name="result" for="a b"></output>
</form>
4. Progress Tag
Indicates how much of a task has been completed (often marked as a percentage). It is expected to be modified through JavaScript code.
<p>Progress: <progress id="bar" value="0" max="100"><span>0</span>%</progress></p>
<script type="text/javascript">
var i = 0;
var progressBar = document.getElementById("bar");
function countNumbers() {
if(i < 100) {
i = i + 1;
progressBar.value = i;
// For browsers that don\'t support progress tag
progressBar.getElementsByTagName("span")[0].textContent = i;
}
// Wait for sometime before running this script again
setTimeout("countNumbers()", 100);
}
countNumbers();
</script>
| Sl.No | Element | Description |
|---|---|---|
| 01. | color | Gives the end user a native color picker to choose a color. |
| 02. | date | Offers a datepicker. |
| 03. | datetime | An element to choose both date and time. |
| 04. | datetime-local | An element to choose both date and time, with local settings support. |
| 05. | A field for entering e-mail address(es). | |
| 06. | month | Choose a full month. |
| 07. | number | Picking a number. |
| 08. | range | Offers a slider to set to a certain value/position. |
| 09. | search | A field for search queries. |
| 10. | tel | Choosing a telephone number. |
| 11. | time | Input a certain time. |
| 12. | url | Entering a URL. |
| 13. | week | Picking a specific week. |
Example:
<input type="color" value="#b97a57">
<input type="date" value="2020-06-08">
<input type="datetime" value="2020-06-09T20:35:34.32">
<input type="datetime-local" value="2020-06-09T22:41">
<input type="email" value="robert@robertnyman.com">
<input type="month" value="2020-06">
<input type="number" value="4">
<input type="range" value="15">
<!-- Note: If not set, default attribut
learning-zone/html-basics is a public repo on GitHub by learning-zone. HTML Basics ( HTML-5 ).
It declares no license on GitHub. Public does not mean open source: without a license, nobody is granted the right to reuse it.
Its maker tagged it for macOS. That is declared by the maker; Take My Repo has not tested it.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-05-02. GitHub counts 0 open issues and pull requests. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Reverse engineer anything with agents, from app behavior down to native binaries.
The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
An introduction to new latest meaningful HTML5 semantic tags like HEADER, SECTION, FOOTER, ARTICLE, ASIDE, NAV, and accessibility WAI-ARIA
Coding articles to level up your development skills
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/learning-zone/html-basicsTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.