Blog Post
This is a semantic article element.
Welcome to the LearnX HTML course — your complete guide to building modern, semantic, and accessible web pages using HTML5.
HTML (HyperText Markup Language) provides the structure of web pages. It tells the browser what each piece of content is — such as headings, paragraphs, images, or links.
In this course, you’ll progress from the basics to advanced topics like semantic layout, forms, and APIs, with practical examples along the way.
<tag>Content</tag>
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Welcome to LearnX</h1>
<p>This is my first HTML page.</p>
</body>
</html>
HTML is the standard language used to create web pages and applications. It describes the structure of content using elements and tags.
Every website you visit is built on HTML. It works together with CSS for styling and JavaScript for interactivity.
<element>Content</element>
<h1>Hello World</h1>
<p>HTML is easy to learn.</p>
To write HTML, you need a text editor. Editors range from simple tools to advanced development environments with helpful features like auto-completion and live preview.
Beginners can start with basic editors like Notepad, but modern editors provide syntax highlighting, error detection, and extensions that make development faster and easier.
Choosing the right editor depends on your workflow, but most developers prefer lightweight tools with strong plugin ecosystems.
Open editor → Create .html file → Write code → Save → Open in browser
<h1>Editing HTML</h1>
<p>This file was created using a code editor.</p>
A basic HTML document includes essential elements that define the page structure such as the document type, head, and body.
Understanding the basic structure is the first step to building any webpage. This skeleton ensures browsers interpret your content correctly.
<!DOCTYPE html>
<html>
<head></head>
<body></body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Basic Page</title>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
HTML elements are the building blocks of web pages. They define structure and meaning using opening and closing tags.
Each element has a specific purpose, such as headings, paragraphs, or images. Nesting elements correctly ensures proper rendering.
<tag>Content</tag>
<p>This is a paragraph element.</p>
Attributes provide additional information about elements. They are always written inside the opening tag.
Attributes allow you to add styles, identifiers, and metadata to elements. They are essential for linking CSS and JavaScript.
<element attribute="value">
<a href="https://example.com">Visit Site</a>
Headings define the structure and hierarchy of content on a page. They range from h1 (most important) to h6 (least important).
Headings help both users and search engines understand your content structure. They should follow a logical order without skipping levels.
<h1>Main Title</h1>
Main Heading
Sub Heading
Section Heading
Paragraph elements are used to display blocks of text content on a webpage.
Breaking content into paragraphs improves readability and helps users scan information quickly.
<p>Text content</p>
This is a paragraph.
This is another paragraph.
Styles allow you to change the appearance of elements using CSS properties like color, font, and spacing.
While inline styles are useful for quick changes, external CSS files provide better scalability and maintainability.
<p style="color:red;">Text</p>
Styled text
Formatting elements help emphasize text by making it bold, italic, highlighted, or marked as important.
Formatting is not just visual — tags like strong and em provide meaning that assistive technologies can interpret.
<strong>Important</strong>
Bold text
Italic text
Quotation elements are used to mark up quotes, citations, and references.
These elements help browsers and assistive tools understand quoted content.
<blockquote>Quote</blockquote>
Learning never exhausts the mind.
Comments are notes in your code that are not displayed in the browser. They help explain and organize code.
Good comments improve maintainability and make it easier to understand code later.
<!-- Comment -->
Visible text
Colors can be applied using names, HEX, RGB, or HSL values to style text, backgrounds, and borders.
Choosing accessible color combinations improves readability and user experience.
style="color:#ff0000;"
Red text
CSS (Cascading Style Sheets) controls the visual appearance of HTML elements, including layout, colors, and typography.
Using external stylesheets is the recommended approach for scalable projects because it keeps styling consistent across pages.
<link rel="stylesheet" href="styles.css">
Styled with CSS
Links allow users to navigate between pages, sections, or external resources.
Links are essential for navigation and building interconnected web experiences.
<a href="url">Link Text</a>
Images enhance visual communication and engagement on web pages.
The alt attribute improves accessibility and helps search engines understand images.
<img src="image.jpg" alt="description">
A favicon is a small icon displayed in the browser tab representing your website.
Favicons help users quickly identify your site among multiple open tabs.
<link rel="icon" href="favicon.ico">
The <title> element defines the title of the document. The title must be text-only, and
it is shown in the browser's title bar or in the page's tab.
A good title helps users understand what the page is about before they even click on it.
<title>Page Title</title>
<head>
<title>HTML Tutorial - LearnX</title>
</head>
Tables are used to display structured data in rows and columns.
Tables should not be used for layout; they are meant only for data representation.
<table>...</table>
Name Age
Ana 22
Lists group related items together in an ordered or unordered format.
Lists improve readability and structure content logically.
<ul><li>Item</li></ul>
- HTML
- CSS
HTML elements are categorized as block-level or inline based on how they appear in the layout.
Block elements start on a new line and create structure, while inline elements flow within text content.
<div>Block</div> <span>Inline</span>
Block element
Inline element
The div element is a container used to group content and apply styles or layout.
Divs are flexible and can hold any type of content, making them essential for page structure.
<div>Content</div>
Grouped content
Classes allow you to apply styles or scripts to multiple elements at once.
Classes are essential for CSS styling and JavaScript targeting.
<p class="note">Text</p>
Highlighted text
The id attribute uniquely identifies an element on a page.
Ids are useful for linking to specific sections or applying unique styles.
<div id="header"></div>
Section 1
Iframes embed another webpage or content within your page.
Iframes are commonly used to embed third-party content safely.
<iframe src="url"></iframe>
JavaScript makes HTML pages dynamic and interactive. You can embed scripts directly in HTML using
the <script> tag, or link to an external JavaScript file.
JavaScript runs in the browser and can modify page content, handle user actions, and communicate with
servers. Best practice is to place scripts at the bottom of the page or use the defer
attribute.
<script> // JavaScript code here </script>
<button onclick="showMessage()">Click Me</button>
<script>
function showMessage() {
alert("Hello from JavaScript!");
}
</script>
onclick — Event attribute that runs JavaScript when the button is clicked<script> — Defines a block of JavaScript codealert() — Displays a message dialog in the browserdefer attribute for better page load performanceFile paths specify the location of resources like images, stylesheets, scripts, and other files relative to the current document or as absolute URLs.
Using relative paths keeps projects portable across different environments and servers.
| Path | Description |
|---|---|
images/photo.jpg |
Relative — same folder |
../images/photo.jpg |
Relative — one folder up |
/images/photo.jpg |
Absolute from root |
https://example.com/img.jpg |
Full absolute URL |
<img src="images/photo.jpg" alt="description">
<img src="https://via.placeholder.com/150" alt="Sample">
<a href="../index.html">Go to Home</a>
The <head> element contains metadata and resources that define how a page behaves and appears.
Proper use of the head improves search engine ranking, accessibility, and page loading speed.
<head> ... </head>
My Page
Layout elements define the structure of a web page using semantic tags.
Modern layouts rely on semantic structure combined with CSS Flexbox or Grid for positioning.
<header>...</header>
Header
Main Content
Responsive design ensures your website looks good on all screen sizes.
Modern websites must adapt to phones, tablets, and desktops. HTML works with CSS media queries to achieve responsiveness.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Semantic HTML uses meaningful tags that clearly describe the purpose of content, improving accessibility, SEO, and code readability.
Instead of relying only on generic containers, semantic elements like <article>, <section>, and <nav> provide context about what each part of the page represents.
Using semantic markup makes projects easier to maintain and aligns with modern HTML5 standards.
<article>Content</article>
Blog Post
This is a semantic article element.
HTML contains several elements for defining user input and computer code.
<code> for computer code<kbd> for keyboard input<samp> for computer output<var> for variables<pre> for preformatted textThese elements are used to display code snippets, keyboard shortcuts, and technical documentation clearly.
<code>x = 5;</code>
x = 5; y = 6; z = x + y;
<pre> to preserve whitespace<pre> and <code> for multi-line blocksSemantic HTML uses meaningful tags that clearly describe the purpose of content, improving accessibility, SEO, and code readability.
Instead of relying only on generic containers, semantic elements like <article>, <section>, and <nav> provide context about what each part of the page represents.
<article>Content</article>
Blog Post
This is a semantic article element.
A style guide ensures consistent and readable HTML across projects, making collaboration easier and reducing errors.
Consistent formatting helps developers quickly understand code. Teams often define their own style rules, but following common conventions improves maintainability.
Modern best practices also emphasize semantic structure and accessibility.
<element attribute="value">
Styled HTML
Consistent Formatting
Entities are used to display reserved characters or symbols that cannot be typed directly in HTML.
For example, the less-than symbol cannot be written directly because it would be interpreted as a tag. Entities solve this by encoding characters.
&entityName;
5 < 10
Copyright © 2026
HTML supports a wide range of mathematical, currency, and technical symbols using entities or Unicode.
Symbols are commonly used in finance, engineering, and documentation pages.
&#symbolCode;
€ Euro
☃ Snowman
Emojis can be added using Unicode characters, making interfaces more expressive and user-friendly.
Emojis are widely used in messaging interfaces, notifications, and social platforms.
😀
😀 Smile Emoji
🚀 Rocket Emoji
A character set defines how text is stored and displayed in a web page. UTF-8 is the standard charset because it supports almost all characters and symbols.
Without a proper charset, browsers may display garbled text. UTF-8 allows you to safely include emojis, symbols, and multilingual content.
<meta charset="UTF-8">
URL encoding converts characters into a format that can be safely transmitted over the internet.
Encoding prevents errors when URLs contain spaces, symbols, or non-ASCII text. Browsers often handle encoding automatically, but developers should understand how it works.
https://example.com/search?q=web%20design
XHTML is a stricter, XML-based version of HTML. Modern development mainly uses HTML5, but understanding XHTML helps you write cleaner code.
XHTML enforced strict syntax rules like lowercase tags and well-formed structure. HTML5 adopted many of these best practices while remaining developer-friendly.
<br /> (XHTML) vs <br> (HTML)
HTML allows flexible syntax.
XHTML requires self-closing tags.
Forms allow users to send data to a server. They are essential for login pages, registrations, searches, and feedback systems.
The form element acts as a container for different input controls. Each control collects specific data that is sent to a server when the form is submitted.
Forms are a core part of interactive web applications.
<form action="/submit" method="post"></form>
Form attributes control how and where form data is sent when a user submits a form.
Choosing the right attributes ensures data is handled securely and correctly. Most forms use the POST method when sending sensitive data.
<form action="/submit" method="post">
Form elements are controls that allow users to enter and select data.
Each element serves a specific purpose. Combining them creates complete forms such as registration or contact forms.
<input> <textarea> <select>
Input types define the kind of data users can enter, such as text, email, date, or password.
Using appropriate input types helps browsers display the right keyboard on mobile devices and reduces validation errors.
<input type="email">
Input attributes provide additional control over form fields such as validation rules and default values.
Attributes help guide users and ensure the correct data format is submitted.
<input type="text" required>
HTML provides built-in validation features that help ensure users enter the correct type of data before submitting a form.
Validation attributes like required, pattern, and minlength allow
developers to enforce rules directly in HTML.
<input type="email" required>
The fieldset element groups related form controls, while legend provides a caption for the group.
Using fieldsets makes forms easier to understand, especially when they contain multiple sections like billing and shipping information.
<fieldset><legend>Info</legend></fieldset>
The datalist element provides autocomplete suggestions for input fields.
Datalists are useful for suggesting common values like cities or product names while still allowing custom input.
<input list="items">
The canvas element allows you to draw graphics dynamically using JavaScript.
Canvas is commonly used for charts, animations, and interactive graphics.
<canvas id="myCanvas"></canvas>
SVG (Scalable Vector Graphics) is used to create resolution-independent graphics directly in HTML.
SVG is ideal for icons, charts, and illustrations because it remains sharp at any size.
<svg><circle /></svg>
HTML supports two powerful technologies for creating graphics on the web: Canvas (pixel-based, JavaScript-driven) and SVG (vector-based, scalable).
Choose Canvas for animations and games; choose SVG for icons, logos, and illustrations that need to be sharp at any size.
HTML5 introduced native support for embedding audio and video directly in web pages without needing plugins like Flash.
Media elements are widely supported and provide a seamless, accessible way to include rich content in your pages.
preload="metadata" to improve performanceThe <video> element embeds video content directly into a webpage with built-in browser
controls.
controls to add play/pause UIautoplay, loop, and muted<video src="file.mp4" controls></video>
<video width="400" controls>
<source src="movie.mp4" type="video/mp4">
<source src="movie.ogg" type="video/ogg">
Your browser does not support the video tag.
</video>
muted with autoplay for browser compatibilityThe <audio> element embeds sound content such as music or podcasts directly into
webpages.
controls attribute for playback UI<audio controls><source src="file.mp3"></audio>
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
<source src="audio.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
<source> elements for browser compatibilityThe <object> and <embed> elements were historically used to embed
external content like PDFs, Flash, or Java applets. Today, native HTML5 elements are preferred.
<object> embeds external resources<embed> is a self-closing void element<object data="file.pdf" type="application/pdf"></object>
<object data="document.pdf" type="application/pdf" width="500" height="400">
<p>Your browser does not support PDFs. <a href="document.pdf">Download the PDF</a></p>
</object>
<object>The easiest way to embed a YouTube video is using an <iframe> with the YouTube embed
URL.
allowfullscreen for fullscreen support<iframe src="https://www.youtube.com/embed/VIDEO_ID"></iframe>
<iframe width="560" height="315"
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
allowfullscreen>
</iframe>
?rel=0 to prevent showing unrelated videos?mute=1 for autoplay complianceHTML5 introduced several powerful browser APIs that allow JavaScript to access device features and browser capabilities directly.
These APIs make it possible to build rich, app-like experiences entirely in the browser without plugins.
The Geolocation API allows you to get the user's current geographic location with their permission.
navigator.geolocationnavigator.geolocation.getCurrentPosition(successFn);
<button onclick="getLocation()">Get My Location</button>
<p id="demo"></p>
<script>
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
document.getElementById("demo").innerHTML = "Geolocation not supported.";
}
}
function showPosition(position) {
document.getElementById("demo").innerHTML =
"Lat: " + position.coords.latitude +
"<br>Lon: " + position.coords.longitude;
}
</script>
The HTML Drag and Drop API enables elements to be dragged and dropped using mouse or touch events.
draggable="true" on source elementondragstart, ondrop, and ondragover eventsevent.dataTransfer to pass data<div draggable="true" ondragstart="drag(event)">Drag me</div>
<div id="div1" ondrop="drop(event)" ondragover="allowDrop(event)"></div>
<img id="drag1" src="img.png" draggable="true" ondragstart="drag(event)">
<script>
function allowDrop(ev) { ev.preventDefault(); }
function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); }
function drop(ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData("text");
ev.target.appendChild(document.getElementById(data));
}
</script>
event.preventDefault() in ondragover to allow droppingWeb Storage allows web applications to store data locally in the user's browser — more securely and with larger capacity than cookies.
localStorage — persists even after browser closesessionStorage — cleared when tab closeslocalStorage.setItem("key", "value");
localStorage.getItem("key");
<button onclick="saveData()">Save</button>
<button onclick="loadData()">Load</button>
<p id="result"></p>
<script>
function saveData() {
localStorage.setItem("username", "LearnX User");
alert("Saved!");
}
function loadData() {
var name = localStorage.getItem("username") || "No data found";
document.getElementById("result").innerText = name;
}
</script>
JSON.stringify() to store objectsWeb Workers let you run JavaScript in a background thread, keeping the main UI thread free and responsive.
postMessage()const worker = new Worker("worker.js");
worker.postMessage("start");
worker.onmessage = (e) => console.log(e.data);
<!-- main.html -->
<button onclick="startWorker()">Start Worker</button>
<p id="result"></p>
<script>
let w;
function startWorker() {
if (typeof(Worker) !== "undefined") {
w = new Worker("worker.js");
w.onmessage = (e) => {
document.getElementById("result").innerText = e.data;
};
}
}
</script>
<!-- worker.js file -->
<!-- postMessage("Worker is running!"); -->
worker.terminate()Server-Sent Events allow a server to push real-time updates to the browser over a persistent HTTP connection.
EventSource APItext/event-streamconst source = new EventSource("/stream");
source.onmessage = (e) => console.log(e.data);
<!-- Client-side -->
<div id="updates"></div>
<script>
const source = new EventSource("/sse-endpoint");
source.onmessage = function(e) {
document.getElementById("updates").innerHTML += e.data + "<br>";
};
</script>
<!-- Server-side (Node.js example) -->
<!-- res.setHeader("Content-Type","text/event-stream"); -->
<!-- res.write("data: Hello World\n\n"); -->
Test your HTML knowledge with these questions! Try to answer each one before revealing the answer.
alt attribute<a href="url">Link text</a>Practice makes perfect! Try these hands-on exercises to reinforce your HTML skills.
<!DOCTYPE html>
<html>
<head>
<title>Exercise Page</title>
</head>
<body>
<h1>My Page Title</h1>
<p>First paragraph goes here.</p>
<p>Second paragraph goes here.</p>
</body>
</html>
Accessible HTML ensures that your website can be used by everyone, including people with visual, auditory, motor, or cognitive disabilities.
alt text to images<label> for form inputsARIA (Accessible Rich Internet Applications) attributes add accessibility information to HTML elements:
<!-- Button with ARIA label -->
<button aria-label="Close menu">×</button>
<!-- Navigation with role -->
<nav aria-label="Main navigation">
<a href="#home">Home</a>
</nav>
<!-- Image with descriptive alt -->
<img src="chart.png" alt="Sales growth chart showing 40% increase in Q3 2025">
<!-- Accessible form -->
<label for="email">Email Address:</label>
<input type="email" id="email" name="email" required>
You have now covered all the major HTML topics. Here's a quick recap of the most important concepts:
<!DOCTYPE html>Now that you know HTML, the natural progression is:
A reference of the most commonly used HTML tags and their purpose:
| Tag | Description |
|---|---|
<!DOCTYPE> |
Defines the document type |
<html> |
Root element of an HTML page |
<head> |
Contains metadata/information for the document |
<title> |
Defines the page title (shown in browser tab) |
<body> |
Defines the document's body |
<h1>–<h6> |
Defines HTML headings |
<p> |
Defines a paragraph |
<a> |
Defines a hyperlink |
<img> |
Defines an image |
<ul> / <ol> |
Unordered / Ordered list |
<li> |
Defines a list item |
<table> |
Defines a table |
<form> |
Defines an HTML form |
<input> |
Defines an input control |
<button> |
Defines a clickable button |
<div> |
Defines a section/container (block) |
<span> |
Defines an inline container |
<header> |
Semantic header element |
<nav> |
Defines navigation links |
<main> |
Specifies the main content |
<section> |
Defines a section in a document |
<article> |
Defines self-contained content |
<aside> |
Defines content aside from main content |
<footer> |
Semantic footer element |
<strong> |
Bold text with semantic importance |
<em> |
Italic text with semantic emphasis |
<br> |
Inserts a single line break |
<hr> |
Defines a thematic change/horizontal rule |
<canvas> |
Used to draw graphics via JavaScript |
<video> |
Defines video or movie content |
<audio> |
Defines sound content |
<iframe> |
Defines an inline frame |
<script> |
Defines a client-side script |
<link> |
Links external resources (CSS, icons) |
<meta> |
Defines metadata about the document |