Skip to content
Laviyx Learn

Try

HTML course menu

Beginner HTML Interview Questions and Answers

Common HTML interview questions for freshers with clear answers: what HTML is, tags vs elements, the DOCTYPE, head vs body, block vs inline, div vs span, id vs class, semantic HTML, alt text, and the difference between HTML and HTML5.

Beginner5 min readUpdated
On this page

These questions come up in nearly every front-end or web developer interview for freshers. Try answering each one out loud first, then open the answer. A clear explanation with a small example is better than a memorised definition.

1. What is HTML?#

Show solution

HTML (HyperText Markup Language) is the standard markup language for web pages. It describes the structure and meaning of content (headings, paragraphs, links, images, forms) using elements written as tags. It is not a programming language: it has no logic, variables or loops. CSS handles presentation and JavaScript handles behaviour.

2. What is the difference between a tag and an element?#

Show solution

A tag is the markup itself: the opening tag <p> or the closing tag </p>. An element is the whole thing: the opening tag, its content and the closing tag, for example <p>Hello</p>. Void elements such as <img> consist of a single tag.

3. What does the DOCTYPE do?#

Show solution

<!DOCTYPE html> at the top of a document tells the browser to render the page in standards mode. Without it, browsers use quirks mode, which imitates old browser bugs and can change how layout and sizing work. It is not an HTML element.

4. What goes in the head and what goes in the body?#

Show solution

The <head> contains information about the page that is not displayed in it: <title>, <meta> tags (charset, viewport, description), <link> (stylesheets, icons), <style> and <script>. The <body> contains everything visible: headings, text, images, links, forms.

5. What are void (empty) elements?#

Show solution

Elements that cannot have content and therefore have no closing tag, such as <br>, <hr>, <img>, <input>, <meta> and <link>. Writing <br /> is allowed in HTML, but the slash has no effect.

6. What are attributes? Give examples.#

Show solution

Attributes add information to an element and are written in the opening tag as name="value": href on a link, src and alt on an image, type on an input, id and class on any element. Boolean attributes such as disabled, checked and required are on when present, whatever their value.

7. What is the difference between block and inline elements?#

Show solution

Block elements (<div>, <p>, <h1>, <ul>, <section>) start on a new line and take the full available width. Inline elements (<span>, <a>, <strong>, <em>) flow within a line of text and are only as wide as their content. CSS display can change this.

8. What is the difference between div and span?#

Show solution

Both are generic containers with no meaning, used for styling or scripting. <div> is a block container for grouping larger sections; <span> is an inline container for a word or phrase inside text. Prefer a semantic element when one fits.

9. What is the difference between id and class?#

Show solution

An id must be unique on the page and identifies one element; a class can be shared by many elements, and an element can have several classes. In CSS they are selected with #id and .class. Ids are also used for fragment links (href="#id") and for connecting <label for> to fields.

10. What is semantic HTML and why does it matter?#

Show solution

Using elements according to their meaning: <header>, <nav>, <main>, <article>, <button>, <h1>, rather than generic <div>s styled to look right. It improves accessibility (screen readers navigate by headings and landmarks), SEO (search engines understand the structure), gives built-in keyboard behaviour, and makes code easier to maintain.

11. Why is the alt attribute important?#

Show solution

alt provides a text alternative for an image. Screen readers read it to blind users, browsers show it when the image fails to load, and search engines use it to understand the image. Meaningful images need a short description; purely decorative images should have an empty alt="" so screen readers skip them.

12. What is the difference between strong and b, or em and i?#

Show solution

<strong> marks importance and <em> marks stress emphasis; both carry meaning. <b> and <i> style text as bold or italic without extra importance, for keywords, terms or foreign phrases. If you only want a visual style, use CSS.

13. What is the difference between ordered, unordered and description lists?#

Show solution

<ol> is a numbered list where order matters (steps). <ul> is a bulleted list where order does not matter. <dl> is a list of name-value pairs, with <dt> for terms and <dd> for descriptions (glossaries, metadata). Items in <ol> and <ul> are <li> elements.

Show solution

Add target="_blank": <a href="https://example.com" target="_blank">Example</a>. Modern browsers apply rel="noopener" behaviour by default, so the new page cannot control the original one. Use it sparingly and tell users the link opens a new tab.

15. What is the difference between HTML and HTML5?#

Show solution

"HTML5" was the name for the major update that added semantic elements (<header>, <nav>, <article>, <section>, <footer>), native <audio> and <video>, <canvas>, new input types (email, date, range), built-in form validation, and APIs such as local storage. Today HTML is maintained as a single Living Standard by WHATWG, which is continuously updated rather than released in numbered versions.

16. What are HTML entities?#

Show solution

Character references that display characters with special meaning or that are hard to type: &lt; for <, &gt; for >, &amp; for &, &quot; for ", &nbsp; for a non-breaking space, &copy; for ©. Any Unicode character can be written numerically, such as &#8377; for ₹.

Keep going#

Move on to the intermediate HTML questions, or browse every question with hints on the HTML interview page.

Finished this lesson?