HTML & CSS Interview Questions and Answers
Frontend interviews still start with HTML and CSS even when the job is mostly React. Interviewers want to know that you can mark up a page accessibly, lay it out without fighting the cascade, and explain how the browser turns HTML and CSS into pixels.
Usually asked in frontend and full stack interviews, from intern / fresher to senior (5+ years).
Intern / Fresher
- Q1Intern / FresherWhat are semantic HTML elements and why do they matter?
Semantic elements describe their meaning in the name, such as header, nav, main, article and footer, so browsers, assistive technology and search engines can understand the page structure.
- Q2Intern / FresherWhat is the CSS box model?
Every element is a box made of content, padding, border and margin. The default content-box size counts only the content; border-box includes padding and border in the width you set.
- Q3Intern / FresherWhat is the difference between display none and visibility hidden in CSS?
display: none removes the element from the layout so it takes no space; visibility: hidden hides it but leaves the empty space, and the element can still be read in the accessibility tree in some cases.
- Q4Intern / FresherWhat is the difference between inline, block and inline-block in CSS?
Block elements start on a new line and take the full available width; inline elements sit in the text flow and ignore width and height; inline-block sits in the flow but accepts width, height, padding and margin on all sides.
Junior (0-2 years)
- Q1Junior (0-2 years)What is the difference between relative, absolute, fixed and sticky positioning in CSS?
Relative offsets an element from its normal place; absolute positions it against the nearest positioned ancestor; fixed is against the viewport; sticky sits in normal flow until a scroll threshold, then sticks.
- Q2Junior (0-2 years)What is the difference between Flexbox and CSS Grid?
Flexbox is one-dimensional (a row or a column). CSS Grid is two-dimensional (rows and columns at once). Use Flexbox for alignment along a line; use Grid when the layout is a real 2D structure.
- Q3Junior (0-2 years)How does CSS specificity work?
Specificity is the score the browser uses to decide which rule wins: inline styles beat IDs, IDs beat classes/attributes/pseudo-classes, and those beat elements. When scores tie, the last rule in the source wins.
- Q4Junior (0-2 years)What is the difference between em, rem, %, vh and vw in CSS?
em is relative to the parent font size, rem is relative to the root font size, % is relative to the parent’s relevant size, and vh/vw are 1% of the viewport height or width.
- Q5Junior (0-2 years)What is the difference between cookies, localStorage and sessionStorage?
Cookies are sent to the server with every matching request and can expire; localStorage persists until cleared and stays in the browser; sessionStorage lasts for the current tab only.
Mid-level (2-5 years)
- Q1Mid-level (2-5 years)What is the difference between async and defer on script tags?
Both download the script without blocking HTML parsing. defer waits until parsing finishes and runs scripts in document order; async runs a script as soon as it is downloaded, which can be before or after parsing and in any order.
- Q2Mid-level (2-5 years)How does the browser render a web page?
The browser parses HTML into a DOM and CSS into a CSSOM, combines them into a render tree, computes layout (reflow), paints pixels and composites layers onto the screen.
Senior (5+ years)
- Q1Senior (5+ years)What are Core Web Vitals and how do you improve them?
Core Web Vitals are Google’s field metrics for real-user experience: LCP (loading), INP (interactivity) and CLS (visual stability). They influence search ranking and are measured on real devices, not only Lighthouse.