Explore top HTML interview questions designed for freshers preparing for web development roles in 2025. This quiz focuses on HTML basics, tags, semantic elements, and best practices to help you review your foundational knowledge and boost interview confidence.
Which of the following correctly describes the structure of an HTML element using tags?
Explanation: An HTML element consists of an opening tag, content, and a closing tag, which together define a section of a document. A single tag with no content represents self-closing or void elements, not full elements. Content without tags is not recognized as an HTML element. Two self-closing tags side by side do not form a valid HTML structure.
What is the main purpose of an attribute in an HTML element, such as class or id?
Explanation: Attributes like class or id give extra information about an element or affect how it behaves. They do not replace the content, close tags, or create comments. Comments in HTML are made using <!-- -->, not attributes.
If you want to create a line break within text on a web page, which tag should you use?
Explanation: The <br> tag is specifically used for creating a line break in text. <hr> creates a horizontal rule, <div> is a block-level section, and <span> is for inline grouping. Only <br> inserts a visible single line break.
Which HTML tag is used to define a row within a table structure?
Explanation: <tr> defines a table row, while <td> is for table data cells, <th> is for header cells, and <table> specifies the entire table. Without <tr>, you cannot properly create a table row.
Which of the following is an example of a self-closing (void) HTML tag?
Explanation: <img> is a self-closing tag used for images and does not require an end tag. <p>, <h1>, and <ul> all need closing tags to specify the end of the element. Using these elements incorrectly can produce errors or unexpected layout issues.
Which tag is considered a semantic HTML element commonly used to define navigation links?
Explanation: <nav> is a semantic tag that clearly indicates navigation sections in a web page. <b> is used for bold text, <font> is deprecated for styling, and <center> is outdated and non-semantic. Only <nav> improves both structure and accessibility.
What is the primary use of the <a> (anchor) tag in HTML documents?
Explanation: The <a> tag is responsible for creating links to other pages or resources using the href attribute. It does not insert images (that's <img>), format text as bold (that's <b>), or define navigation sections (that's <nav>).
Which HTML tag is typically used for grouping inline elements within a block of content?
Explanation: <span> is an inline element designed for grouping text or other inline elements for styling or scripting. <table>, <ol>, and <section> are block-level elements and not intended for inline grouping.
What tag is used to create a new paragraph of text in an HTML document?
Explanation: <p> is the tag used for paragraphs in HTML, ensuring automatic spacing before and after the text. <li> creates list items, <pre> maintains preformatted text, and <body> signifies the main document body but is not for paragraphs alone.
Within a table, which tag is used to denote a header cell that usually appears bold and centered by default?
Explanation: <th> is used for table header cells, giving them distinct styling like bold text and center alignment. <td> is for regular data cells, <tr> creates rows, and <thead> groups header content but doesn't itself create a cell.