Interview Questions

HTML Interview Questions and Answers

  1. What is HTML?

    HTML stands for HyperText Markup Language. It is the standard language used to create and design webpages.

  2. What are the advantages of using HTML?
    • Universal Standard
    • Simple Syntax
    • Accessibility
    • Integration with CSS and JavaScript
    • Extensibility
  3. Difference Between HTML and XHTML

    HTML is more flexible with syntax rules, while XHTML adheres to stricter XML rules. XHTML requires well-formed documents, including closed tags and lowercase element names.

  4. Basic Building Blocks of HTML
    • Elements: The fundamental building blocks, like <div>, <p>, <a>, etc.
    • Tags: Elements are defined by tags, such as <tagname>content</tagname>.
    • Attributes: Provide additional information about elements, such as id, class, src, etc.
  5. Difference Between HTML Tags and Attributes

    Tags define the structure and content of HTML elements. E.g., <p>, <div>. Attributes provide additional information about an HTML element. E.g., <img src="image.jpg" alt="Description">.

  6. Syntax of an HTML Tag

    The syntax of an HTML tag is:

    <tagname attribute="value">Content</tagname>
    • Opening Tag: <tagname>
    • Attributes (optional): attribute="value"
    • Content (optional): Text or other tags between the opening and closing tags
    • Closing Tag: </tagname>
  7. HTML Attribute

    An attribute provides additional information about an element and is written within the opening tag of the element. Attributes usually come in name-value pairs: name="value".

  8. Different Types of HTML Attributes
    • Global Attributes: Can be applied to any HTML element (e.g., class, id, style).
    • Event Attributes: Trigger JavaScript functions (e.g., onclick, onmouseover).
    • Specific Attributes: Relevant to specific tags (e.g., src for <img>, href for <a>).
  9. Difference Between Block-Level and Inline Elements

    Block-Level Elements start on a new line and take up the full width available (e.g., <div>, <p>, <h1>). Inline Elements do not start on a new line and take up only as much width as necessary (e.g., <span>, <a>, <strong>).

  10. Hyperlink in HTML

    A hyperlink is created using the <a> tag and allows users to navigate from one page to another. Example:

    <a href="https://www.example.com">Visit Example</a>
  11. Difference Between Absolute and Relative URLs
    • Absolute URL: A full URL that includes the protocol and domain (e.g., https://www.example.com/page).
    • Relative URL: A partial URL relative to the current page’s URL (e.g., /page or page.html).
  12. Mailto Link in HTML

    A mailto link opens the default email client to send an email. Example:

    <a href="mailto:example@example.com">Email Us</a>
  13. Image Tag in HTML

    The <img> tag is used to embed images in a webpage. Example:

    <img src="image.jpg" alt="Description of image">
  14. Different Types of Images
    • JPEG: Common for photos.
    • PNG: Supports transparency.
    • GIF: Supports animations.
    • SVG: Scalable vector graphics.
  15. HTML Table

    An HTML table displays data in rows and columns. Example:

    <table>
          <tr>
            <th>Header 1</th>
            <th>Header 2</th>
          </tr>
          <tr>
            <td>Data 1</td>
            <td>Data 2</td>
          </tr>
        </table>
  16. Different Parts of an HTML Table
    • <table>: Container for the table.
    • <tr>: Table row.
    • <th>: Table header cell.
    • <td>: Table data cell.
  17. HTML Form

    An HTML form collects user input. Example:

    <form action="/submit" method="post">
          <label for="name">Name:</label>
          <input type="text" id="name" name="name">
          <input type="submit" value="Submit">
        </form>
  18. Different Types of Form Controls
    • Text Input: <input type="text">
    • Password Input: <input type="password">
    • Checkbox: <input type="checkbox">
    • Radio Button: <input type="radio">
    • Select Menu: <select>
    • Button: <button>
  19. Difference Between GET and POST Requests
    • GET: Sends data via the URL, suitable for retrieving data. Data is visible in the URL.
    • POST: Sends data in the request body, suitable for submitting data. Data is not visible in the URL.
  20. Difference Between a Text Area and a Text Input
    • Text Area: <textarea> allows multiple lines of input.
    • Text Input: <input type="text"> allows single-line input.
  21. HTML List

    An HTML list organizes items into a list format. There are two main types:

    • Ordered List (<ol>): Numbered list.
    • Unordered List (<ul>): Bulleted list.
  22. Difference Between Ordered and Unordered Lists
    • Ordered List: Items are numbered (e.g., <ol><li>Item 1</li></ol>).
    • Unordered List: Items are bulleted (e.g., <ul><li>Item 1</li></ul>).
  23. HTML Heading

    **HTML headings** are used to define headings on a webpage. There are six levels of headings:

    • <h1>: Most important heading.
    • <h2>: Second level.
    • <h3>: Third level.
    • <h4>: Fourth level.
    • <h5>: Fifth level.
    • <h6>: Least important heading.
  24. HTML Paragraph

    An HTML paragraph is defined by the <p> tag and represents a block of text.

  25. HTML Span

    The <span> tag is used for inline styling or grouping text within a block-level element.

  26. HTML Div

    The <div> tag is used for grouping block-level elements and applying styles or scripts.

  27. Difference Between and
    • <span>: Inline container for styling or scripting.
    • <div>: Block-level container for grouping larger sections.
  28. Difference Between an HTML Class and ID

    • Class: Can be applied to multiple elements (e.g., <div class="myClass">). Used for grouping similar elements.
    • ID: Must be unique within a document (e.g., <div id="uniqueId">). Used for unique element identification.
  29. Purpose of the Alt Attribute

    The alt attribute provides alternative text for images when they cannot be displayed. It improves accessibility and SEO.

Creative Footer for Interview Questions