Skip to content
Home » Forum

Forum

HTML structure with...
 
Notifications
Clear all

[Solved] HTML structure with Basics

1 Posts
1 Users
0 Reactions
88 Views
Mark Sikaundi
(@emmanuelmark117)
Member Admin
Joined: 2 years ago
Posts: 99
Topic starter  

Creating an HTML structure involves understanding the basic semantic elements and how to use forms effectively. Here's a comprehensive guide with explanations and examples:

Basic HTML Structure

An HTML document starts with a <!DOCTYPE html> declaration, followed by <html>, <head>, and <body> elements. Here's a simple example:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Basic HTML Structure</title>
</head>
<body>
    <header>
        <h1>Welcome to My Website</h1>
    </header>
    <nav>
        <ul>
            <li><a href="#home">Home</a></li>
            <li><a href="#about">About</a></li>
            <li><a href="#contact">Contact</a></li>
        </ul>
    </nav>
    <main>
        <section id="home">
            <h2>Home</h2>
            <p>This is the home section.</p>
        </section>
        <section id="about">
            <h2>About</h2>
            <p>This is the about section.</p>
        </section>
        <section id="contact">
            <h2>Contact</h2>
            <form action="/submit" method="post">
                <label for="name">Name:</label>
                <input type="text" id="name" name="name" required>
                <br>
                <label for="email">Email:</label>
                <input type="email" id="email" name="email" required>
                <br>
                <label for="message">Message:</label>
                <textarea id="message" name="message" required></textarea>
                <br>
                <input type="submit" value="Submit">
            </form>
        </section>
    </main>
    <footer>
        <p>&copy; 2024 My Website</p>
    </footer>
</body>
</html>

Explanation of Semantic Elements

  1. <header>: Represents introductory content, typically a group of introductory or navigational aids.
  2. <nav>: Contains navigation links.
  3. <main>: The main content of the document. Only one <main> element is allowed per document.
  4. <section>: A standalone section of content, which can contain headings, articles, and other sections.
  5. <article>: Independent, self-contained content (e.g., blog posts, news articles).
  6. <aside>: Content indirectly related to the main content (e.g., sidebars, callouts).
  7. <footer>: Contains footer content, such as copyright information.

HTML Forms

Forms are used to collect user input. Here are the basic form elements:

  1. <form>: The container for form elements.
  2. <input>: Used to create input fields. Types include text, email, password, submit, etc.
  3. <label>: Describes the input element.
  4. <textarea>: Multiline text input.
  5. <select>: Dropdown list.
  6. <button>: Clickable button.

Example Form

Here's a form with various input types:

<form action="/submit" method="post">
    <label for="name">Name:</label>
    <input type="text" id="name" name="name" required>
    <br>
    <label for="email">Email:</label>
    <input type="email" id="email" name="email" required>
    <br>
    <label for="password">Password:</label>
    <input type="password" id="password" name="password" required>
    <br>
    <label for="gender">Gender:</label>
    <input type="radio" id="male" name="gender" value="male">
    <label for="male">Male</label>
    <input type="radio" id="female" name="gender" value="female">
    <label for="female">Female</label>
    <br>
    <label for="hobbies">Hobbies:</label>
    <input type="checkbox" id="hiking" name="hobbies" value="hiking">
    <label for="hiking">Hiking</label>
    <input type="checkbox" id="reading" name="hobbies" value="reading">
    <label for="reading">Reading</label>
    <br>
    <label for="country">Country:</label>
    <select id="country" name="country">
        <option value="us">United States</option>
        <option value="ca">Canada</option>
        <option value="uk">United Kingdom</option>
    </select>
    <br>
    <label for="message">Message:</label>
    <textarea id="message" name="message"></textarea>
    <br>
    <button type="submit">Submit</button>
</form>

 

Explanation of Form Elements

  1. <input type="text">: Single-line text input.
  2. <input type="email">: Email address input.
  3. <input type="password">: Password input.
  4. <input type="radio">: Radio button for selecting one option.
  5. <input type="checkbox">: Checkbox for selecting multiple options.
  6. <select>: Dropdown list.
  7. <textarea>: Multiline text input.
  8. <button>: Clickable button to submit the form.

This guide covers the essentials of HTML structure, semantic elements, and form creation. Each element serves a specific purpose to enhance the structure and usability of web pages. Join Lupleg Community

 


   
Quote
Share: