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 HTML?

    HTML (HyperText Markup Language) is the standard language for the structure and meaning of web pages. It uses elements written as tags to say what each piece of content is: headings, paragraphs,…

  2. Most asked What is HTML5, and how is it different from HTML 4?

    HTML5 (a W3C Recommendation in 2014, now the WHATWG's HTML Living Standard) modernised HTML for web applications: semantic structure elements, native video and audio, canvas, new form input types…

  3. Most asked What is semantic HTML, and why does it matter?

    Semantic HTML means choosing elements for the meaning of their content (header, nav, main, article, button, ul, table) instead of generic divs and spans. It gives browsers, search engines and…

  4. Most asked What is the alt attribute for, and what makes good alt text?

    alt provides a text alternative for an image, read by screen readers and shown when the image fails to load; search engines use it too. Good alt text briefly conveys what the image means in context.…

  5. Most asked What input types and validation attributes did HTML5 add?

    Types such as email, url, tel, number, range, date, time, color and search, which bring suitable mobile keyboards and pickers and check formats. Validation attributes: required, min, max, step,…

  6. Most asked What is ARIA, and what is the first rule of ARIA?

    ARIA (Accessible Rich Internet Applications) attributes add roles, states and properties for assistive technology when HTML can't express something, such as aria-expanded on a custom disclosure or…

  7. Most asked What does <!DOCTYPE html> do?

    It tells the browser to render the page in standards mode using modern HTML rules. Without a doctype (or with certain old ones), browsers use quirks mode, which emulates old browser bugs and changes…

  8. What goes in the head of an HTML document, and what goes in the body?

    The head holds metadata that isn't displayed: charset, viewport, title, meta description, links to stylesheets and icons, scripts, Open Graph and structured data. The body holds all visible content.

  9. What do the autocomplete and inputmode attributes do?

    autocomplete tells browsers and password managers what a field contains (email, name, street-address, current-password, one-time-code) so they can fill it in. inputmode chooses the on-screen…

  10. What does the viewport meta tag do?

    <meta name="viewport" content="width=device-width, initial-scale=1"> tells mobile browsers to lay out the page at the device's width instead of a virtual desktop width (about 980px), which is what…

  11. What is structured data (JSON-LD), and why add it?

    Machine-readable facts about a page, written with the schema.org vocabulary in a <script type="application/ld+json"> block. Search engines use it to understand entities (articles, products, courses,…

  12. What is the DOM, and how does the browser build it from HTML?

    The DOM (Document Object Model) is the tree of objects the browser builds by parsing HTML; JavaScript and CSS work with this tree, not the source text. HTML5 specifies the parsing algorithm exactly,…

  13. What are data-* attributes for?

    Custom attributes for storing extra information on elements for scripts and CSS, such as data-product-id="42". JavaScript reads them through element.dataset (dataset.productId) and CSS can select…

  14. What do the dialog element and the popover attribute provide?

    dialog is a native modal or non-modal dialog: showModal() traps focus, makes the rest of the page inert, closes on Escape and has a ::backdrop. The popover attribute turns any element into a…

  15. What does the sandbox attribute on an iframe do?

    It applies strict restrictions to the embedded page: no scripts, no form submission, no popups, no top-level navigation, and a unique opaque origin. You re-enable only what's needed with tokens such…

  16. What are resource hints such as preload and preconnect?

    link rel="preconnect" opens the connection (DNS, TCP, TLS) to an origin you'll need soon; rel="preload" fetches a critical resource early (a font, the hero image) with the right as attribute;…

  17. What are HTML entities and when do you need them?

    Entities are codes that represent characters in HTML, such as < for <, > for >, & for & and   for a non-breaking space. You need them for characters that would otherwise be read as…

  18. What is the details element used for?

    details with summary creates a native disclosure widget: the summary is a clickable toggle and the rest of the content shows or hides, with keyboard and screen-reader support built in. Giving…

  19. What is the template element?

    template holds inert HTML that isn't rendered, doesn't load images or run scripts until JavaScript clones its content (template.content.cloneNode(true)) and inserts it into the page. It's used for…

  20. What are web components?

    A set of browser standards for reusable custom elements: Custom Elements (define your own tags with customElements.define), Shadow DOM (encapsulated markup and styles) and HTML templates with slots.…

Was this page helpful?

Report a mistake