HTML Interview Questions and Answers for 10 years experience

100 HTML Interview Questions & Answers (10 Years Experience)
  1. What is the difference between HTML and XHTML?

    • Answer: HTML is a markup language that allows for flexibility in syntax, while XHTML is an XML-based version of HTML that requires strict syntax rules. XHTML is more strict about well-formedness, requiring proper nesting and closing of tags, while HTML is more forgiving. XHTML documents must be served with a `text/xml` MIME type, while HTML documents use `text/html`. XHTML's stricter nature offers potential benefits in terms of validation and interoperability but has largely been superseded by HTML5.
  2. Explain the difference between inline, block, and inline-block elements.

    • Answer: Inline elements only take up as much width as necessary and don't start on a new line. Block elements always start on a new line and take up the full width available. Inline-block elements combine features of both: they take up only the space they need but can be styled with width and height properties, and don't always start on a new line.
  3. What are semantic HTML5 elements and why are they important?

    • Answer: Semantic HTML5 elements (like `
      `, `
  4. Explain the use of `DOCTYPE`.

    • Answer: The `DOCTYPE` declaration tells the browser which version of HTML the document uses, allowing the browser to render the page correctly according to that specification. It triggers standards mode (or quirks mode if missing or incorrectly specified) which affects how the browser interprets the HTML.
  5. How do you create a responsive website using HTML and CSS?

    • Answer: Responsive web design uses techniques like fluid grids (using percentages for widths), flexible images (`max-width: 100%`), media queries (applying different styles based on screen size), and viewport meta tags (``) to ensure a website adapts to different screen sizes and devices.
  6. What are HTML5 APIs? Give examples.

    • Answer: HTML5 APIs are built-in features that allow web pages to interact with the user's device and the web. Examples include Geolocation (obtaining user's location), Web Storage (local storage and session storage), Web Workers (multithreading), Canvas (drawing graphics), Drag and Drop, and WebSockets (real-time communication).
  7. Explain the difference between `