HTML & CSS Interview

HTML Fundamentals, Structure, Semantics, Links, Images, Tables & Forms

HTML interview questions covering document structure, semantic HTML, headings, links, images, tables, forms and core markup fundamentals.

25 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

25 Results
1
JuniorBeginner

What is HTML and what is its role in a web page?

HTML stands for HyperText Markup Language. It defines the structure and meaning of content on a web page. Browsers parse HTML elements to build the document structure that users see and assistive technologies can interpret.

2
JuniorBeginner

What is HTML5?

HTML5 is the modern evolution of HTML used for structuring web documents and applications. The term is commonly associated with semantic elements, improved forms, native audio and video, canvas, and APIs introduced during the development of modern HTML.

3
JuniorBeginner

What does the <!DOCTYPE html> declaration do?

The DOCTYPE tells the browser which document type and rendering mode should be used. The HTML5 declaration is simply <!DOCTYPE html>.

4
JuniorBeginner

What is the basic structure of an HTML document?

A basic HTML document contains a DOCTYPE followed by the html root element. The head contains document metadata and linked resources, while the body contains the page content presented to the user.

5
JuniorBeginner

What is the difference between the <head> and <body> elements?

The head contains metadata and resources that describe or support the document, such as the title, character encoding, viewport configuration, stylesheet links, and selected metadata for search engines.

6
JuniorBeginner

What are HTML elements, tags, and attributes?

An HTML element is a component of the document, usually represented by a start tag, content, and an end tag. A tag is the markup syntax used to declare an element, such as <p> or </p>.

7
JuniorBeginner

What is the difference between block-level and inline elements?

Historically, block-level elements normally start on a new line and occupy the available horizontal space, while inline elements participate within a line of text. Common examples are div and p for block-level behavior, and span and a for inline behavior.

8
JuniorBeginner

What are void elements in HTML?

Void elements cannot contain child content and do not have an end tag in HTML syntax. Examples include img, input, br, hr, meta, link, source, and area.

9
JuniorBeginner

What is semantic HTML?

Semantic HTML uses elements whose names communicate the meaning and role of their content. Examples include header, nav, main, article, section, aside, footer, button, and form.

10
JuniorBeginner

Why is semantic HTML important for accessibility and SEO?

Semantic elements provide structural meaning that browsers and assistive technologies can expose to users. Proper headings, landmarks, lists, buttons, links, labels, and other native elements make interfaces easier to navigate and understand.

11
JuniorBeginner

What is the difference between <div> and <span>?

div and span are generic elements with no specific semantic meaning. A div is commonly used as a generic block container, while span is commonly used to wrap a small inline portion of content.

12
JuniorBeginner

What are the HTML heading elements and how should they be used?

HTML provides h1 through h6 heading elements. They represent headings at different levels in the document hierarchy, with h1 representing the highest level and h6 the lowest.

13
JuniorBeginner

What is the difference between <strong> and <b>, and between <em> and <i>?

strong indicates strong importance, seriousness, or urgency, while b draws attention without adding that importance. Similarly, em represents stress emphasis, while i represents text in an alternate voice or convention where italics are typically appropriate.

14
JuniorBeginner

What are HTML lists and when would you use them?

HTML provides unordered lists with ul, ordered lists with ol, and description lists with dl. li represents an item in an ordered or unordered list, while dt and dd represent terms and descriptions in a description list.

15
JuniorBeginner

How do hyperlinks work in HTML?

The anchor element creates a hyperlink, and its href attribute specifies the destination. The destination can be another page, a fragment within a page, an email or telephone URI, or another valid URL.

16
JuniorBeginner

What is the purpose of the target and rel attributes on links?

target controls where a linked resource is opened. For example, target="_blank" requests a new browsing context, commonly a new tab.

17
JuniorBeginner

How do you display images correctly in HTML?

Use the img element with a src attribute for the image resource and an alt attribute for text alternatives. Meaningful images should have useful alternative text that communicates the relevant purpose or content.

18
JuniorBeginner

What is the purpose of the alt attribute on an image?

The alt attribute provides a text alternative when an image cannot be perceived or loaded and is essential for many screen-reader users. The correct text depends on the image's purpose and surrounding context.

19
JuniorBeginner

What are figure and figcaption used for?

figure represents self-contained content that is referenced as a unit, such as an illustration, diagram, code listing, photograph, or chart. figcaption provides a caption or legend for that figure.

20
JuniorBeginner

What are the main elements used to create an HTML table?

A table uses table as the container, tr for rows, th for header cells, and td for data cells. thead, tbody, and tfoot can group logical table sections, while caption provides an accessible table title or description.

21
JuniorBeginner

What are colspan and rowspan in HTML tables?

colspan allows a table cell to span multiple columns, while rowspan allows it to span multiple rows. They are useful for representing legitimate grouped relationships in complex tabular data.

22
JuniorBeginner

What is an HTML form?

An HTML form groups controls used to collect and submit user input. The form element can specify where data is submitted with action and which HTTP method is used with method.

23
JuniorBeginner

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

With method="get", successful form controls are encoded into the request URL query string. GET is appropriate for safe, repeatable operations such as search and filtering, and the resulting URL can often be bookmarked or shared.

24
JuniorBeginner

Why is the <label> element important in forms?

A label gives an input control an accessible name and makes the form easier to understand and operate. When a label is correctly associated with a control, selecting the label can also focus or activate that control.

25
JuniorBeginner

What are common HTML input types and why should you use the correct type?

Common input types include text, email, password, number, tel, url, date, checkbox, radio, file, hidden, search, range, and color. The selected type communicates the intended kind of data to the browser.