What is HTML?
HTML (HyperText Markup Language) is the standard markup language used to create web pages. It defines the structure and content of a webpage. HTML is used to describe the elements of a webpage, such as headings, paragraphs, links, images, tables, forms, and more. It is the backbone of most websites and works alongside CSS (Cascading Style Sheets) for styling and JavaScript for interactivity.
Key Features of HTML:
- Markup Language: HTML is not a programming language but a markup language. It uses tags to define the structure of the content on a page. These tags tell the web browser how to display text, images, and other elements.
- Declarative Syntax: HTML is declarative in nature, meaning you tell the browser what content to display rather than how to perform tasks. This makes HTML easy to read and understand.
- Elements and Tags: HTML consists of elements represented by tags. Tags are used to define the different parts of a webpage. Tags typically come in pairs: an opening tag and a closing tag. For example,
<h1>
is the opening tag for a heading, and</h1>
is the closing tag. - Hyperlinks: HTML provides the ability to create hyperlinks using the
<a>
tag. This allows users to navigate between pages and websites by clicking on links. - Forms and Input: HTML provides a powerful set of tags for creating forms where users can input data. Elements like
<form>
,<input>
,<textarea>
,<select>
, and<button>
allow web developers to collect user input. - Multimedia: HTML supports embedding various media types such as images, audio, and video using tags like
<img>
,<audio>
, and<video>
. - Semantic Elements: HTML5 introduced semantic elements that provide meaning to the structure of web pages. These include tags like
<header>
,<footer>
,<article>
,<section>
, and<nav>
, which improve both accessibility and SEO (Search Engine Optimization).

Basic Structure of an HTML Document
An HTML document has a specific structure that includes the following parts:
htmlCopy<!DOCTYPE html> <!-- Declaration of HTML5 document -->
<html lang="en"> <!-- Start of the HTML document -->
<head> <!-- Head section with metadata -->
<meta charset="UTF-8"> <!-- Character encoding -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Viewport settings for responsive design -->
<title>Page Title</title> <!-- The title of the web page displayed in the browser tab -->
<link rel="stylesheet" href="styles.css"> <!-- Link to external CSS -->
</head>
<body> <!-- Body section where the content of the page is placed -->
<h1>Welcome to My Website</h1> <!-- Main heading -->
<p>This is a paragraph of text.</p> <!-- A paragraph -->
<a href="https://example.com">Click here</a> <!-- A link -->
</body>
</html>
<!DOCTYPE html>
: Specifies the document type and version of HTML (HTML5 here).<html>
: The root element of the HTML document.<head>
: Contains meta-information about the document, such as the character encoding, title, links to external resources (like stylesheets), and other settings.<body>
: Contains the visible content of the webpage (text, images, links, etc.).
HTML Tags and Elements
HTML is built using various tags and elements. Here are some important ones:
1. Text Elements
<h1>
to<h6>
: Headings, with<h1>
being the largest and<h6>
being the smallest.htmlCopy<h1>Main Heading</h1> <h2>Subheading</h2>
<p>
: Paragraph.htmlCopy<p>This is a paragraph of text.</p>
<strong>
: Bold text with semantic meaning.htmlCopy<strong>Important text</strong>
<em>
: Italic text with semantic meaning.htmlCopy<em>Emphasized text</em>
<br>
: Line break (no closing tag).htmlCopyLine 1<br>Line 2
2. Links and Navigation
<a>
: Anchor tag used to create hyperlinks.htmlCopy<a href="https://www.example.com">Visit Example</a>
<nav>
: Defines a navigation section (used for navigation menus).htmlCopy<nav> <a href="#home">Home</a> <a href="#services">Services</a> <a href="#contact">Contact</a> </nav>
3. Images and Multimedia
<img>
: Embeds an image.htmlCopy<img src="image.jpg" alt="Description of Image" width="300" height="200">
<audio>
: Embeds an audio file.htmlCopy<audio controls> <source src="audio.mp3" type="audio/mp3"> Your browser does not support the audio element. </audio>
<video>
: Embeds a video file.htmlCopy<video width="320" height="240" controls> <source src="video.mp4" type="video/mp4"> Your browser does not support the video element. </video>
4. Lists
<ul>
: Unordered list (bulleted).htmlCopy<ul> <li>Item 1</li> <li>Item 2</li> <li>Item 3</li> </ul>
<ol>
: Ordered list (numbered).htmlCopy<ol> <li>First Item</li> <li>Second Item</li> </ol>
<li>
: List item, used inside both<ul>
and<ol>
.
5. Tables
<table>
: Defines a table.<tr>
: Table row.<td>
: Table cell.<th>
: Table header cell.htmlCopy<table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Row 1, Cell 1</td> <td>Row 1, Cell 2</td> </tr> </table>
6. Forms
Forms collect user input. Common form elements include:
<form>
: Defines a form.<input>
: User input field.<textarea>
: Multi-line text input.<button>
: A button for submitting or interacting with a form.htmlCopy<form action="/submit" method="post"> <input type="text" name="username" placeholder="Enter username"> <textarea name="message" placeholder="Your message"></textarea> <button type="submit">Submit</button> </form>
7. Semantic HTML5 Elements
HTML5 introduced new elements that give more meaning to the structure of a webpage. These elements improve accessibility and SEO.
<header>
: Defines a header for a document or section.<footer>
: Defines a footer for a document or section.<article>
: Defines independent content (e.g., blog posts).<section>
: Defines a section of content.<aside>
: Defines content tangentially related to the main content (e.g., a sidebar).<main>
: Defines the main content of a document.
HTML Attributes
HTML elements can have attributes that provide additional information about the element. For example:
href
: Specifies the URL in an<a>
tag.src
: Specifies the source file in<img>
,<audio>
, or<video>
.alt
: Provides alternative text for images (important for accessibility).class
: Specifies one or more classes for styling or JavaScript.id
: Specifies a unique identifier for an element.
Example:
htmlCopy<a href="https://www.example.com" target="_blank">Visit Example</a>
<img src="logo.png" alt="Website Logo" class="logo">
HTML5 New Features
- Local Storage: HTML5 provides a way to store data locally in the browser using the
localStorage
andsessionStorage
APIs. - Canvas: The
<canvas>
element allows for dynamic, scriptable rendering of 2D shapes and bitmap images. - Geolocation: HTML5 provides a Geolocation API to access the geographical position of a user.
- Audio/Video: The
<audio>
and<video>
tags allow embedding multimedia directly into a webpage without the need for plugins.