1. What is HTML?
Answer: HTML (HyperText Markup Language) is the standard markup language used to create web pages. It is used to structure the content on the web, defining elements like headings, paragraphs, links, images, and other multimedia elements.
2. What is a tag in HTML?
Answer: A tag in HTML is a code that defines the structure and content of web pages. Tags are enclosed in angle brackets, e.g., <tagName>. Most tags come in pairs, with an opening tag <tag> and a closing tag </tag> and some are self-closing tags.
3. What are attributes in HTML?
Answer: Attributes in HTML provide additional information about HTML elements. They are always specified in the opening tag and most commonly used HTML attributes are, name, value, id, class and more.
For example, <a href="https://www.geekshelp.com">Geeks Help </a>.
4. What is the difference between HTML and XHTML?
Answer: HTML is a markup language that allows for some flexibility in code, such as unclosed tags and attributes without quotes. XHTML (eXtensible HyperText Markup Language) is a stricter version of HTML, requiring well-formed code, proper nesting, and all tags to be closed.
5. What is the purpose of the <!DOCTYPE> declaration in HTML?
Answer: The <!DOCTYPE> declaration defines the document type and version of HTML. It helps the browser understand how to render the web page correctly. For HTML5, the declaration is <!DOCTYPE html>.
6. What are HTML semantic elements?
Answer: HTML tags that provide meaning for the content they contain are known as semantic elements. <header>, <footer>, <article>, <section>, and <nav> are a few examples of semantic HTML elements.. SEO and accessibility are improved by these tags.
7. What is the difference between an inline element and a block-level element in HTML?
Answer: Inline elements do not start on a new line and only take up as much width as necessary. Examples include <span>, <a>, and <img>. Block-level elements start on a new line and take up the full width available. Examples include <div>, <p>, <h1>, and <table>.
8. How do you create a hyperlink in HTML?
Answer: We can create a hyperlink using the <a> tag with the href attribute.
For example: <a href="https://www.naukrinotice.in"> Naukri Notice</a>
9. How do you add an image to an HTML page?
Answer: We can add an image using the <img> tag with the src attribute specifying the image source. For example: <img src="image.jpg" alt="Description of image">
10. What is the alt attribute used for in images?
Answer: The alt attribute provides alternative text for an image if it cannot be displayed. It is also used by screen readers to describe images for visually impaired users.
11. What is the difference between <div> and <span>?
Answer: <div> is a block-level element used to group other elements, while <span> is an inline element used to group inline elements. <div> creates a new block, while <span> does not.
12. How do you create a table in HTML?
Answer: You create a table using the <table> tag along with <tr> for table rows, <th> for table headers, and <td> for table data cells.
For Example:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
13. What is the purpose of the <head> tag in HTML?
Answer: The <head> tag contains meta information about the HTML document, such as the title, character set, styles, scripts, and other meta tags. It does not display content on the page.
14. What is the <meta> tag used for?
Answer: The <meta> tag provides metadata about the HTML document, such as the character set, author, description, and viewport settings for responsive design. It is placed within the <head> tag.
15. How do you create a form in HTML?
Answer: You create a form using the <form> tag, with various input elements such as <input>, <textarea>, <select>, and <button>.
For example:
<form action="/submit" method="post">
<input type="text" name="name" placeholder="Enter your name">
<input type="submit" value="Submit">
</form>
16. What is the difference between the id and class attributes in HTML?
Answer: The id attribute is used to uniquely identify a single HTML element, while the class attribute can be used to identify multiple elements with the same class name. IDs must be unique, but classes can be reused.
17. How do you include a CSS file in an HTML document?
Answer: You include a CSS file using the <link> tag within the <head> section of the HTML document.
For example: <link rel="stylesheet" href="styles.css">
18. How do you include JavaScript in an HTML document?
Answer: You include JavaScript using the <script> tag. It can be placed within the <head>, <body>, or included as an external file.
For example:
<script src="script.js"></script>
OR
<script> // JavaScript code here </script>
19. What is the data-* attribute used for in HTML?
Answer: The data-* attribute is used to store custom data private to the page or application. It allows you to embed custom data attributes on all HTML elements.
For example: <div data-custom="value">Content</div>
20. What are self-closing tags in HTML?
Answer: Self-closing tags, also known as void elements, do not require a closing tag. They include tags like <img>, <br>, <hr>, and <input>. In XHTML, they are written with a closing slash, e.g., <img src="image.jpg" />.