HTML interview questions
HTML interview questions
1. What is HTML?
Answer: HTML (HyperText Markup Language) is the standard language for creating web pages. It uses a series of
elements (tags) to structure content on a webpage.
Answer:
Answer:
Answer:
Tags define elements, e.g., <p> for paragraphs, <img> for images.
Attributes provide additional information, e.g., <img src="image.jpg" alt="Image">, where src and alt are
attributes.
Answer:
Block-level elements (<div>, <p>, <h1>) start on a new line and take full width.
Inline elements (<span>, <a>, <strong>) do not start on a new line and only take as much width as needed.
Answer: The <!DOCTYPE> declaration tells the browser which version of HTML to use. Example:
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>
Answer:
html
CopyEdit
<br>
<hr>
Answer: Void elements are tags that do not have a closing tag, such as <img>, <br>, <input>, <hr>.
11. What is the difference between <strong> and <b>, <em> and <i>?
Answer:
<strong> (semantic) makes text bold for importance, while <b> (non-semantic) just makes it bold.
<em> (semantic) emphasizes text (italic), while <i> just makes it italic for style.
12. What is the difference between absolute, relative, and fixed positioning in CSS?
Answer:
Absolute: Positions relative to the nearest positioned ancestor or the <html> if none.
html
CopyEdit
Answer:
html
CopyEdit
<ol>
<li>Item 1</li>
<li>Item 2</li>
</ol>
html
CopyEdit
<ul>
<li>Item A</li>
<li>Item B</li>
</ul>
15. What is the difference between <section>, <article>, and <div>?
Answer:
Answer:
html
CopyEdit
Answer: It provides metadata such as character set, viewport settings, SEO keywords, and author info.
html
CopyEdit
Answer:
Answer:
html
CopyEdit
21. What is the difference between <input type="submit"> and <button type="submit">?
Answer: <button> allows custom HTML inside, whereas <input> is limited to text.
html
CopyEdit
Answer: Text (text), Password (password), Email (email), Checkbox (checkbox), Radio (radio), File (file), Submit (submit).
24. What is the difference between local storage, session storage, and cookies?
Answer:
25. What are custom data attributes in HTML? How are they used?
html
CopyEdit
js
CopyEdit
console.log(userId);