PrepPilotPractise free

HTML & CSS interview questions

Semantics, box model, layout, responsive design

17 questions · <div> · updated November 2026

Practise these as flashcards. One or two lines each; the ones you miss come back first.

Start free

Core questions

What is semantic HTML and why is it important?

Semantic HTML uses elements that describe their meaning in the context of the page, like <header>, <main>, or <footer>. It's important because it improves accessibility, SEO, and code clarity.

Describe the CSS box model.

The box model consists of content, padding, border, and margin. The total size of an element is the sum of these parts, which affects layout and spacing.

How do you make a layout responsive?

I use flexible units like percentages or rem, CSS media queries to adjust styles for different screen sizes, and a mobile-first approach to ensure layouts work well on all devices.

What does the display: flex property do?

display: flex turns an element into a flex container, enabling its children to be laid out using the flexbox model, which makes alignment and spacing much easier.

Intermediate questions

Explain the difference between position: absolute and position: relative.

position: absolute removes the element from the normal flow and positions it relative to the nearest positioned ancestor. position: relative keeps the element in the flow but allows you to offset it from its normal position.

How does CSS specificity work?

Specificity is calculated based on the types of selectors used: inline styles, IDs, classes, and element selectors. Higher specificity rules override lower ones, and if specificity is equal, the last rule in the source order wins.

When would you use CSS Grid over Flexbox?

I use CSS Grid for two-dimensional layouts where I need to control both rows and columns, like dashboards. Flexbox is better for one-dimensional layouts, such as navigation bars.

How do you use CSS custom properties?

I define variables with --var-name syntax, usually in the :root selector for global scope, and use them with var(--var-name). This helps with theming and keeping styles consistent.

What is the cascade in CSS?

The cascade is the process by which browsers determine which CSS rules apply to an element, resolving conflicts based on specificity, importance, and source order.

How do you implement native form validation in HTML?

I use input types like email or number, and attributes like required, min, max, or pattern. Browsers then handle validation and show error messages automatically.

What is mobile-first design and why is it recommended?

Mobile-first design means writing styles for small screens first, then using media queries to add enhancements for larger screens. It's recommended because it ensures a good experience on the most constrained devices.

How do you prevent layout shifts when loading images?

I set explicit width and height attributes on images or use aspect-ratio in CSS, so the browser can allocate space before the image loads, preventing layout shifts.

Senior questions

How would you debug a layout issue where a container overflows its parent?

See the answer in the app, free

Describe a scenario where specificity caused a bug and how you resolved it.

See the answer in the app, free

How do you ensure accessibility when building forms?

See the answer in the app, free

How would you approach building a complex, responsive dashboard layout?

See the answer in the app, free

What are the trade-offs between using CSS custom properties and preprocessor variables (like Sass)?

See the answer in the app, free

More Frontend topics