HTMLBasicsbeginner

HTML Tutorial for Beginners with Examples

Learn HTML from your first file to forms and semantic pages, with working examples and practice projects.

Published
TL;DR – Quick Answer

HTML gives a web page its content and structure. Start with headings, paragraphs, links, images and lists, then learn tables, forms and semantic tags. You need only a text editor and a browser.

On This Page

HTML is the language that gives a web page its content and structure. This HTML tutorial starts with an empty file and ends with a small page that has text, links, a table and a form. You need only a text editor and a browser.

HTML is a markup language, not a programming language. You label each piece of content: this is a heading, this is a paragraph, this is a button. The browser reads the labels and draws the page.

HTML tutorial: make your first page

Create a file named index.html, paste this code and open the file in your browser.

<!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, Hyderabad</h1>
  <p>I am learning HTML today.</p>
</body>
</html>

You should see a large heading and one line of text. The words "My first page" appear on the browser tab, not on the page.

Line What it does
<!DOCTYPE html> Tells the browser to use modern HTML rules
<html lang="en"> Wraps the whole page and states its language
<head> Holds information about the page
<meta charset="UTF-8"> Lets the page show all languages and symbols
<meta name="viewport" ...> Makes the page fit a phone screen
<body> Holds everything the visitor sees

Tags, elements and attributes

Beginners often mix up these three words. Look at one link:

<a href="/learn/css-tutorial">Read the CSS lesson</a>
  • Tag: <a> opens the link and </a> closes it.
  • Element: the opening tag, the text and the closing tag together.
  • Attribute: extra information inside the opening tag. Here it is href, which says where the link goes.

Some elements have no content, so they have no closing tag. Examples are <img>, <br>, <input> and <meta>. They are called void elements.

Elements can sit inside other elements. Close them in the reverse order you opened them.

<!-- Correct -->
<p>This is <strong>important</strong>.</p>

<!-- Wrong: closed in the wrong order -->
<p>This is <strong>important.</p></strong>

Common mistake: Browsers try to repair broken HTML without showing an error. Your page may look fine today and break when you add CSS. Paste your code into the W3C HTML validator to find mistakes early.

HTML has six heading levels, from <h1> to <h6>. Use one <h1> for the page topic. Use <h2> for main sections and <h3> for parts inside them. Do not pick a heading for its size, because CSS controls size.

<h2>About me</h2>
<p>I am a <strong>final-year student</strong> from Warangal.</p>

<img src="photo.jpg" alt="Anil standing near a library"
     width="300" height="200">

<h3>My skills</h3>
<ul>
  <li>HTML</li>
  <li>CSS</li>
</ul>

<h3>My plan</h3>
<ol>
  <li>Finish one small page.</li>
  <li>Put it on GitHub.</li>
</ol>

<a href="https://developer.mozilla.org/">Open MDN Web Docs</a>

The alt text describes the image. Screen readers speak it, and browsers show it when the image cannot load. Use alt="" only for a picture that is pure decoration.

Use <ul> when the order does not matter and <ol> when it does. A link path such as about.html is relative to the current file. A path that starts with https:// is a full address.

Tables and forms

Use a table for data with rows and columns, such as marks. Do not use it to place parts of a page side by side. That is the job of CSS Flexbox or Grid.

<table>
  <caption>Test marks</caption>
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">Marks</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Anil</td>
      <td>82</td>
    </tr>
  </tbody>
</table>

<tr> is a row, <th> is a heading cell and <td> is a data cell.

A form collects information from a user:

<form action="/contact" method="post">
  <label for="name">Your name</label>
  <input id="name" name="name" type="text" required>

  <label for="email">Email</label>
  <input id="email" name="email" type="email" required>

  <label for="course">Course</label>
  <select id="course" name="course">
    <option value="java">Java</option>
    <option value="data">Data analytics</option>
  </select>

  <button type="submit">Send</button>
</form>

Notice three details. Each <label> has a for value that matches an input id. Each input has a name, which becomes the field name sent to the server. type="email" and required ask the browser to check the value first.

HTML does not save this data. A server must receive it at /contact. You can build one later with Node.js.

Pro tip: Click the label text in your browser. If the cursor jumps into the input, the label is connected correctly.

Semantic HTML: use tags with meaning

A <div> is a plain box. It tells the browser nothing about its content. A semantic tag names the role of the content.

<body>
  <header>
    <h1>Anil's portfolio</h1>
    <nav>
      <a href="#projects">Projects</a>
      <a href="#contact">Contact</a>
    </nav>
  </header>

  <main>
    <section id="projects">
      <h2>Projects</h2>
      <article>
        <h3>Marks calculator</h3>
        <p>Adds marks and shows the percentage.</p>
      </article>
    </section>
  </main>

  <footer id="contact">
    <p>Email: anil@example.com</p>
  </footer>
</body>
Tag Use it for
<header> Introduction to a page or section
<nav> Main navigation links
<main> The main content, shown once per page
<section> A group of content on one topic
<article> Content that makes sense by itself
<footer> Closing details of a page or section

Semantic tags help people who use screen readers. They also make your code easier to read. Use a <div> when none of these tags fits.

Interview note: A common question is the difference between <section> and <div>. Say that a section groups related content and usually has a heading, while a div has no meaning and is useful for styling.

Learn HTML and CSS, then JavaScript

These three languages share the work on a page. It is easier to learn HTML, CSS and JavaScript in that order.

Language Its job Example
HTML Structure There is a button
CSS Appearance The button is blue
JavaScript Behaviour A click changes the number

This small page uses all three:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Counter</title>
  <style>
    button { background: navy; color: white; padding: 12px; }
  </style>
</head>
<body>
  <button id="add" type="button">Add one</button>
  <p>Total: <span id="total">0</span></p>
  <script>
    let total = 0;
    document.querySelector("#add").addEventListener("click", () => {
      total = total + 1;
      document.querySelector("#total").textContent = total;
    });
  </script>
</body>
</html>

Click the button twice and the total becomes 2. The script sits near the end of the body, so the button already exists when the script runs.

This is a useful order if you want to learn HTML and CSS from beginning to advanced level:

  1. HTML basics: headings, links, lists, images and tables.
  2. HTML forms and meaning: labels, input types and semantic tags.
  3. CSS basics: selectors, colours, spacing and the box model. Follow the CSS tutorial.
  4. CSS layout: Flexbox, Grid and media queries.
  5. Advanced HTML and CSS: accessibility, responsive images, animations and custom properties.
  6. JavaScript: variables, functions, events and arrays. Start with the JavaScript fundamentals tutorial.

You do not need to finish every advanced CSS topic before you start JavaScript. You do need to be able to build a simple page without copying it.

Practice projects to learn HTML well

This HTML tutorial for beginners gives you the pieces. Building pages without looking at an answer makes them stick.

  • Recipe page: one heading, one image, a list of items and numbered steps.
  • Class timetable: a table with a caption and proper heading cells.
  • Registration form: text, email, date, radio buttons and a select box.
  • Portfolio: a home page, a project page and links between them.

For each project, check that every image has suitable alt text, every input has a label and every link opens the right page. Then resize the browser and look for problems.

When you can explain each tag you used, test yourself with the HTML interview questions. Next, save your work with Git commands and share it on GitHub. If you plan to move on to full applications, see how HTML fits into the Java full stack course.

Frequently Asked Questions

Is HTML a programming language?
No. HTML is a markup language that describes content and structure. JavaScript adds programming logic to a web page.
How long does it take to learn HTML?
Many beginners can make a simple page within a few days of regular practice. Forms, accessibility and good structure take longer. Judge your progress by whether you can build a page without copying it.
Should I learn HTML or CSS first?
Learn basic HTML first, then add CSS. CSS needs HTML elements to style. You can continue learning both by building small pages.
What is the difference between an HTML tag and an element?
A tag is a label such as an opening or closing p tag. An element includes the opening tag, its content and its closing tag. Void elements such as img have no closing tag.
Can I make a full website with only HTML?
You can make pages with text, images and links using only HTML. CSS is needed to control their design, and JavaScript is used for richer behaviour. Saving form data also needs a server or form service.

Want to Build Your Career in Java Full Stack with AI?

Join CodeBegun and train with working industry engineers — Discover CodeBegun's Java Full Stack track

Apply for Demo Class →
Siva Prasad Galaba
Founder, CodeBegun · Staff Engineer

Founder of CodeBegun. 15+ years building Java systems at companies like Crunchyroll. Teaches Java, Spring Boot and system design the way the industry actually works, and mentors students through projects, mock interviews and placement preparation.

Technically reviewed by CodeBegun Technical TeamLast reviewed 3 December 2026 LinkedIn
Chat with us