HTML & CSS Interview Question #8
What are void elements in HTML?
HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms Junior Beginner
Quick Interview Answer
Void elements cannot contain child content and do not have an end tag in HTML syntax. Examples include img, input, br, hr, meta, link, source, and area.
Detailed Explanation
Void elements cannot contain child content and do not have an end tag in HTML syntax. Examples include img, input, br, hr, meta, link, source, and area.
Writing a slash before the closing angle bracket, such as <img />, is permitted by many tools and conventions, but HTML does not require XML-style self-closing syntax for void elements.
Code Example
<img src="product.jpg" alt="Wireless charger">
<input type="email" name="email">
<br>
<hr>
<meta charset="UTF-8">