HTML Questions
Test your HTML knowledge with 60 interview-style questions covering fundamentals, semantics, forms, accessibility, SEO, performance, and advanced HTML.
1. What is HTML?
HTML stands for HyperText Markup Language. It is the standard markup language used to structure content and describe its semantics on the web. HTML defines elements such as headings, paragraphs, links, forms, images, tables, and semantic page regions.
HTML is a markup language.
HTML defines structure and semantics rather than application logic.
What is HTML primarily used for?
2. Is HTML a programming language?
No. HTML is a markup language. It describes document structure and semantics but does not provide the general-purpose programming constructs associated with programming languages, such as functions, loops, and algorithmic control flow.
HTML is declarative markup.
JavaScript is commonly used when programming behavior is required.
Why is HTML not generally classified as a programming language?
3. What is HTML5?
HTML5 refers to the modern evolution of HTML and the collection of web platform capabilities standardized around HTML. It introduced or standardized many semantic elements and native capabilities such as audio, video, canvas, forms improvements, and more.
Modern HTML includes semantic and multimedia capabilities.
HTML continues to evolve as a web standard.
Which is associated with modern HTML capabilities?
4. What is the purpose of <!DOCTYPE html>?
It tells the browser to use standards mode for the document. The modern HTML doctype is intentionally simple: <!doctype html>.
DOCTYPE is a declaration.
Use the modern HTML doctype in HTML documents.
What does <!doctype html> primarily do?
5. What is the difference between an element and a tag?
A tag is the markup syntax such as <p> or </p>. An element is the complete construct, including its opening tag, content, and closing tag when applicable. For example, <p>Hello</p> is a paragraph element.
Tags are syntax.
Elements represent document nodes and their semantics.
Which represents the complete HTML element?
6. What are void elements?
Void elements are HTML elements that cannot have child content and do not use closing tags. Examples include <img>, <input>, <br>, <hr>, <meta>, and <link>.
Void elements do not contain child nodes.
Do not add unnecessary closing tags to void elements.
Which is a void element?
7. What is the DOM?
The Document Object Model is an object representation of a document that scripts and browser APIs can interact with. The browser parses HTML and creates a tree of nodes representing the document.
The DOM represents document structure.
JavaScript commonly interacts with the DOM.
What does the DOM represent?
8. What is semantic HTML?
Semantic HTML uses elements that communicate the meaning or role of content. Examples include <article>, <nav>, <main>, <header>, and <footer>. Semantic markup improves structure, accessibility, maintainability, and machine understanding.
Semantics communicate meaning.
Prefer meaningful HTML over generic containers when appropriate.
Which is a semantic HTML element?
9. What is the difference between div and span?
Both are generic containers. <div> is normally used as a block-level structural container, while <span> is an inline phrasing container. Neither adds meaningful semantics by itself.
div and span are generic.
Use semantic elements when one accurately describes the content.
Which statement is correct?
10. What is the purpose of the lang attribute?
The lang attribute identifies the language of the element's content. Setting it on the root <html> element helps browsers, search engines, translation tools, and assistive technologies interpret the document correctly.
Declare the document's language.
Language metadata supports accessibility and user agents.
Where is the primary document language commonly declared?
11. What is the difference between strong and b?
<strong> conveys strong importance, while <b> draws attention without necessarily implying additional importance. Both may appear bold by default, but their semantics differ.
Choose elements according to meaning.
Visual boldness is not the same as semantic importance.
Which element communicates strong importance?
12. What is the difference between em and i?
<em> represents stress emphasis, while <i> represents text set apart from normal prose for a reason such as a technical term, idiom, taxonomy, or alternate voice. Both may appear italic by default, but their meanings differ.
Use em when stress emphasis is meaningful.
Do not choose semantic elements solely based on default appearance.
Which element represents stress emphasis?
13. What is the difference between section and article?
<section> represents a thematic grouping of content, usually with a heading. <article> represents a self-contained piece of content that could potentially be distributed or understood independently.
article is independently meaningful content.
section groups related content thematically.
Which element is commonly appropriate for an independently distributable blog post?
14. What is the purpose of the main element?
<main> represents the dominant content of the document. Content repeated across pages such as primary navigation and site-wide footers generally should not be placed inside main.
Use main for the dominant document content.
Avoid putting repeated site-wide content inside main.
What does main represent?
15. Why is alt text important?
Alternative text provides a textual replacement for meaningful images when the image cannot be perceived or loaded. Screen readers can announce it, and it can communicate the image's purpose.
Describe meaningful image information.
Use alt="" for images that are purely decorative when appropriate.
Which attribute provides alternative text?
16. What is the difference between GET and POST in forms?
GET submits form data as part of the request URL, making it suitable for many retrieval/search operations. POST sends the data in the request body and is commonly used for operations that create or modify server-side state. Neither should be treated as a substitute for authentication or authorization.
GET is commonly used for retrieval-oriented submissions.
POST commonly sends form data in the request body.
Which method commonly places form data in the URL?
17. Why is the name attribute important in forms?
The name attribute identifies a successful form control in submitted form data. An input may have an id for DOM and label association, but without a suitable name its value generally will not be included in standard form submission.
id and name serve different purposes.
Use meaningful names for submitted form fields.
Which attribute commonly determines the field name in submitted form data?
18. Why should labels be associated with inputs?
Labels provide an accessible name for form controls and improve usability. Explicitly associating a label with an input also allows users to activate the input by selecting its label.
Every user-facing control should have an appropriate accessible label.
Placeholder text should not replace labels.
How can a label be explicitly associated with an input?
19. What is the purpose of placeholder?
The placeholder attribute provides a short hint about the expected value of a form control. It disappears when the user enters data and should not be treated as a permanent label.
Use labels for identification.
Use placeholders for supplementary hints.
Should placeholder normally replace a visible label?
20. What does the required attribute do?
The required attribute indicates that a form control must have a value before the browser allows normal form submission. It provides native client-side validation.
required enables native mandatory-field validation.
Server-side validation is still necessary.
What does required do?
21. What is the difference between disabled and readonly?
A disabled control is generally not editable, focusable, or included in normal form submission. A readonly control cannot normally be edited by the user but can remain focusable and its value can be submitted when applicable.
disabled and readonly have different interaction and submission behavior.
Choose based on the intended user experience.
Which control is generally excluded from form submission?
22. What is the difference between button types?
A button inside a form defaults to submit behavior in common HTML usage unless another type is specified. type="submit" submits the form, type="button" is a generic action button, and type="reset" resets form controls to their initial values.
Explicitly specify button types when clarity matters.
Use button for actions rather than clickable div elements.
Which button type prevents a button from acting as a form submitter?
23. What is the difference between checkbox and radio inputs?
Checkboxes represent independent binary or multi-select choices. Radio buttons represent mutually exclusive choices within a group sharing the same name.
Checkboxes support independent selection.
Radio groups support one selection among alternatives.
Which control is appropriate when exactly one option should be selected from a group?
24. What is the purpose of autocomplete?
The autocomplete attribute provides hints about the type of information expected in a form control and allows browsers or password managers to provide appropriate stored values. Correct autocomplete tokens can improve usability.
Use appropriate autocomplete tokens.
Autocomplete can improve both usability and completion speed.
What is autocomplete mainly intended to improve?
25. What is the purpose of the viewport meta tag?
The viewport meta tag controls how the layout viewport is configured on mobile browsers. A common configuration is width=device-width, initial-scale=1.0, which helps pages use the device viewport appropriately.
Viewport configuration is important for responsive pages.
Responsive design also requires appropriate CSS.
Which value is commonly used for responsive viewport configuration?
26. What is the difference between id and class?
An id identifies a particular element and should be unique within a document. A class represents membership in a reusable group and can be assigned to multiple elements.
Use id for unique document identity.
Use classes for reusable grouping and styling or scripting hooks.
Which is intended to identify a unique element within a document?
27. What is the difference between href and src?
href generally identifies a referenced destination or relationship, such as a hyperlink or stylesheet. src generally identifies an external resource that an element embeds or loads, such as an image or script.
href and src serve different resource-loading semantics.
Use the attribute appropriate to the HTML element.
Which attribute is used by an anchor to identify its destination?
28. What is the purpose of srcset?
srcset allows developers to provide multiple image resource candidates. The browser can choose an appropriate candidate based on factors such as viewport size and device pixel density.
srcset can improve image delivery efficiency.
Use sizes when providing width-based responsive image candidates.
Why is srcset useful?
29. What is the picture element?
<picture> provides a container for multiple image sources and supports responsive art direction and source selection. Each <source> can specify conditions such as media queries or supported image formats, with <img> serving as the fallback image.
picture supports art direction and source selection.
img remains the fallback image element.
Which element is commonly used as the fallback inside picture?
30. What is lazy loading?
Lazy loading delays loading certain resources until they are likely to be needed. HTML supports this for images and iframes through loading="lazy". It can reduce initial network usage and improve page loading performance.
Lazy loading can reduce initial resource work.
Do not delay resources that are immediately critical to the page experience.
Which attribute requests lazy loading?