1. What is HTML?
HTML (HyperText Markup Language) is the standard language used to create and structure content on the web. It defines the layout of web pages using elements like headings, paragraphs, images, links, and more.
2. What is the basic structure of an HTML document?
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
<!DOCTYPE html> – defines the document type.
<html> – root of the HTML document.
<head> – contains metadata and the page title.
<body> – contains the content displayed on the page.
3. What is the difference between <div> and <span>?
<div> is a block-level element used for grouping larger chunks of content.
<span> is an inline element used for styling or scripting small portions within text.
Example:
<div>This is a block element</div>
<p>This is a <span>highlighted</span> word.</p>
4. What are semantic HTML tags?
Semantic tags clearly describe their meaning in a human and machine-readable way.
Examples include:
<header>, <footer>, <article>, <section>, <nav>
Benefit: They improve accessibility and SEO.
5. What is the purpose of the alt attribute in an <img> tag?
The alt (alternative text) attribute describes the image when it can't be displayed. It is important for accessibility and screen readers.
<img src="logo.png" alt="Company Logo">
6. How do you create a hyperlink in HTML?
Answer: Use the <a> tag with the href attribute.
<a href="https://www.example.com">Visit Example</a>
7. What is the difference between id and class in HTML?
id is unique and used to identify a single element.
class is reusable and used to group multiple elements.
<p id="intro">This is unique</p>
<p class="highlight">This is styled</p>
8. What is the role of the <meta> tag in HTML?
<meta> tags provide metadata about the HTML document, such as character set, viewport settings, or SEO information.
Example:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9. What is the use of the <form> tag?
Answer:
The <form> tag is used to collect user input and send it to a server.
Example:
<form action="/submit" method="POST">
<input type="text" name="username">
<button type="submit">Submit</button>
</form>
10. What are void elements in HTML?
Void elements are self-closing elements that don't need a closing tag.
Examples: <br>, <hr>, <img>, <input>, <meta>
No comments:
Post a Comment