Interview Q&A · questions with model answers

HTML & CSS Interview Questions

Part of the study plan for: Frontend Engineer · Full Stack Engineer

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked What is the difference between script, script async and script defer?

    A plain script blocks HTML parsing while it downloads and runs. async downloads in parallel and runs as soon as it arrives, in no guaranteed order. defer downloads in parallel and runs after parsing…

  2. Most asked Compare localStorage, sessionStorage and cookies.

    localStorage persists per origin until cleared; sessionStorage lasts for one tab's session; both hold a few megabytes of strings, are read only by JavaScript and aren't sent to the server. Cookies…

  3. Which head tags matter for SEO and social sharing?

    A unique, descriptive title; a meta description; a canonical link to the preferred URL; the viewport tag; Open Graph tags (og:title, og:description, og:image, og:url) for link previews; and…

  4. Why set width and height on images, and when should you use loading="lazy"?

    width and height let the browser reserve space before the image loads, preventing layout shift (CLS). loading="lazy" defers offscreen images until the user scrolls near them; use it for images below…

  5. What is the difference between a tag, an element and an attribute?

    A tag is the markup in angle brackets, such as <a> or </a>. An element is the whole unit: opening tag, content and closing tag. An attribute is extra information inside the opening tag as…

  6. What is the difference between block and inline elements?

    Block elements (p, div, h1, ul, section) start on a new line and take the full available width. Inline elements (a, span, strong, em, img) flow within a line of text and take only the width of their…

  7. When should you use id and when class?

    Use id for one unique element on the page, for example a section you link to with #id or a form field a label points to. Use class for any number of elements that share a role or style.

  8. What is the difference between article, section and div?

    article is self-contained content that makes sense on its own (a blog post, comment or product card). section is a thematic grouping within a page, usually with a heading. div has no meaning and is…

  9. What is the difference between absolute and relative URLs?

    An absolute URL includes the scheme and host (https://example.com/about). A relative URL is resolved against the current page's address (about.html, ../index.html, /contact). Use relative URLs for…

  10. What is the difference between GET and POST in an HTML form?

    GET appends the form data to the URL as a query string; it suits searches and filters that can be bookmarked and shared. POST sends the data in the request body; use it for anything that changes…

  11. What is the difference between canvas and SVG?

    canvas is a bitmap you draw on with JavaScript (immediate mode): fast for many objects, games and image processing, but pixels have no structure and aren't accessible by default. SVG is vector…

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

    strong marks importance and em marks stress emphasis; both carry meaning. b and i only offset text stylistically (keywords, foreign phrases, technical terms) without implying importance. Use CSS…

  13. When do you use ul, ol and dl?

    ul for items where order doesn't matter, ol for sequences and rankings (numbered automatically), and dl for term-description pairs (dt and dd), such as glossaries or metadata.

Was this page helpful?

Report a mistake