1. What is HTML?
HTML stands for HyperText Markup Language. It is the standard markup language used to create the structure of web pages.
2. What is the basic structure of an HTML document?
An HTML document consists of the following basic structure:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<!-- Content of the document goes here -->
</body>
</html>
3. What is the purpose of the <!DOCTYPE html> declaration?
The <!DOCTYPE html> declaration defines the document type and version of HTML being used. It helps browsers to render the web page correctly.
4. Explain the difference between block-level and inline elements.
Block-level elements start on a new line and take up the full width available, while inline elements do not start on a new line and only take up as much width as necessary.
5. What is the role of the <head> section in an HTML document?
The <head> section contains meta-information about the HTML document, such as the title, character set, styles, scripts, and other metadata.
6. How do you create a hyperlink in HTML?
Use the <a> (anchor) element with the href attribute to create a hyperlink. For example:
<a href="https://www.example.com">Visit Example.com</a>
7. Explain the difference between the <div> and <span> elements.
<div> is a block-level element used to group other elements and apply styles, while <span> is an inline element typically used for applying styles or scripting to a specific part of text within a block.
8. How do you add comments in HTML?
Comments in HTML are added using the <!-- ... --> syntax. For example:
<!-- This is a comment -->
9. What is the purpose of the alt attribute in the <img> tag?
The alt attribute in the <img> tag provides alternative text for an image, which is displayed if the image cannot be loaded. It also aids accessibility by providing a description of the image for screen readers.
10. How can you create an ordered list in HTML?
Use the <ol> (ordered list) element along with <li> (list item) elements. For example:
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
11. Explain the purpose of the <meta> tag.
The <meta> tag is used to provide metadata about the HTML document. Common uses include specifying the character set, setting the viewport for responsive design, and providing information for search engines.
12. What is the difference between the <header> and <h1> elements?
The <header> element is a container for introductory content or a set of navigation links, while <h1> is a heading element that defines the main heading of the document. The <h1> element is often placed within the <header>.
13. How can you create a line break in HTML?
Use the <br> (break) tag to create a line break. For example:
This is the first line.<br>
This is the second line.
14. What is the role of the <form> element in HTML?
The <form> element is used to create an HTML form for user input. It can contain various form elements like text fields, checkboxes, radio buttons, and buttons. The form data can be submitted to a server for processing.
15. Explain the difference between GET and POST methods in a form.
The GET method appends form data to the URL in the form of query parameters, visible in the address bar. POST method sends form data in the HTTP request body, making it more secure and suitable for sensitive information.
16. What is the purpose of the target attribute in the <a> tag?
The target attribute in the <a> tag specifies where to open the linked document. Common values include _blank (open in a new tab or window) and _self (open in the same tab or window).
17. How can you create a table in HTML?
Use the <table> element to create a table, and <tr> (table row), <th> (table header), and <td> (table data) elements to define the structure. For example:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
18. What does the colspan attribute do in a <td> element?
The colspan attribute in a <td> element specifies the number of columns the cell should span or occupy in a table.
19. How do you embed an audio file in HTML?
Use the <audio> element with the src attribute to embed an audio file. For example:
<audio controls>
<source src="audio.mp3" type="audio/mp3">
Your browser does not support the audio tag.
</audio>
20. What is the purpose of the <iframe> element?
The <iframe> element is used to embed another HTML document within the current document. It is commonly used to include external content such as maps, videos, or other web pages.
21. What is semantic HTML, and why is it important?
Semantic HTML involves using tags that carry meaning about the structure and content of the page (e.g., <header>, <nav>, <article>, <footer>). It is important for accessibility, search engine optimization, and maintaining a clear and meaningful structure in the code.
23. How can you create a hyperlink that opens an email client with a pre-filled subject?
Use the <a> tag with the mailto scheme in the href attribute. For example:
<a href="mailto:example@email.com?subject=Feedback">Send Email</a>
24. How can you include external CSS styles in an HTML document?
Use the <link> element within the <head> section with the href attribute pointing to the external CSS file. For example:
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
25. What is the purpose of the <blockquote> element?
The <blockquote> element is used to define a block of text that is a quotation from another source. It is often styled to indicate visually that it is a quote.
26. How can you create a horizontal line in HTML?
Use the <hr> (horizontal rule) tag to create a thematic break or horizontal line. For example:
<p>This is some text.</p>
<hr>
<p>This is more text.</p>
27. What is the purpose of the role attribute in HTML?
The role attribute is used to define the role of an element in accessibility. It helps assistive technologies understand the purpose and function of the element on the page.
28. Explain the difference between the <input type="text"> and <textarea> elements.
The <input type="text"> element is used for single-line text input, while the <textarea> element is used for multi-line text input. <textarea> is often used when users need to enter longer paragraphs or multiple lines of text.
29. What is the purpose of the HTML5 Canvas element?
The <canvas> element provides a drawing surface for JavaScript to manipulate and draw graphics, charts, or animations dynamically on a web page.
30. How can you embed a video in HTML?
Use the <video> element with <source> elements for different video formats. For example:
<video width="320" height="240" controls>
<source src="video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
31. What is the purpose of the lang attribute in the <html> tag?
The lang attribute specifies the language of the HTML document. It helps screen readers and search engines understand the language used in the content for better accessibility and indexing.
32. How can you create a dropdown list in HTML?
Use the <select> element to create a dropdown list, and <option> elements to define the available options. For example:
<select>
<option value="option1">Option 1</option>
<option value="option2">Option 2</option>
<option value="option3">Option 3</option>
</select>
33. What is the purpose of the <nav> element in HTML?
The <nav> element is used to define a section of navigation links on a page. It is intended for major navigation blocks and helps assistive technologies and search engines understand the structure of the page.
34. What is the purpose of the placeholder attribute in a form input?
The placeholder attribute provides a short hint that describes the expected value of the input field. It is typically displayed in a lighter color and disappears when the user starts typing.
35. How can you create a clickable button in HTML?
Use the <button> element to create a clickable button. For example:
<button type="button">Click me</button>
36. What is the purpose of the <figcaption> element in HTML?
The <figcaption> element is used to provide a caption or legend for the content inside a <figure> element, often used with images or illustrations.
37. How do you create a hyperlink that opens in a new browser window?
Use the target="_blank" attribute in the <a> tag to open the linked document in a new browser window. For example:
<a href="https://www.example.com" target="_blank">Visit Example.com</a>