HTML Basics

What is HTML?

HTML stands for HyperText Markup Language. It's the standard markup language used to create web pages and web applications. It describes the structure of a web page semantically and originally included cues for the appearance of the document.

Think of HTML as the skeleton of a webpage, providing the fundamental structure and content.

Basic HTML Document Structure

Every HTML document follows a basic structure:

Example: Standard HTML5 Structure

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First Web Page</title>
</head>
<body>
    <h1>Hello, World!</h1>
    <p>This is my first paragraph.</p>
</body>
</html>

HTML Elements and Tags

HTML documents are built using elements. Elements are defined by tags. Most HTML elements have an opening tag and a closing tag.

Example: Paragraph Element

This is a paragraph element.

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

HTML Attributes

Attributes provide additional information about HTML elements. They are always specified in the start tag and usually come in name/value pairs like: name="value".

Example: Anchor Tag with HREF Attribute

Visit Example.com.

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

HTML Headings

Headings are used to define titles and headings for sections of content. HTML provides six levels of headings, from <h1> (most important) to <h6> (least important).

Example: Heading Levels

This is H1

This is H2

This is H3

This is H4

This is H5
This is H6
<h1>This is H1</h1>
<h2>This is H2</h2>
<h3>This is H3</h3>
<h4>This is H4</h4>
<h5>This is H5</h5>
<h6>This is H6</h6>

Use headings to structure your content logically. Don't skip heading levels (e.g., don't go from <h1> directly to <h3>).

HTML Paragraphs

The <p> tag defines a paragraph. Browsers automatically add some space (margin) before and after each paragraph.

Example: Paragraphs

This is the first paragraph. It contains some introductory text.

This is the second paragraph. It's separated from the first by a small amount of vertical space.

<p>This is the first paragraph. It contains some introductory text.</p>
<p>This is the second paragraph. It's separated from the first by a small amount of vertical space.</p>

HTML Images

The <img> tag is used to embed an image in an HTML page. It's an empty tag (or void tag) as it doesn't need a closing tag. It requires at least two attributes: src and alt.

Example: Embedding an Image

A placeholder image
<img src="image.jpg" alt="Description of image">

It's crucial to provide meaningful alt text for images. This helps search engines understand the content of the image and provides a fallback for users who cannot see the image (e.g., using screen readers or having images turned off).

HTML Lists

HTML lists are used to group a set of related items. There are two main types of lists:

Unordered Lists (Bulleted)

Unordered lists use the <ul> tag, and each list item is defined by the <li> tag.

Example: Unordered List

  • First item
  • Second item
  • Third item
<ul>
    <li>First item</li>
    <li>Second item</li>
    <li>Third item</li>
</ul>

Ordered Lists (Numbered)

Ordered lists use the <ol> tag, and each list item is defined by the <li> tag. The items are displayed with numbering.

Example: Ordered List

  1. First step
  2. Second step
  3. Third step
<ol>
    <li>First step</li>
    <li>Second step</li>
    <li>Third step</li>
</ol>