HTML Basics
What is HTML?
HTML, or HyperText Markup Language, is the standard markup language used to create web pages. It describes the structure of a web page using a series of elements or tags that define the content and layout.
What are the basic components of an HTML document?
The basic components of an HTML document include:
- DOCTYPE declaration: Specifies the HTML version being used (e.g.,
<!DOCTYPE html>). - <html> element: The root element of an HTML page.
- <head> section: Contains meta-information about the document, such as title, character set, and linked stylesheets.
- <body> section: Contains the content of the HTML document that is visible to users, including text, images, and links.
What is the purpose of the <head> element in HTML?
The <head> element is used to contain meta-information about the HTML document, such as the document title, character set, stylesheets, and scripts. It does not display content on the page.
<head>
<meta charset="UTF-8">
<title>My Web Page</title>
<link rel="stylesheet" href="styles.css">
</head>
What is the significance of the <body> element?
The <body> element contains all the content that is displayed on the web page, including text, images, videos, links, and other media. It is the main area where user interaction occurs.
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text.</p>
<img src="image.jpg" alt="A description of the image">
</body>
What are HTML tags and attributes?
HTML tags are the building blocks of HTML, used to create elements. Tags are enclosed in angle brackets (e.g., <tag>), and most tags have a corresponding closing tag (e.g., </tag>). Attributes provide additional information about an element and are placed within the opening tag.
<a href="https://www.example.com" target="_blank">Visit Example</a>
What is the purpose of the alt attribute in the <img> tag?
The alt attribute provides alternative text for an image in case it cannot be displayed. It is essential for accessibility as it allows screen readers to describe the image to users with visual impairments.
<img src="logo.png" alt="Company Logo">
How do you create a hyperlink in HTML?
You can create a hyperlink using the <a> tag, specifying the target URL in the href attribute. The content inside the <a> tag is the clickable text or element.
<a href="https://www.google.com">Go to Google</a>
What are semantic HTML elements?
Semantic HTML elements are tags that convey meaning about their content. They help improve the accessibility and search engine optimization (SEO) of a web page. Examples include <header>, <footer>, <article>, <section>, and <nav>.
<header>
<h1>Website Title</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
How do you create a form in HTML?
You can create a form using the <form> tag, which can contain various input elements such as text fields, checkboxes, radio buttons, and buttons.
<form action="/submit" method="POST">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<button type="submit">Submit</button>
</form>
What are the different types of input fields in HTML forms?
There are several types of input fields in HTML forms, including:
- Text:
<input type="text"> - Password:
<input type="password"> - Email:
<input type="email"> - Checkbox:
<input type="checkbox"> - Radio:
<input type="radio"> - File:
<input type="file"> - Submit:
<input type="submit">