Obafemi Emmanuel

Understanding Basic HTML Structure

Published 1 month ago

1. HTML Document Structure

Every HTML document follows a standard structure to ensure compatibility with web browsers. Below is the fundamental structure of an HTML document:

<!DOCTYPE html>
<html>
<head>
    <title>My First HTML Page</title>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This is my first web page.</p>
</body>
</html>

Explanation of Key Elements:

  1. <!DOCTYPE html>: Declares the document type and version of HTML (HTML5 in this case).
  2. <html>: The root element that contains all HTML content.
  3. <head>: The head section includes metadata, links to stylesheets, and the page title.
  4. <title>: Sets the title of the web page, which appears in the browser tab.
  5. <body>: Contains the main content displayed on the webpage, such as text, images, and links.

2. Understanding Tags, Elements, and Attributes

HTML Tags:

Tags are the building blocks of an HTML document. They are enclosed in angle brackets (<>). Most tags come in pairs: an opening tag and a closing tag.

Example:

<p>This is a paragraph.</p>

<p> is the opening tag, and </p> is the closing tag.


HTML Elements:

An HTML element consists of an opening tag, content, and a closing tag.

Example:

<h1>Welcome!</h1>

Here, <h1> is the tag, and "Welcome!" is the content inside the element.


HTML Attributes:

Attributes provide additional information about an element. They are included inside the opening tag.

Example:

<img src="image.jpg" alt="A beautiful scenery">
  • src: Specifies the image source.
  • alt: Provides alternative text for the image.

3. Creating a Simple HTML Page

Now that we understand the structure, let’s create a basic webpage.

<!DOCTYPE html>
<html>
<head>
    <title>My Simple Webpage</title>
</head>
<body>
    <h1>Welcome to My Webpage</h1>
    <p>This is a simple HTML page demonstrating basic elements.</p>
    <img src="welcome.jpg" alt="Welcome Image">
    <a href="https://www.example.com">Visit Example</a>
</body>
</html>

Breakdown of the Simple Page:

  • A heading (<h1>) to introduce the page.
  • A paragraph (<p>) describing the content.
  • An image (<img>) with a source and alternative text.
  • A hyperlink (<a>) leading to another webpage.

Conclusion

Understanding the basic structure of an HTML document is the first step in web development. By mastering tags, elements, and attributes, you can create well-structured and functional web pages. As you progress, you will learn more about styling with CSS and adding interactivity with JavaScript to enhance your webpages.

Stay tuned for more lessons on HTML and web development!


Leave a Comment


Choose Colour