FrontendDeveloper.in

HTML Interview Questions

Filter by topic:
  • Semantic HTML uses elements that describe meaning, such as header, main, article, nav, and footer, instead of generic wrappers everywhere.

    It matters because:

    • It improves accessibility for screen readers.
    • It helps search engines understand page structure.
    • It makes code easier to maintain for developers.
  • id should be unique in a document and is best for one specific element. class can be reused across many elements.

    Use class for styling patterns and component states. Use id for unique relationships like label associations or in-page anchors.

  • data-* attributes let you store custom data directly on HTML elements.

    Example:

    <button data-product-id="sku_123">Buy</button>
    

    This is useful for connecting markup with JavaScript behavior without creating invalid custom attributes.

  • The viewport tag controls responsive scaling on mobile devices.

    Typical usage:

    <meta name="viewport" content="width=device-width, initial-scale=1" />
    

    This ensures the layout width maps to device width and avoids zoomed-out mobile rendering.

  • alt text provides a text alternative for users who cannot see images and is announced by assistive technologies.

    It also helps when images fail to load and gives search engines context about image content.

  • ARIA adds accessibility metadata when native HTML alone cannot express needed semantics.

    Rule of thumb: use native semantic elements first. Add ARIA only when necessary for custom widgets.

  • Void elements do not have closing tags because they cannot contain children, e.g., img, input, br, hr, meta, link.

    Writing closing tags for void elements is invalid in HTML.