HTML Examples
Learn by doing. Every example below can be opened in our online editor — change the code, press Run and see the result instantly.
Open the Try it Now editor »HTML Document Structure
HTML Basics · 1 example<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My First Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first web page.</p>
</body>
</html>
The title appears in the browser tab; the heading and paragraph appear on the page.
HTML Comments
HTML Basics · 1 example<!-- This is a single-line comment -->
<p>This paragraph is visible.</p>
<!--
This is a comment
over several lines.
-->
<!-- <p>This paragraph is hidden while testing.</p> -->
<p>Only two paragraphs appear on the page.</p>
HTML Text Formatting
HTML Text & Links · 1 example<p>This is <strong>very important</strong> text.</p>
<p>I <em>really</em> like coding.</p>
<p>Don't forget to <mark>submit the form</mark>.</p>
<p>Price: <del>₹999</del> <ins>₹499</ins></p>
<p>Water is H<sub>2</sub>O and 5<sup>2</sup> = 25.</p>
<p><small>Terms and conditions apply.</small></p>
HTML Quotations
HTML Text & Links · 1 example<blockquote>
Arise, awake, and stop not till the goal is reached.
</blockquote>
<p>— Swami Vivekananda</p>
<p>My teacher said <q>practice every day</q>.</p>
<p>I learnt <abbr title="HyperText Markup Language">HTML</abbr> from <cite>AgyanAdda Tutorials</cite>.</p>
<address>
AgyanAdda, Gaya, Bihar<br>
<a href="mailto:agyanadda@gmail.com">agyanadda@gmail.com</a>
</address>
HTML Lists
HTML Text & Links · 2 examples<h3>Skills I am learning</h3>
<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>
<h3>Steps to make tea</h3>
<ol>
<li>Boil water</li>
<li>Add tea leaves and sugar</li>
<li>Add milk and boil again</li>
</ol>
<ul>
<li>Frontend
<ul>
<li>HTML</li>
<li>CSS</li>
</ul>
</li>
<li>Backend
<ul>
<li>PHP</li>
<li>MySQL</li>
</ul>
</li>
</ul>
<dl>
<dt>HTML</dt>
<dd>The structure of a web page.</dd>
<dt>CSS</dt>
<dd>The design of a web page.</dd>
</dl>
HTML Tables
HTML Text & Links · 2 examples<table border="1" cellpadding="8">
<caption>Class 10 Results</caption>
<thead>
<tr><th>Name</th><th>Maths</th><th>Science</th></tr>
</thead>
<tbody>
<tr><td>Asha</td><td>92</td><td>88</td></tr>
<tr><td>Rohit</td><td>78</td><td>85</td></tr>
</tbody>
</table>
<table border="1" cellpadding="8">
<tr>
<th>Name</th>
<th colspan="2">Phone numbers</th>
</tr>
<tr>
<td>Asha</td>
<td>98765 43210</td>
<td>91234 56789</td>
</tr>
</table>
colspan="2" makes the header cover both phone columns.
HTML Colors
HTML Text & Links · 1 example<h2 style="color: navy;">Navy heading</h2>
<p style="color: #ff6347;">Tomato text using HEX</p>
<p style="background-color: rgb(255, 235, 59); padding: 8px;">Yellow background using RGB</p>
<p style="background-color: rgba(0, 128, 0, 0.3); padding: 8px;">See-through green using RGBA</p>
HTML Block and Inline Elements
HTML Layout & Structure · 1 example<div style="background: #e3f2fd; padding: 10px;">
This is a div. It takes the full width.
</div>
<div style="background: #fce4ec; padding: 10px;">
Another div starts on a new line.
</div>
<p>
This sentence has a <span style="color: red; font-weight: bold;">red span</span> inside it,
and it stays on the same line.
</p>
HTML Classes and IDs
HTML Layout & Structure · 1 example<style>
.note { background: #fff8e1; padding: 10px; border-left: 4px solid orange; }
.important { font-weight: bold; }
#title { color: #1e3a8a; }
</style>
<h1 id="title">Classes and IDs</h1>
<p class="note">This is a note.</p>
<p class="note important">This note is also important.</p>
HTML Semantic Elements
HTML Layout & Structure · 1 example<header>
<h1>My Blog</h1>
<nav>
<a href="#">Home</a> | <a href="#">Posts</a> | <a href="#">Contact</a>
</nav>
</header>
<main>
<article>
<h2>Learning HTML in 30 days</h2>
<p>Here is how I learnt HTML step by step...</p>
</article>
<aside>
<h3>Related posts</h3>
<p>CSS basics</p>
</aside>
</main>
<footer>
<p>© 2026 My Blog</p>
</footer>
HTML Page Layout
HTML Layout & Structure · 1 example<style>
body { font-family: Arial, sans-serif; margin: 0; }
header, footer { background: #1e3a8a; color: #fff; padding: 12px; }
.wrap { display: flex; gap: 12px; padding: 12px; }
main { flex: 3; background: #f1f5f9; padding: 12px; }
aside { flex: 1; background: #fef3c7; padding: 12px; }
@media (max-width: 600px) { .wrap { flex-direction: column; } }
</style>
<header>My Website</header>
<div class="wrap">
<main>Main content goes here.</main>
<aside>Sidebar</aside>
</div>
<footer>© 2026</footer>
On small screens the media query stacks the columns.
HTML Audio
HTML Media · 1 example<audio controls>
<source src="https://www.w3schools.com/html/horse.mp3" type="audio/mpeg">
Your browser does not support audio.
</audio>
The text inside appears only in very old browsers that cannot play audio.
HTML Video
HTML Media · 2 examples<video controls width="360" poster="https://www.w3schools.com/html/pic_trulli.jpg">
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
Your browser does not support video.
</video>
<style>
video { max-width: 100%; height: auto; }
</style>
<video controls>
<source src="https://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4">
</video>
max-width: 100% keeps the video inside small screens.
HTML Iframes
HTML Media · 2 examples<iframe width="360" height="203"
src="https://www.youtube.com/embed/qz0aGYrrlhU"
title="HTML tutorial video"
loading="lazy"
allowfullscreen></iframe>
Use the "embed" link from YouTube → Share → Embed.
<iframe
src="https://www.google.com/maps?q=Gaya,Bihar&output=embed"
width="360" height="250" style="border:0;"
title="Map of Gaya" loading="lazy"></iframe>
HTML Favicon
HTML Media · 1 example<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Site</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
</head>
<body>
<p>Look at the browser tab for the icon.</p>
</body>
</html>
HTML Form Elements
HTML Forms · 1 example<form>
<fieldset>
<legend>Course enquiry</legend>
<label for="name">Name</label><br>
<input id="name" name="name" type="text"><br><br>
<label for="course">Course</label><br>
<select id="course" name="course">
<option>Web Designing</option>
<option>PHP & Laravel</option>
<option>Python</option>
</select><br><br>
<label for="msg">Message</label><br>
<textarea id="msg" name="message" rows="4" cols="30"></textarea><br><br>
<button type="submit">Send</button>
</fieldset>
</form>
HTML Form Validation
HTML Forms · 1 example<form>
<input type="text" name="name" placeholder="Full name" required minlength="3"><br><br>
<input type="email" name="email" placeholder="Email" required><br><br>
<input type="tel" name="mobile" placeholder="10-digit mobile"
pattern="[6-9][0-9]{9}" title="Enter a valid 10-digit Indian mobile number" required><br><br>
<input type="number" name="age" placeholder="Age" min="16" max="60"><br><br>
<button type="submit">Register</button>
</form>
Try pressing Register with empty or wrong values.
HTML Head Element
HTML Head & SEO · 1 example<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Learn HTML Free | AgyanAdda</title>
<meta name="description" content="Free HTML tutorial with examples you can run online.">
<link rel="stylesheet" href="style.css">
<script src="app.js" defer></script>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
defer loads the script without blocking the page.
HTML Meta Tags for SEO
HTML Head & SEO · 1 example<head>
<title>Online PHP Course in Patna | AgyanAdda</title>
<meta name="description" content="Live online PHP and Laravel training with projects, doubt sessions and certificate.">
<link rel="canonical" href="https://agyanadda.com/online-training">
<meta property="og:title" content="Online PHP Course | AgyanAdda">
<meta property="og:description" content="Learn PHP with live classes and real projects.">
<meta property="og:image" content="https://agyanadda.com/images/php-course.jpg">
<meta property="og:url" content="https://agyanadda.com/online-training">
</head>
HTML Entities and Symbols
HTML Head & SEO · 1 example<p>To make a paragraph, write <p>text</p>.</p>
<p>Fish & Chips</p>
<p>Price: ₹499 → Buy now</p>
<p>© 2026 AgyanAdda</p>
HTML Responsive Design
HTML Best Practices · 1 example<style>
img { max-width: 100%; height: auto; }
.cards { display: flex; gap: 10px; }
.card { flex: 1; background: #e0f2fe; padding: 12px; }
@media (max-width: 600px) {
.cards { flex-direction: column; }
}
</style>
<div class="cards">
<div class="card">Card 1</div>
<div class="card">Card 2</div>
<div class="card">Card 3</div>
</div>
<p>Make the window narrow — the cards stack on top of each other.</p>
HTML Accessibility
HTML Best Practices · 1 example<img src="https://www.w3schools.com/html/pic_trulli.jpg" width="200"
alt="White stone houses with cone-shaped roofs">
<p><a href="/syllabus.pdf">Download the PHP course syllabus (PDF)</a></p>
<form>
<label for="email">Email address</label>
<input id="email" type="email" name="email">
<button type="submit">Subscribe</button>
</form>
HTML Best Practices
HTML Best Practices · 1 example<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Clean HTML Example</title>
</head>
<body>
<header>
<h1>My Portfolio</h1>
</header>
<main>
<section>
<h2>About me</h2>
<p>I am learning web development.</p>
</section>
</main>
<footer>
<p>© 2026</p>
</footer>
</body>
</html>
HTML Introduction
HTML Basics · 1 example<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to AgyanAdda</h1>
<p>HTML gives a web page its structure.</p>
</body>
</html>
Change the heading text and press Run to see your change.
HTML Editors
HTML Basics · 1 example<!-- 1. Type this in Notepad or VS Code -->
<!-- 2. Save it as index.html -->
<!-- 3. Double-click the file to open it in your browser -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Saved from my editor</title>
</head>
<body>
<p>I wrote this page in a code editor.</p>
</body>
</html>
HTML Elements
HTML Basics · 2 examples<div>
<h2>My favourite fruits</h2>
<ul>
<li>Mango</li>
<li>Banana</li>
</ul>
<p>Elements can be <strong>nested</strong> inside other elements.</p>
</div>
<p>Line one<br>Line two (br has no closing tag)</p>
<hr>
<img src="https://www.w3schools.com/html/pic_trulli.jpg" alt="Houses" width="180">
br, hr and img are empty elements: they have no content and no closing tag.
HTML Attributes
HTML Basics · 1 example<a href="https://agyanadda.com" title="Visit AgyanAdda" target="_blank">Open AgyanAdda</a>
<img src="https://www.w3schools.com/html/pic_trulli.jpg" alt="Stone houses" width="200">
<p style="color: green;" id="intro" class="note">This paragraph has style, id and class attributes.</p>
<input type="text" placeholder="Your name" required>
HTML Headings
HTML Text & Links · 1 example<h1>Heading 1 — page title</h1>
<h2>Heading 2 — main section</h2>
<h3>Heading 3 — sub-section</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>
Use only one h1 per page and keep the order (h2 inside h1, h3 inside h2).
HTML Paragraphs
HTML Text & Links · 1 example<p>This is the first paragraph.</p>
<p>This is the second paragraph.
Extra spaces and new lines are ignored here.</p>
<p>Use a line break<br>to start a new line.</p>
<pre>
pre keeps spaces
and line breaks
exactly as typed.
</pre>
HTML Links
HTML Text & Links · 1 example<p><a href="https://agyanadda.com">Same tab link</a></p>
<p><a href="https://agyanadda.com/tools" target="_blank" rel="noopener">Open in a new tab</a></p>
<p><a href="mailto:agyanadda@gmail.com">Send an email</a></p>
<p><a href="tel:+919999999999">Call us</a></p>
<p><a href="#contact">Jump to contact section</a></p>
<h3 id="contact">Contact</h3>
<p>You jumped here using an id link.</p>
rel="noopener" is recommended with target="_blank" for security.
HTML Images
HTML Text & Links · 2 examples<img src="https://www.w3schools.com/html/pic_trulli.jpg"
alt="White stone houses with cone roofs" width="240" height="160">
<p>Clickable image:</p>
<a href="https://agyanadda.com">
<img src="https://www.w3schools.com/html/img_girl.jpg" alt="Go to AgyanAdda" width="120">
</a>
<figure>
<img src="https://www.w3schools.com/html/pic_trulli.jpg" alt="Trulli houses" width="240">
<figcaption>Fig 1. Traditional houses in Italy.</figcaption>
</figure>
HTML Forms
HTML Forms · 1 example<form action="/login" method="post">
<label for="email">Email</label><br>
<input id="email" type="email" name="email" required><br><br>
<label for="pass">Password</label><br>
<input id="pass" type="password" name="password" required><br><br>
<button type="submit">Log in</button>
</form>
method="post" sends data in the request body — always use it for passwords.
HTML Input Types
HTML Forms · 1 example<form>
<input type="text" placeholder="Name"><br><br>
<input type="email" placeholder="Email"><br><br>
<input type="number" min="1" max="10" placeholder="1 to 10"><br><br>
<input type="date"><br><br>
<input type="color" value="#1e3a8a"><br><br>
<input type="range" min="0" max="100"><br><br>
<label><input type="checkbox"> I agree</label><br>
<label><input type="radio" name="g"> Male</label>
<label><input type="radio" name="g"> Female</label><br><br>
<input type="file"><br><br>
<input type="submit" value="Submit">
</form>
Radio buttons with the same name let you choose only one.