CSS interview questions
8 questions, easy to hard. Read one, then answer it out loud: an AI interviewer follows up, hints when you're stuck and grades your answer.
CSS interviews test whether you can lay out real interfaces: the box model, specificity, flexbox and grid, positioning and responsive design.
CSS and Layout
- The Box Model
- easy
A card is set to be three hundred pixels wide, but with padding and a border it takes up more than that and breaks the layout. Explain the CSS box model, why this happens, and how you'd fix it.
What a strong answer covers
- The layers that make up every box, from the content outwards.
- What a declared width actually measures by default, and why extra space appears.
- The setting that changes how width is counted, and where teams usually apply it.
- How the outermost spacing behaves between neighbouring blocks.
Common mistake: Shrinking the width by hand to compensate for padding, which breaks again the next time the padding changes.
- Specificity and the Cascade
- easy
- Pro
You add a class to make a button red, but it stays blue, and a colleague suggests adding important. Explain how the browser decides which CSS rule wins, and a better fix.
What a strong answer covers
- How the browser ranks competing selectors.
- What decides the winner when two rules rank equally.
- Why forcing a rule to win tends to escalate over time.
- How to track down the rule that's actually winning and correct it at the source.
Common mistake: Reaching for the strongest override first, so the next person has to override the override.
- Flexbox or Grid
- easy
- Pro
You need to build a navigation bar with a logo on the left and links on the right, and a photo gallery with rows of equal-sized tiles. Explain the difference between flexbox and grid, and which you'd use for each.
What a strong answer covers
- How the two layout systems differ in the number of directions they control.
- Where the sizing decisions come from in each: the items or the container.
- A sensible choice for the navigation bar and how to push items apart.
- A sensible choice for the gallery and how it can adapt to the screen width.
Common mistake: Treating one system as strictly better and forcing every layout into it.
- Centre Anything
- medium
- Pro
A designer asks you to centre a loading spinner in the middle of a full-height panel, centre a line of text, and centre a fixed-width page column. Explain the techniques you'd use for each and why centring has a reputation for being hard.
What a strong answer covers
- A modern way to centre something in both directions inside a container.
- Centring a run of text versus centring a whole block.
- What a block needs before automatic margins can centre it.
- Why vertical centring fails without a defined height, and the older technique people used.
Common mistake: Expecting vertical centring to work when the parent is only as tall as its content.
- Responsive Layouts
- medium
- Pro
A desktop-only site needs to work on phones. Explain how you'd make the layout responsive, including the viewport setting, breakpoints and units.
What a strong answer covers
- The setting that stops phones from shrinking a desktop page.
- Which screen size to design for first and how larger screens build on it.
- Flexible sizing in place of fixed widths.
- Details beyond layout, such as images, touch targets and components that respond to their own space.
Common mistake: Writing separate overrides for a list of specific devices instead of letting the layout flex between breakpoints.
- Position and Stacking
- medium
- Pro
A dropdown menu is hidden behind the next section, even with a z-index of nine thousand nine hundred and ninety-nine. A sticky header also stops sticking. Explain how CSS positioning and stacking contexts work and how you'd fix both.
What a strong answer covers
- The positioning modes and what each one is positioned against.
- Why a huge z-index can still lose, and which properties start a new stacking context.
- Ways to free the dropdown, either by fixing the ancestor or rendering it elsewhere.
- What sticky positioning needs to work and what quietly breaks it.
Common mistake: Raising the z-index further, when the real limit is the stacking context of an ancestor.
- Relative Units
- medium
- Pro
A user who sets a larger default font size in their browser finds your site's text doesn't grow. Explain the differences between pixels, rems, ems and viewport units, and which you'd use for text, spacing and layout.
What a strong answer covers
- What each unit is measured against.
- Why one unit compounds when elements are nested.
- The zoom and readability risk of sizing text by the window alone.
- A reasoned choice of unit for text, spacing and fine details.
Common mistake: Setting all text in pixels, which ignores the font size the user chose in their browser.
- Organise CSS at Scale
- hard
- Pro
A large app has one global stylesheet with thousands of rules. Changing a style for one page breaks others, and nobody dares delete anything. Explain how you'd organise the CSS so it scales with the team.
What a strong answer covers
- Why global styles make the reach of a change unpredictable.
- Ways to scope styles so a rule only touches its own component.
- Sharing colours, spacing and type through named values.
- Tools for controlling precedence and safely removing styles nobody uses.
Common mistake: Adding more specific selectors to win each conflict, which makes the stylesheet harder to change.
Questions about practising
- How should I prepare for css interview questions?
- Practise answering them out loud, not just reading them. Explaining an answer under follow-up questions is what interviews test. Work through the 8 questions here from easy to hard, and revisit the ones you struggle with.
- Can I practise css interview questions with an AI?
- Yes. Open any question and start a voice session: an AI interviewer asks it, follows up on your answer, gives hints when you're stuck and grades your answer with written feedback when the call ends.
- Are these css interview questions free?
- 1 of the 8 questions are free to practise. Sign in with Google, no card needed. Pro unlocks the rest, plus practice calls to your phone.