Interview
June 3, 2026 5 min read

HTML and CSS Interview Questions

HS
HEMANT SINGH
Technical Writer & Educator

List of popular asked questions with answers

  1. Explain the purpose of HTML and CSS.
  2. What is the key difference between <div> and <span> elements in HTML?
  3. How do you link an external CSS file to an HTML document?
  4. Explain the difference between inline and block-level elements in HTML.
  5. What is the CSS "box model"?
  6. How can you center an element horizontally and vertically using CSS?
  7. Explain the concept of CSS specificity.
  8. What is the purpose of the CSS z-index property?
  9. How can you create a responsive web design using CSS?
  10. Explain the difference between padding and margin in CSS.

1. Explain the purpose of HTML and CSS.

HTML serves as the foundation for structuring web content, while CSS is responsible for styling and layout presentation.

 

2. What is the key difference between <div> and <span> elements in HTML?

<div> is a block-level element, typically used for grouping and layout, while <span> is an inline element used for styling specific portions of text.

 

3. How do you link an external CSS file to an HTML document?

To link an external CSS file, use the <link> element in the <head> section of the HTML document with the rel attribute set to "stylesheet" and the href attribute specifying the CSS file's path.

 

4. Explain the difference between inline and block-level elements in HTML.

Inline elements flow within the content, while block-level elements create distinct, visible blocks. Block-level elements typically start on a new line and stretch to the full width of their parent container.

 

5. What is the CSS "box model"?

The CSS box model describes how elements are rendered as rectangular boxes, comprising content, padding, border, and margin.

 

6. How can you center an element horizontally and vertically using CSS?

To center an element horizontally, use margin: 0 auto; for the element's left and right margins. To center it vertically within its parent, use techniques like display: flex; or position: absolute

 

7. Explain the concept of CSS specificity.

CSS specificity determines which style rules take precedence when multiple rules apply to the same element. Specificity is calculated based on selectors, with higher specificity overriding lower specificity.

 

8. What is the purpose of the CSS z-index property?

The z-index property controls the stacking order of positioned elements. It specifies which elements appear on top when they overlap in a web page's layout.

 

9. How can you create a responsive web design using CSS?

To create a responsive design, use media queries to adjust styles based on the device's screen size. Employ flexible layouts, relative units (like percentages), and fluid images to adapt content to various screen sizes.

 

10. Explain the difference between padding and margin in CSS.

Padding is the space between an element's content and its border, affecting the inner area of the element. Margin, on the other hand, is the space outside the element's border, influencing its positioning and spacing relative to other elements.