HTML Coding Examples

User: How do I create a basic HTML page?

AI Chat Assistant: To create a basic HTML page, you can use the following structure:

Example 1: Basic HTML Structure

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Your Page Title</title>
</head>
<body>
  <h1>Hello, World!</h1>
  <p>This is a simple HTML page.</p>
</body>
</html>

User: How can I add CSS to style my HTML?

AI Chat Assistant: You can add CSS in the "head" section using a <style> tag or link to an external stylesheet. Here’s how to add internal styles:

Example 2: Adding CSS Styles

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Styled Page</title>
  <style>
    body {
      background-color: lightblue;
      font-family: Arial, sans-serif;
    }
    h1 {
      color: darkblue;
    }
  </style>
</head>
<body>
  <h1>Welcome</h1>
  <p>This page is styled with CSS.</p>
</body>
</html>

User: How do I create a simple contact form?

AI Chat Assistant: You can create a contact form using the <form> element. Here’s a basic example:

Example 3: Creating a Contact Form

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Contact Form</title>
</head>
<body>
  <h1>Contact Us</h1>
  <form action="/submit-form" method="post">
    <label for="name">Name:</label><br>
    <input type="text" id="name" name="name" required><br>
    <label for="email">Email:</label><br>
    <input type="email" id="email" name="email" required><br>
    <input type="submit" value="Submit">
  </form>
</body>
</html>

User: How can I add JavaScript to my HTML page?

AI Chat Assistant: You can include JavaScript using the <script> tag. Here’s an example of adding an external JS file:

Example 4: Including External JavaScript

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript Example</title>
  <script src="script.js" defer></script>
</head>
<body>
  <h1>Hello, World!</h1>
  <script>
    console.log("This is an inline JavaScript example.");
  </script>
</body>
</html>

User: What are semantic HTML elements?

AI Chat Assistant: Semantic HTML elements clearly describe their meaning in a readable way. Here’s an example using semantic tags:

Example 5: Using Semantic HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Semantic HTML</title>
</head>
<body>
  <header>
    <h1>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>
      <h2>About Us</h2>
      <p>Our company is dedicated to excellence.</p>
    </section>
  </main>
  <footer>
    <p>© 2023 My Website</p>
  </footer>
</body>
</html>

Example 6: Troubleshooting HTML Errors

If your HTML page isn't displaying correctly, consider the following: