Introduction
HTML (HyperText Markup Language) is the standard markup language used to create web pages. It provides the structure of a webpage, allowing you to define elements such as headings, paragraphs, links, images, and more. HTML is the foundation of web development and is essential for anyone looking to build websites.
Prerequisites
- Basic understanding of how the web works
- A text editor (e.g., Visual Studio Code, Sublime Text, or even Notepad)
Step 1: Understanding HTML Structure
An HTML document is structured with tags that define different elements. Here is a basic structure of an HTML document:
<!DOCTYPE html>
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
<p>This is a paragraph of text on my webpage.</p>
</body>
</html>
<!DOCTYPE html>
: Declares the document type and version of HTML.<html>
: The root element of an HTML page.<head>
: Contains meta-information about the document, such as the title.<title>
: Sets the title of the webpage, which appears in the browser tab.<body>
: Contains the content of the webpage, such as text, images, and links.
Step 2: Basic HTML Tags
Here are some basic HTML tags and their usage:
- Headings: Define headings using
<h1>
to<h6>
tags.
<h1>This is a Heading 1</h1>
<h2>This is a Heading 2</h2>
Paragraphs: Define paragraphs using the <p>
tag.
<p>This is a paragraph of text.</p>
Links: Create hyperlinks using the <a>
tag.
<a href="https://www.example.com">Visit Example</a>
Images: Embed images using the <img>
tag.
<img src="image.jpg" alt="Description of image">
Lists: Create ordered and unordered lists using <ol>
, <ul>
, and <li>
tags.
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
Step 3: HTML Attributes
HTML tags can have attributes that provide additional information about the element. Attributes are always included in the opening tag and usually come in name/value pairs like name="value"
.
- Example:
<a href="https://www.example.com" target="_blank">Visit Example</a>
href
: Specifies the URL of the page the link goes to.target
: Specifies where to open the linked document.
Step 4: Creating a Simple Webpage
Let’s create a simple webpage that includes headings, paragraphs, links, images, and lists.
<!DOCTYPE html>
<html>
<head>
<title>My Simple Webpage</title>
</head>
<body>
<h1>Welcome to My Simple Webpage</h1>
<p>This is a paragraph of text on my webpage. Here is a link to <a href="https://www.example.com" target="_blank">Example</a>.</p>
<h2>My Favorite Foods</h2>
<ul>
<li>Pizza</li>
<li>Burgers</li>
<li>Ice Cream</li>
</ul>
<h2>My Favorite Websites</h2>
<ol>
<li><a href="https://www.google.com" target="_blank">Google</a></li>
<li><a href="https://www.wikipedia.org" target="_blank">Wikipedia</a></li>
<li><a href="https://www.github.com" target="_blank">GitHub</a></li>
</ol>
<h2>My Favorite Image</h2>
<img src="https://via.placeholder.com/150" alt="Placeholder Image">
</body>
</html>
Step 5: HTML Forms
HTML forms are used to collect user input. Form elements include text fields, checkboxes, radio buttons, and submit buttons.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Contact Form</title>
</head>
<body>
<h1>Contact Us</h1>
<form action="/submit_form" method="post">
<label for="name">Name:</label><br>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label><br>
<input type="email" id="email" name="email"><br><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message"></textarea><br><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
Step 6: HTML Tables
HTML tables are used to display data in a tabular format.
Example:
<!DOCTYPE html>
<html>
<head>
<title>HTML Table</title>
</head>
<body>
<h1>Student Grades</h1>
<table border="1">
<tr>
<th>Name</th>
<th>Subject</th>
<th>Grade</th>
</tr>
<tr>
<td>Alice</td>
<td>Math</td>
<td>A</td>
</tr>
<tr>
<td>Bob</td>
<td>Science</td>
<td>B</td>
</tr>
<tr>
<td>Charlie</td>
<td>History</td>
<td>C</td>
</tr>
</table>
</body>
</html>
Conclusion
Congratulations! You’ve completed the beginner’s guide to HTML. You’ve learned the basics of HTML structure, tags, attributes, forms, and tables. With this knowledge, you can start creating your own web pages.
Next Steps
- Explore more advanced HTML topics, such as semantic HTML, multimedia elements, and HTML5 APIs.
- Learn CSS (Cascading Style Sheets) to style your web pages.
- Learn JavaScript to add interactivity to your web pages.
- Work on real-world projects to apply your skills.