agyanadda@gmail.com

HTML Examples

39 examples 39 you can try online 33 topics

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
Example — A complete HTML page HTML
<!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
Example — Single and multi-line comments HTML
<!-- 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
Example — Formatting tags HTML
<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
Example — Quotes and abbreviations HTML
<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
Example — Unordered and ordered lists HTML
<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>
Example — Nested and description lists HTML
<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
Example — A marks table HTML
<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>
Example — Merging cells HTML
<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
Example — Text and background colors HTML
<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
Example — div vs span HTML
<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
Example — Classes and IDs with CSS HTML
<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
Example — A semantic page layout HTML
<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>&copy; 2026 My Blog</p>
</footer>

HTML Page Layout

HTML Layout & Structure · 1 example
Example — Two-column layout with Flexbox HTML
<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>&copy; 2026</footer>

On small screens the media query stacks the columns.

HTML Audio

HTML Media · 1 example
Example — Audio player HTML
<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
Example — Video player HTML
<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>
Example — Responsive video HTML
<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
Example — Embed a YouTube video HTML
<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.

Example — Embed a Google Map HTML
<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
Example — Add a favicon HTML
<!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
Example — A complete enquiry form HTML
<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 &amp; 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
Example — Validated sign-up form HTML
<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
Example — A well-filled head HTML
<!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
Example — SEO and social meta tags HTML
<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
Example — Showing code and symbols HTML
<p>To make a paragraph, write &lt;p&gt;text&lt;/p&gt;.</p>
<p>Fish &amp; Chips</p>
<p>Price: &#8377;499 &nbsp; &rarr; &nbsp; Buy now</p>
<p>&copy; 2026 AgyanAdda</p>

HTML Responsive Design

HTML Best Practices · 1 example
Example — Responsive basics HTML
<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
Example — Accessible image, link and form HTML
<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
Example — Clean, well-structured page HTML
<!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>&copy; 2026</p>
  </footer>
</body>
</html>

HTML Introduction

HTML Basics · 1 example
Example — Your first HTML page HTML
<!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
Example — Write, save and open HTML
<!-- 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
Example — Nested elements HTML
<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>
Example — Empty elements HTML
<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
Example — Common attributes HTML
<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
Example — All six headings HTML
<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
Example — Paragraphs, line breaks and pre HTML
<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 Images

HTML Text & Links · 2 examples
Example — Images with alt, size and link HTML
<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>
Example — Figure with caption HTML
<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
Example — A simple login form HTML
<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
Example — Common input types HTML
<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.