HTML and CSS Interview Questions with Answers
HTML Questions
Q: What is HTML?
Ans: HTML (HyperText Markup Language) is the standard language used to create web pages.
Q: What are HTML tags?
Ans: Tags are keywords enclosed in angle brackets like <p>, <h1>, <div>, etc.
Q: Difference between HTML and HTML5
Ans: HTML5 supports audio, video, and canvas without plugins. It introduces new semantic tags
like <header>, <footer>, <section>.
Q: Purpose of head tag
Ans: Contains metadata, title, CSS/JS links.
Q: Doctype declaration
Ans: Tells the browser which HTML version is used. Example: <!DOCTYPE html> for HTML5.
Q: Difference between div and span
Ans: <div> is block-level, <span> is inline-level.
Q: Semantic tags
Ans: Describe meaning — <header>, <footer>, <article>, <nav>.
Q: Meta tag
Ans: Defines metadata like encoding, description, or author.
Q: Hyperlink example
Ans: <a href='[Link]
Q: Image tag
Ans: <img src='[Link]' alt='Description'>
CSS Questions
Q: What is CSS?
Ans: Used to style HTML (color, font, layout).
Q: Types of CSS
Ans: Inline, Internal, External.
Q: Syntax
Ans: selector { property: value; }
Q: Class vs ID
Ans: Class uses '.', multiple times; ID uses '#', unique.
Q: Pseudo-classes
Ans: Special states like a:hover.
Q: Z-index
Ans: Controls stacking order of elements.
Q: Box Model
Ans: Content → Padding → Border → Margin.
Q: Flexbox & Grid
Ans: Flexbox is 1D layout, Grid is 2D layout.
Q: Visibility:hidden vs Display:none
Ans: display:none removes element; visibility:hidden hides but keeps space.
Q: Media Queries
Ans: Used for responsive design: @media(max-width:600px){...}