HTML Documentation

This technical documentation provides a clear guide to HTML, covering its basic structure, elements, and key components used in web development.

<Introduction>

HTML, or Hypertext Markup Language, is the backbone of web development. It provides the structure for web pages, allowing developers to format text, embed images, create links, and organize content.

HTML consists of elements represented by tags such as <html>, <head>, <body>, and more. These tags structure content and give instructions to the browser on how to display the page.

<Basic Structure>

The basic structure of an HTML document includes a doctype declaration, an HTML tag, and essential child elements such as <head> and <body>. These elements form the foundation for any HTML page.

Here's a simple example of the basic structure of an HTML document:


  <!DOCTYPE html>
  <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Page Title</title>
    </head>
    <body>
      <h1>Welcome to the Basic HTML Structure</h1>
      <p>This is a simple HTML page</p>
    </body>
  </html>
        

<Elements and Tags>

In HTML, elements are the building blocks of a webpage, typically consisting of an opening tag, content, and a closing tag. Tags tell the browser how to display content. For example, the <h1> tag defines a top-level heading, and the <p> tag defines a paragraph.

Some elements are void elements, meaning they don’t have content and don’t require a closing tag. These self-closing elements perform a specific function. Examples include the <img> tag for images and the <br> tag for line breaks. Void elements are used when no surrounding content is needed, so they close immediately after the opening tag.

<Attributes>

HTML attributes provide additional information about HTML elements. They are used to modify the behavior or style of an element or provide additional functionality. Attributes are always written within the opening tag of an element and consist of a name and a value pair.

Some of the most commonly used attributes in HTML are:

<Headings and Paragraphs>

Headings and paragraphs are fundamental elements in HTML, used to structure content and make it more readable. They help organize the text and give it a clear hierarchy, which improves both user experience and accessibility.

Headings in HTML range from <h1> to <h6>, with <h1> being the highest level, usually reserved for the main title of the page, and <h6> for the least important headings. Each level should be used to represent a different level of content importance.


<h1>This is a level 1 heading</h1>
<h2>This is a level 2 heading</h2>
<h3>This is a level 3 heading</h3>
        

Here's an example of how headings and paragraphs are used together to create a well-structured document:


<h1>HTML Basics</h1>
<p>HTML is the language used to create web pages.</p>

<h2>Headings</h2>
<p>Headings are used to create titles and organize content.</p>

<h2>Paragraphs</h2>
<p>Paragraphs group sentences into blocks of text for readability.</p>
        

<Lists: Ordered and Unordered>

In HTML, lists are used to group related items together. There are two main types of lists: ordered lists and unordered lists.

<Images>

Images play a crucial role in web design by enhancing the visual appeal of a webpage, conveying information, and improving user engagement.

To add an image in HTML, you use the <img> element. Unlike most other HTML elements, the <img> tag is a void element, or self-closing, meaning it doesn't require a closing tag.

Some of the most commonly used attributes with the <img> element include:

<Tables>

Tables are essential for organizing data in rows and columns on web pages. They allow for a clear, structured way to display information such as financial reports, schedules, or any data that fits a tabular format. When used correctly, tables can enhance readability and make complex data easier to interpret.

To create a table in HTML, you use the <table> element, along with various other elements to define rows, headers, and cells.

Key HTML Elements for Tables:

Code Example:
The following HTML code creates a basic table with three rows and three columns.


<table>
  <thead>
    <tr>
      <th>Header 1</th>
      <th>Header 2</th>
      <th>Header 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Row 1, Col 1</td>
      <td>Row 1, Col 2</td>
      <td>Row 1, Col 3</td>
    </tr>
    <tr>
      <td>Row 2, Col 1</td>
      <td>Row 2, Col 2</td>
      <td>Row 2, Col 3</td>
    </tr>
    <tr>
      <td>Row 3, Col 1</td>
      <td>Row 3, Col 2</td>
      <td>Row 3, Col 3</td>
    </tr>
  </tbody>
</table>
        

Rendered Table:
Here’s how the above code will display as an actual table in a browser.

Header 1 Header 2 Header 3
Row 1, Col 1 Row 1, Col 2 Row 1, Col 3
Row 2, Col 1 Row 2, Col 2 Row 2, Col 3
Row 3, Col 1 Row 3, Col 2 Row 3, Col 3

<Forms and Input>

Forms are key for collecting user data on websites. HTML provides input elements that let users enter text, select options, check boxes, or upload files. These simple inputs gather information like names, emails, preferences, and feedback.

Labels make forms more user-friendly and accessible. The <label> tag, paired with the for attribute, connects directly to its input, helping users understand the required information and making the form easier to navigate, especially for screen reader users.
A typical form contains the following parts:

  • Text Inputs: The <input type="text"> element is used for collecting textual information from users, such as names, email addresses, or other simple text. It's one of the most commonly used form fields.

    Code Example:

    
    <form>
       <label for="username">Username:</label>
       <input type="text" id="username" name="username" 
       placeholder="Enter your username">
    </form>
              

    Rendered Example:

  • Email Input: The <input type="email"> element is specifically designed for gathering email addresses. It automatically checks that the input follows the correct email format, ensuring it contains an "@" symbol and a domain name (e.g., user@example.com).

    Code Example:

    
    <form>
       <label for="email">Email:</label>
       <input type="email" id="email" name="email" 
       placeholder="Enter your email address">
    </form>
              

    Rendered Example:

  • Password Inputs: The <input type="password"> element is used to collect sensitive information, such as passwords. It masks the entered characters to keep the information secure.

    Code Example:

    
    <form>
      <label for="password">Password:</label>
      <input type="password" id="password" name="password" 
      placeholder="Enter your password">
    </form>
              

    Rendered Example:

  • Checkboxes: The <input type="checkbox"> element allows users to select one or more options from a list. It's ideal for situations where multiple selections are allowed, such as choosing hobbies or preferences.

    Code Example:

    
    <form>
      <label for="hobby1">
        <input type="checkbox" id="hobby1" 
        name="hobbies" value="reading"> Reading
      </label>
      <label for="hobby2">
        <input type="checkbox" id="hobby2" 
        name="hobbies" value="traveling"> Traveling
      </label>
      <label for="hobby3">
        <input type="checkbox" id="hobby3" 
        name="hobbies" value="gaming"> Gaming
      </label>
    </form>
              

    Rendered Example:

  • Radio Buttons: The <input type="radio"> element is used when users must select one option from a set of choices. This is common in surveys or forms that require a single choice from predefined options, such as selecting a size or preference.

    Code Example:

    
    <form>
      <label for="sizeSmall">
        <input type="radio" id="sizeSmall" name="size" 
        value="small"> Small
      </label>
      <label for="sizeMedium">
        <input type="radio" id="sizeMedium" name="size" 
        value="medium"> Medium
      </label>
      <label for="sizeLarge">
        <input type="radio" id="sizeLarge" name="size" 
        value="large"> Large
      </label>
    </form>
              

    Rendered Example:

  • Select Dropdowns: The <select> element creates a dropdown list, which is useful when you have many options for the user to choose from, such as selecting a country, language, or other categorized choices.

    Code Example:

    
    <form>
      <label for="country">Choose a country:</label>
      <select id="country" name="country">
        <option value="" disabled selected>
        Choose your country</option>
        <option value="france">France</option>
        <option value="germany">Germany</option>
        <option value="italy">Italy</option>
        <option value="uk">United Kingdom</option>
      </select>
    </form>
              

    Rendered Example:

  • Buttons and Submit: The <button> element is used for form actions, such as submitting data. The type="submit" button submits the form, while a type="reset" button can clear the form fields. Custom buttons can also be used for additional actions like adding more fields.

    Code Example:

    
    <button type="submit">Submit</button>
    <button type="reset">Reset</button>
              

    Rendered Example: