HTML – Basics, Structure, and Practical Examples

HTML (HyperText Markup Language) is the fundamental language used to structure content on the web. Every standard web page relies on HTML to tell the browser which parts of a page represent headings, text paragraphs, images, links, lists, tables, forms, and other elements.

When you open a web page, HTML defines its content structure. CSS is used to control the appearance and layout of elements, while JavaScript enables interactivity and dynamic behavior. Together, these technologies form the foundation of frontend development.

In this guide, you will learn the basics of HTML syntax, understand how document structure is created, and see how the most commonly used HTML elements are applied in practice. Each important topic is accompanied by code examples that you can experiment with and use in your own projects.

What Is HTML and How Does It Work?

HTML is a markup language used to structure content on the web. This means that HTML tags are used to define the meaning and organization of different parts of a webpage.

For example, a heading is marked with the <h1> element, regular text with the <p> element, and a hyperlink with the <a> element. A web browser reads the HTML document and uses its elements to display content to the user.

A simple HTML example looks like this:

HTML

<h1>Welcome to My Website</h1>

<p>This is the first paragraph of text on the page.</p>

<a href="https://example.com">Visit the Website</a>

In this example:

  • <h1> defines the main page heading.
  • <p> represents a text paragraph.
  • <a> creates a link to another web address.

HTML elements typically consist of a starting tag, content, and an ending tag. For example, <p> is the opening tag, the text between the tags is the content, and </p> is the closing tag.

 

Basic Structure of an HTML Document

Every standard HTML page follows a basic structure that provides the browser with information about the document type, language, page title, and the content that should be displayed.

Take a look at the following example of a complete HTML document:

HTML

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

 

<title>My First HTML Page</title>

<meta name="description" content="Example of a basic HTML page.">

</head>

 

<body>

 

<h1>My First Web Page</h1>

 

<p>This is my first HTML document.</p>

 

</body>

</html>

 

The most important parts of the document are:

  1. <!DOCTYPE html> – defines the document as an HTML5 document.
  2. <html lang="en"> – represents the root element of the document and specifies the language of the content.
  3. <head> – contains metadata and information about the page that is generally not displayed directly within the page content.
  4. <meta charset="UTF-8"> – ensures proper display of characters and symbols from different languages.
  5. <meta name="viewport"> – helps the page display correctly on mobile devices and different screen sizes.
  6. <title> – defines the page title displayed in the browser tab.
  7. <body> – contains the visible content of the webpage.

You can use this structure as a starting template for almost any new HTML document.

HTML Headings – H1, H2, H3, and Other Levels

Headings are used to organize content and clearly define the hierarchy of information on a webpage. HTML supports six heading levels, ranging from <h1> to <h6>.

The <h1> tag is typically used for the main page title, while <h2> is used for major sections and <h3> for subsections within those sections.

Here is an example of a properly structured heading hierarchy:

HTML

 

 

<h1>Learning HTML</h1>

 

<h2>Basic HTML Elements</h2>

 

<h3>Headings and Paragraphs</h3>

<p>HTML allows you to structure textual content.</p>

 

<h3>Links and Images</h3>

<p>Links connect pages, while images enrich content.</p>

 

<h2>HTML Forms</h2>

 

<h3>Data Input</h3>

<p>Forms allow users to submit data.</p>

 

It is important to use headings according to their semantic meaning and hierarchy rather than simply for their visual size. CSS should be used to control the appearance, size, and styling of headings, while HTML headings should be used to define the structure and organization of the content.

HTML Text Elements – Paragraphs, Bold, and Emphasized Text

The <p> element is most commonly used to display textual content and represents a paragraph. When certain words or parts of the text need to be emphasized, elements such as <strong> and <em> are used.

Example:

HTML

 

<p>

HTML is <strong>the fundamental technology for structuring web pages</strong>.

Together with CSS and JavaScript, it forms the foundation of frontend development.

</p>

 

<p>

<em>Proper document structure</em> makes content easier to understand.

</p>

 

There is an important distinction between visual formatting and semantic meaning. The <strong> element indicates content of particular importance, while <em> is used to emphasize text. In contrast, the <b> and <i> elements are primarily intended for visual styling and do not carry the same semantic meaning.

HTML Links – Connecting Pages and Content

Links allow you to connect different pages, documents, and resources across the web. The <a> (anchor) element is used to create a link, while its destination is specified using the href attribute.

Example of a link to another website:

HTML

 

 

<a href="https://www.example.com">

Visit Our Website

</a>

 

A link can also point to another page within the same website:

HTML

 

 

<a href="/blog/web-development/html">

HTML Guide

</a>

 

You can also use links to navigate to a specific section of the same page:

HTML

 

 

<a href="#html-forms">View HTML Forms</a>

 

<h2 id="html-forms">HTML Forms</h2>

<p>This section explains HTML forms.</p>

 

To open a link in a new browser tab, use the target="_blank" attribute. In such cases, it is recommended to also include rel="noopener" for improved security and performance:

HTML

 

 

<a href="https://www.example.com" target="_blank" rel="noopener">

Open External Website

</a>

 

When creating web pages, it is important to use link text that clearly describes the destination or content of the link, rather than generic phrases such as "click here."

HTML Images – Displaying Photos and Graphics

Images are an important part of web content. In HTML, they are displayed using the <img> element, which uses the src attribute to specify the image path and the alt attribute to provide a text description of the image.

Example:

HTML

 

 

<img

src="/images/html-example.jpg"

alt="Example of an HTML webpage structure"

width="800"

height="450"

>

 

The most important attributes are:

  1. src – the path or URL of the image.
  2. alt – a text description of the image.
  3. width – the width of the image.
  4. height – the height of the image.

The alt attribute is especially important for accessibility, as screen readers use this description to convey the image's content to users. It is also useful when an image cannot be loaded.

For decorative images that do not provide additional information, an empty alt attribute can be used:

HTML

 

 

<img src="/images/decoration.svg" alt="">

 

HTML Lists – Ordered and Unordered Lists

Lists are used when you need to display multiple related items. HTML supports two main types of lists: unordered lists and ordered lists.

An unordered list uses the <ul> element, while an ordered list is created using the <ol> element. Each list item is defined with the <li> element.

Example of an unordered list:

HTML

 

<h2>Core Web Technologies</h2>

 

<ul>

<li>HTML – page structure</li>

<li>CSS – appearance and layout</li>

<li>JavaScript – interaction and functionality</li>

</ul>

 

Example of an ordered list:

HTML

 

 

<h2>Steps to Create an HTML Page</h2>

 

<ol>

<li>Create an HTML document.</li>

<li>Add the basic document structure.</li>

<li>Insert textual content.</li>

<li>Link a CSS stylesheet.</li>

<li>Open the page in a web browser.</li>

</ol>

 

Lists are particularly useful for presenting step-by-step instructions, product features, navigation menus, and other clearly organized information.

HTML Tables – Displaying Data in Rows and Columns

Tables are used to present related data in a structured format, such as price lists, specifications, results, and comparison charts.

The basic elements of an HTML table are:

  1. <table> – defines the table.
  2. <tr> – defines a table row.
  3. <th> – represents a column or row header.
  4. <td> – represents a data cell.
  5. <thead> – groups the table header section.
  6. <tbody> – groups the main content of the table.

Example:

HTML

 

 

<table>

<thead>

<tr>

<th>Technology</th>

<th>Purpose</th>

<th>Type</th>

</tr>

</thead>

 

<tbody>

<tr>

<td>HTML</td>

<td>Content structure</td>

<td>Markup language</td>

</tr>

 

<tr>

<td>CSS</td>

<td>Page styling</td>

<td>Style sheet language</td>

</tr>

 

<tr>

<td>JavaScript</td>

<td>Interactivity</td>

<td>Programming language</td>

</tr>

</tbody>

</table>

 

For proper table usage, it is important not to use tables for page layout and positioning. Modern web development relies on CSS Flexbox and CSS Grid for layout purposes, while tables should be reserved for displaying tabular data.

HTML Semantic Elements – Proper Content Organization

Semantic HTML elements describe the purpose and meaning of different parts of a webpage. Instead of building every section of a document using generic <div> elements, semantic elements provide a clearer and more meaningful content structure.

The most commonly used semantic elements are:

  1. <header> – the header of a page or a specific section.
  2. <nav> – a navigation menu.
  3. <main> – the main content of the page.
  4. <section> – a thematic section of content.
  5. <article> – a self-contained piece of content, such as a blog post.
  6. <aside> – supplementary or secondary content.
  7. <footer> – the footer of a page or section.

Example of a webpage structure:

HTML

 

 

<body>

 

<header>

<h1>My Website</h1>

 

<nav>

<a href="/">Home</a>

<a href="/about-us">About Us</a>

<a href="/contact">Contact</a>

</nav>

</header>

 

<main>

 

<article>

<h2>Introduction to HTML</h2>

<p>HTML is the foundation of web page structure.</p>

</article>

 

<section>

<h2>Other Lessons</h2>

<p>Explore additional frontend technologies.</p>

</section>

 

</main>

 

<footer>

<p>&copy; 2026 My Website</p>

</footer>

 

</body>

 

A semantic structure makes code easier to maintain, improves accessibility, and helps browsers, search engines, and other systems better understand the organization and meaning of the content.

HTML Forms – Entering and Submitting Data

HTML forms allow users to enter and submit data. They are commonly used for contact pages, user registration, login systems, search functionality, and various other interactive features.

The basic form element is <form>, while data input is handled through elements such as <input>, <textarea>, and <select>.

Example of a simple contact form:

HTML

 

 

<form action="/contact" method="post">

 

<label for="name">Full Name:</label>

<input type="text" id="name" name="name" required>

 

<label for="email">Email Address:</label>

<input type="email" id="email" name="email" required>

 

<label for="message">Message:</label>

<textarea id="message" name="message" rows="5"></textarea>

 

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

 

</form>

 

Important attributes and elements:

  1. action – specifies the URL where the form data will be submitted.
  2. method – defines the HTTP method, most commonly get or post.
  3. name – identifies the form field when data is submitted.
  4. required – marks a field as mandatory.
  5. <label> – associates descriptive text with an input field.
  6. <button> – creates a button for submitting the form or performing another action.

HTML provides basic input validation capabilities, but processing data, storing it in a database, and performing more advanced validation requires a backend system.

HTML Attributes – Additional Information for Elements

Attributes provide additional information about HTML elements or define their behavior. They are placed inside the opening tag, most commonly in the form name="value".

Example:

HTML

 

<a href="/contact" title="Contact Us">

Contact

</a>

 

In this example:

  • href specifies the link destination.
  • title provides additional information about the element.

Some attributes can be used on a wide variety of HTML elements:

HTML

 

 

<p id="introduction" class="text">

This is an introductory paragraph.

</p>

 

The id attribute is used to uniquely identify an element within a document, while the class attribute allows elements to be grouped for CSS styling or JavaScript manipulation.

There are also global attributes that can be applied to many HTML elements, such as title, lang, hidden, tabindex, and data-* attributes.

 

HTML Comments – Explanations Within Code

Comments allow developers to add notes and explanations within an HTML document. Browsers do not display comments as part of the webpage content.

Example:

HTML

 

 

<!-- Main page header -->

<header>

<h1>Welcome</h1>

</header>

 

<!-- Main content -->

<main>

<p>This is the page content.</p>

</main>

 

Comments are useful for organizing code, explaining more complex sections, and making it easier to navigate larger projects. However, you should never store passwords, login credentials, or other sensitive information in comments, as they remain visible in the page's source code.

Connecting HTML with CSS and JavaScript

HTML defines the structure of a webpage, but on its own it does not provide advanced visual styling or interactivity. That is why it is commonly combined with CSS and JavaScript.

CSS is usually linked within the <head> section of the document:

HTML

 

 

<link rel="stylesheet" href="style.css">

 

A JavaScript file can be linked using the <script> element:

Error: CdnAliasUnresolved - Unresolved CDN references: 1

HTML

 

 

<script src="script.js" defer></script>

 

Console

 

 

Current preview

CdnAliasUnresolved - Unresolved CDN references: 1

Console content may be incorrect

The defer attribute ensures that the script is executed only after the HTML document has been fully parsed.

Complete example:

Error: CdnAliasUnresolved - Unresolved CDN references: 1

HTML

 

 

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

 

<title>HTML, CSS, and JavaScript</title>

 

<link rel="stylesheet" href="style.css">

<script src="script.js" defer></script>

</head>

 

<body>

 

<h1>My First Web Page</h1>

 

<p id="message">This is an example of connecting web technologies.</p>

 

<button id="button">Change Text</button>

 

</body>

</html>

 

Console

 

Current preview

CdnAliasUnresolved - Unresolved CDN references: 1

Console content may be incorrect

In this setup, HTML serves as the foundation of the project, CSS defines the visual appearance, and JavaScript adds functionality and interactivity.

Practical HTML Mini Project – Building a Simple Web Page

The best way to learn HTML is by creating a simple web page on your own and applying the elements you have learned.

In the following example, we will create a basic website that includes a header, navigation menu, introductory text, a list of services, an image, and a contact section.

HTML

 

 

<!DOCTYPE html>

<html lang="en">

 

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

 

<title>My First Website</title>

 

<meta name="description" content="Example of a simple HTML website.">

</head>

 

<body>

 

<header>

<h1>My Website</h1>

 

<nav>

<a href="#home">Home</a>

<a href="#services">Services</a>

<a href="#contact">Contact</a>

</nav>

</header>

 

<main>

 

<section id="home">

<h2>Welcome to Our Website</h2>

 

<p>

We would like to introduce our company and the services

we provide to our clients.

</p>

 

<img

src="/images/presentation.jpg"

alt="Example of a business website"

width="800"

height="450"

>

</section>

 

<section id="services">

<h2>Our Services</h2>

 

<ul>

<li>Website Development</li>

<li>Web Design</li>

<li>SEO Optimization</li>

</ul>

</section>

 

<section id="contact">

<h2>Contact Us</h2>

 

<p>Email: info@example.com</p>

 

<a href="mailto:info@example.com">

Send an Email

</a>

</section>

 

</main>

 

<footer>

<p>&copy; 2026 My Website</p>

</footer>

 

</body>

</html>

 

This example combines many fundamental HTML elements and serves as an excellent beginner exercise. Save the code in a file named index.html, open it in a web browser, and see how it is displayed.

After that, you can add CSS styles, adapt the layout for mobile devices, and gradually enhance the page with additional features and functionality.

Common Mistakes When Writing HTML Code

When learning HTML, beginners often make mistakes that can make code harder to maintain or affect how content is displayed in a browser.

Pay attention to the following examples:

1. Incorrectly Closing Elements

Incorrect:

HTML

 

 

<p>First paragraph

<p>Second paragraph</p>

 

 

Correct:

HTML

 

 

<p>First paragraph</p>

<p>Second paragraph</p>

 

2. Improper Nesting of Elements

Incorrect:

HTML

 

 

<p>

This is text <strong>important text</p></strong>

 

Correct:

HTML

 

 

<p>

This is text <strong>important text</strong>

</p>

 

3. Omitting the alt Attribute on Informative Images

Incorrect:

HTML

 

 

<img src="/images/product.jpg">

 

Correct:

HTML

 

<img src="/images/product.jpg" alt="Product photograph">

 

4. Using HTML Elements Only for Their Visual Appearance

Headings should be chosen according to the structure and meaning of the content, not based on their font size. CSS should be used to control the visual appearance.

5. Using Obsolete Elements for Styling

The appearance of text and layout of page elements should be controlled with CSS rather than outdated HTML elements and attributes that were originally intended for visual formatting.

Writing clean and valid HTML from the beginning makes future development, testing, and maintenance of web projects much easier.

How to Continue Learning HTML?

Once you have mastered the basic HTML elements, the next step is to gain a deeper understanding of semantic structure, accessibility, forms, and the proper organization of content.

Recommended learning path:

  1. Basic HTML document structure.
  2. Headings, paragraphs, links, and images.
  3. Lists, tables, and HTML attributes.
  4. Semantic HTML5 elements.
  5. HTML forms and input validation.
  6. Accessibility and proper use of HTML elements.
  7. Connecting HTML with CSS and JavaScript.

After learning HTML, it is recommended to continue with CSS, as it will teach you how to style content, control layouts, and adapt web pages to different screen sizes and devices.

HTML is the first important step in frontend development. The better you understand its structure and best practices, the easier it will be to learn more advanced web technologies and build high-quality, accessible, and functional websites.