Introduction

HTML (HyperText Markup Language) is the standard language used to create and design documents on the World Wide Web. It structures the content on web pages by using a series of elements and tags, which define the different parts of the document, such as headings, paragraphs, links, images, and more.

Key Concepts

  1. HyperText: Refers to the way in which web pages (HTML documents) are linked together. Hyperlinks are the primary means of navigation on the web.
  2. Markup Language: A system for annotating a document in a way that is syntactically distinguishable from the text. HTML uses tags to mark up the content.

Basic Structure of an HTML Document

An HTML document is structured with a series of nested elements. Here is a simple example of an HTML document:

<!DOCTYPE html>
<html>
<head>
    <title>My First HTML Page</title>
</head>
<body>
    <h1>Welcome to HTML</h1>
    <p>This is a paragraph of text.</p>
</body>
</html>

Explanation of the Code

  • <!DOCTYPE html>: This declaration defines the document type and version of HTML. It helps browsers to render the content correctly.
  • <html>: The root element that contains all other HTML elements.
  • <head>: Contains meta-information about the HTML document, such as its title and links to stylesheets.
  • <title>: Sets the title of the web page, which is displayed in the browser's title bar or tab.
  • <body>: Contains the content of the HTML document, such as text, images, links, etc.
  • <h1>: A heading element. In this case, it is the highest level heading.
  • <p>: A paragraph element that contains a block of text.

Practical Example

Let's create a simple HTML page to understand how HTML works in practice.

Step-by-Step Guide

  1. Open a Text Editor: You can use any text editor like Notepad, Sublime Text, or Visual Studio Code.
  2. Create a New File: Save the file with a .html extension, for example, index.html.
  3. Write the HTML Code: Copy and paste the following code into your file:
<!DOCTYPE html>
<html>
<head>
    <title>My First HTML Page</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is my first HTML page. I am learning HTML!</p>
</body>
</html>
  1. Save the File: Save your changes.
  2. Open the File in a Browser: Double-click the file or open it in a web browser to see your first HTML page in action.

Exercise

Task

Create an HTML document that includes the following elements:

  • A title of your choice.
  • A main heading (<h1>) with the text "Hello, World!".
  • A paragraph (<p>) with a brief introduction about yourself.

Solution

<!DOCTYPE html>
<html>
<head>
    <title>About Me</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <p>My name is [Your Name]. I am learning HTML to build amazing websites!</p>
</body>
</html>

Common Mistakes

  • Forgetting the <!DOCTYPE html> declaration: This can cause the browser to render the page in "quirks mode," leading to unexpected behavior.
  • Mismatched Tags: Ensure that every opening tag has a corresponding closing tag (e.g., <p> should be closed with </p>).
  • Incorrect Nesting: HTML elements should be properly nested. For example, <p><strong>Text</strong></p> is correct, but <p><strong>Text</p></strong> is not.

Conclusion

In this lesson, you learned what HTML is and how it is used to structure web pages. You also created your first HTML document and learned about the basic structure of an HTML document. In the next lesson, we will set up your environment to start creating more complex HTML pages.

© Copyright 2024. All rights reserved