HTML Interview Questions and Answers (Set 12)

Introduction

This twelfth set of HTML interview questions further explores advanced topics and practical applications. The questions and answers provide insights into HTML’s versatility and its integration with modern web development practices.


191. How do you create a collapsible section in HTML?

  • Answer: Use the <details> and <summary> tags:
    <details>
      <summary>Click to Expand</summary>
      <p>This is hidden content that can be toggled.</p>
    </details>
    

    Explanation: The <details> element creates a collapsible section, with <summary> serving as the clickable label.


192. How do you specify a placeholder for a <textarea>?

  • Answer: Use the placeholder attribute:
    <textarea placeholder="Enter your message here..."></textarea>
    

    Explanation: The placeholder attribute displays a hint within the <textarea> until the user enters text.


193. What is the <template> tag in HTML?

  • Answer: Defines a fragment of HTML that is not rendered until activated with JavaScript.
    <template id="myTemplate">
      <p>This is template content.</p>
    </template>
    

    Explanation: The <template> tag is useful for defining reusable HTML blocks that can be dynamically inserted into the DOM.


194. How do you set the tabbing order of elements?

  • Answer: Use the tabindex attribute:
    <button tabindex="1">First</button>
    <button tabindex="2">Second</button>
    

    Explanation: The tabindex attribute defines the order in which elements are focused when navigating with the keyboard.


195. How do you group multiple checkboxes in a form?

  • Answer: Use the <fieldset> element to group related checkboxes:
    <fieldset>
      <legend>Choose your hobbies:</legend>
      <label><input type="checkbox" name="hobby" value="reading"> Reading</label>
      <label><input type="checkbox" name="hobby" value="sports"> Sports</label>
    </fieldset>
    

    Explanation: The <fieldset> and <legend> elements enhance form accessibility by grouping related inputs.


196. What is the <progress> tag, and how is it used?

  • Answer: Displays the progress of a task.
    <progress value="50" max="100">50%</progress>
    

    Explanation: The <progress> tag visually represents a task’s completion level, such as file upload progress.


197. How do you create a dropdown menu with optgroups?

  • Answer: Use the <optgroup> tag within a <select> element:
    <select>
      <optgroup label="Fruits">
        <option value="apple">Apple</option>
        <option value="banana">Banana</option>
      </optgroup>
      <optgroup label="Vegetables">
        <option value="carrot">Carrot</option>
        <option value="broccoli">Broccoli</option>
      </optgroup>
    </select>
    

    Explanation: The <optgroup> tag groups related options, improving the organization and readability of dropdown menus.


198. What is the <abbr> tag used for?

  • Answer: Represents an abbreviation or acronym.
    <p><abbr title="Hypertext Markup Language">HTML</abbr> is the language of the web.</p>
    

    Explanation: The title attribute provides the full form of the abbreviation, displayed as a tooltip.


199. How do you make a button that resets a form?

  • Answer: Use the <button> tag with type="reset":
    <form>
      <input type="text" name="username">
      <button type="reset">Reset</button>
    </form>
    

    Explanation: A reset button clears all user inputs in the form, restoring default values.


200. How do you create an image that links to another page?

  • Answer: Wrap the <img> tag inside an <a> tag:
    <a href="https://example.com">
      <img src="image.jpg" alt="Clickable Image">
    </a>
    

    Explanation: Clicking the image navigates the user to the specified URL.


201. How do you create a multi-select dropdown?

  • Answer: Add the multiple attribute to the <select> tag:
    <select multiple>
      <option value="option1">Option 1</option>
      <option value="option2">Option 2</option>
    </select>
    

    Explanation: The multiple attribute allows users to select more than one option from the dropdown.


202. What is the <bdi> tag?

  • Answer: Isolates a segment of text for bidirectional text support.
    <p>Username: <bdi>user123</bdi></p>
    

    Explanation: The <bdi> tag ensures that the directionality of the text does not affect surrounding content.


203. How do you embed a YouTube video in HTML?

  • Answer: Use an <iframe> tag:
    <iframe width="560" height="315" src="https://www.youtube.com/embed/example" frameborder="0" allowfullscreen></iframe>
    

    Explanation: The <iframe> tag embeds YouTube videos with customizable dimensions and playback controls.


204. How do you create a table with a caption?

  • Answer: Use the <caption> tag inside a <table>:
    <table border="1">
      <caption>Student Grades</caption>
      <tr>
        <th>Name</th>
        <th>Grade</th>
      </tr>
      <tr>
        <td>John</td>
        <td>A</td>
      </tr>
    </table>
    

    Explanation: The <caption> tag provides a descriptive title for the table.


Conclusion

This set of advanced HTML interview questions highlights practical applications and techniques to enhance your web development skills. Let me know if you’d like more sets or refinements!

Scroll to Top