01
CSS fundamentals
3 questionsQ01
How does the box model affect sizing?
The content box is surrounded by padding, border, and margin. With content-box, a declared width excludes padding and border; border-box includes them. Margin remains outside either width. In layout debugging, inspect computed dimensions rather than guessing from the width declaration.
*, *::before, *::after { box-sizing: border-box; }
.card { width: 100%; padding: 1rem; border: 1px solid; }
Common mistake
A 100%-wide content-box element with padding can overflow its parent.
Go one level deeper ↗
Why can adjacent vertical margins collapse?
Q02
How do cascade and specificity differ?
The cascade resolves competing declarations through origin and importance, layer order, selector specificity, scoping proximity where applicable, and source order. Specificity compares selector weights within the winning cascade context. A later selector does not automatically beat an earlier more specific selector.
/* Same origin, layer, and importance: the class wins. */
.notice { color: blue; }
p { color: red; }
Common mistake
Adding IDs or !important everywhere makes overrides fragile and hides the real cascade conflict.
Go one level deeper ↗
Can a less specific rule in a different cascade layer win?
Q03
Which properties inherit?
Some properties, such as color and font-family, normally inherit; others, such as margin and border, normally do not. inherit explicitly takes the parent’s computed value, initial uses the property default, and unset chooses inheritance or the default depending on the property. Custom properties normally inherit too.
button, input, select, textarea { font: inherit; }
Common mistake
Expecting a child to inherit a parent’s width or margin gives surprising layout results.
Go one level deeper ↗
How do you make a form control use the surrounding font?
02
Layout
4 questionsQ04
When would you choose Flexbox over Grid?
Use Flexbox to arrange a navigation bar or controls along one main axis, with items distributing available space. Use Grid when rows and columns should align across a dashboard or card layout. Wrapped flex lines size independently; grid tracks align items across rows. Both can be nested.
.toolbar { display: flex; gap: .75rem; flex-wrap: wrap; }
.cards { display: grid; gap: 1rem;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr));
}
Common mistake
Using Flexbox for a two-dimensional layout often requires brittle widths and spacer elements.
Go one level deeper ↗
How would the choice change for variable-width toolbar buttons?
Q05
How do alignment axes work?
In Flexbox, justify-content works on the main axis and align-items on the cross axis, so changing flex-direction changes their physical direction. In Grid, justify-items aligns items within their inline-axis grid areas; align-items aligns them in the block axis. Content alignment distributes tracks or flex lines when there is free space.
.center { display: flex; align-items: center;
justify-content: center; min-height: 12rem; }
Common mistake
Using align-content on a single flex line will not center each item.
Go one level deeper ↗
What changes when flex-direction becomes column?
Q06
Why does a flex or grid child overflow?
A child’s automatic minimum size can preserve its content width instead of allowing it to shrink. Try min-width: 0 on the shrinkable child and minmax(0, 1fr) for flexible grid tracks. Then decide whether content should wrap, clip, or scroll; those are different product behaviors.
.row { display: flex; }
.row > .content { min-width: 0; overflow-wrap: anywhere; }
.grid { display: grid; grid-template-columns: 12rem minmax(0, 1fr); }
Common mistake
Adding overflow: hidden to the whole page hides the symptom and may clip usable controls.
Go one level deeper ↗
How would you handle a long unbroken URL inside a card?
Q07
How do you build a responsive layout without many breakpoints?
Start with intrinsic sizing: flexible tracks, wrapping, max-width, and content-driven minimums. Add breakpoints when the layout actually stops serving the content. Check narrow viewports, long text, and zoom; a device-name breakpoint does not prove the layout is usable.
.page { width: min(100% - 2rem, 70rem); margin-inline: auto; }
Common mistake
Fixed widths that only fit your laptop can produce horizontal scrolling on a phone.
Go one level deeper ↗
How would you test a translated label that is twice as long?
03
Positioning
3 questionsQ08
How do relative and absolute positioning differ?
Relative positioning keeps the element’s original space in normal flow while offsetting its visible position. Absolute positioning removes it from normal flow and uses its containing block for offsets. A positioned ancestor commonly establishes that block, but transforms and other properties can also do so.
.card { position: relative; }
.badge { position: absolute; inset-block-start: .5rem;
inset-inline-end: .5rem; }
Common mistake
An absolute badge can anchor to an unexpected ancestor when the intended card does not establish a containing block.
Go one level deeper ↗
Why does the parent not automatically grow around an absolute child?
Q09
How do fixed and sticky positioning differ?
Fixed elements are out of normal flow and usually positioned relative to the viewport, though a transformed ancestor can establish their containing block. Sticky elements retain normal-flow space, then stick within their scrolling context and containing-block limits after reaching an inset such as top: 0.
.scroll-area { max-height: 30rem; overflow: auto; }
.heading { position: sticky; top: 0; background: white; }
Common mistake
Sticky with no relevant inset, no room to move, or an unexpected overflow ancestor may appear ineffective.
Go one level deeper ↗
Why might sticky stop before reaching the bottom of the page?
Q10
How do containing blocks change overlay positioning?
Containing blocks determine percentage sizes and offset references for positioned boxes. position: relative often anchors an absolute child; transform on an ancestor can also anchor fixed descendants. Inspect the ancestor chain when a supposedly viewport-fixed overlay follows a card.
Common mistake
Moving an overlay into a transformed animation wrapper can change where it is positioned.
Go one level deeper ↗
Would a portal or the browser top layer solve the clipping and positioning requirements?
04
Layering
1 questionsQ11
Why can a huge z-index still leave a dropdown behind?
z-index is compared within a stacking context. A child cannot escape its ancestor’s context to outrank a sibling context above that ancestor. Positioned elements with non-auto z-index, transforms, and opacity below 1 are common creators. Change the context hierarchy or place the overlay in an appropriate portal/top layer; a portal still needs suitable CSS.
.panel { position: relative; z-index: 1; }
.panel .dropdown { position: absolute; z-index: 9999; }
.sidebar { position: relative; z-index: 2; }
/* The dropdown stays within .panel’s lower context. */
Common mistake
Increasing a dropdown from z-index: 100 to 999999 does not move its parent context above a sibling.
Go one level deeper ↗
How does clipping by overflow differ from stacking order?
05
Responsive UI
3 questionsQ12
When should you use a media query?
Media queries respond to viewport or environment conditions, including width, reduced-motion preferences, and pointer capabilities. Choose layout changes around content needs. Use CSS for presentation changes rather than duplicating viewport state in JavaScript when no behavioral change is needed.
@media (max-width: 48rem) {
.layout { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
.card { animation: none; }
}
Common mistake
Assuming every narrow screen has a touch pointer confuses size with input capability.
Go one level deeper ↗
How would you respect a user’s reduced-motion setting?
Q13
When are container queries useful?
Container queries let a reusable component respond to the size of a containing element rather than the whole viewport. Establish a query container, then adapt its descendants. A card in a narrow sidebar may need the compact layout even on a wide desktop screen.
.card-shell { container-type: inline-size; }
@container (min-width: 30rem) {
.card-body { display: grid; grid-template-columns: 1fr 2fr; }
}
Common mistake
Testing viewport width alone can make the same component fail in a sidebar.
Go one level deeper ↗
Why should the query container usually be a wrapper rather than the element it restyles?
Q14
How do rem, percentages, and clamp help flexible sizing?
rem scales with the root font size, percentages depend on the relevant containing dimension, and clamp sets a minimum, preferred, and maximum. Use flexible sizing while preserving text zoom and content growth. A viewport-only font size can shrink text too much on small screens.
.title { font-size: clamp(1.5rem, 1rem + 2vw, 2.5rem); }
.card { min-height: 10rem; padding: 1rem; }
Common mistake
Fixed heights around text can clip content at larger font settings.
Go one level deeper ↗
How would you bound a fluid heading without making it tiny on mobile?
06
Practical implementation
4 questionsQ15
How do you truncate one line of text?
Single-line ellipsis needs a constrained inline size, non-wrapping text, and hidden overflow. In a flex child, also allow shrinking with min-width: 0. Truncation loses visible information, so provide a usable way to reach the full title when it matters; a hover-only tooltip is insufficient for touch and keyboard users.
.title { min-width: 0; overflow: hidden;
white-space: nowrap; text-overflow: ellipsis; }
Common mistake
text-overflow alone does nothing when the text can keep expanding the box.
Go one level deeper ↗
How would you handle a full accessible name while truncating the visible label?
Q16
What is a reliable way to center content?
For a single item in both axes, Grid with place-items: center is concise. For a group along an axis, Flexbox often fits better. margin-inline: auto centers a constrained block horizontally; it does not provide vertical centering. Ensure the parent has available space in the axis being centered.
.empty-state { display: grid; place-items: center;
min-height: 15rem; padding: 1rem; }
Common mistake
Absolute centering can overlap other content because the child leaves normal flow.
Go one level deeper ↗
How would you center a dialog but allow its content to scroll on a short screen?
Q17
How should images fit a responsive card?
Use max-width: 100% and height: auto to preserve the intrinsic ratio for ordinary images. For uniform thumbnails, set a box ratio and use object-fit: cover to crop or contain to preserve the full image. Reserve space with intrinsic dimensions or aspect-ratio to reduce layout shifts, and handle load failure.
.thumbnail { width: 100%; aspect-ratio: 4 / 3;
object-fit: cover; }
Common mistake
Stretching to independent fixed width and height distorts images.
Go one level deeper ↗
When is cropping unacceptable, such as for a product label?
Q18
How do you debug a broken layout?
Reproduce the smallest failing viewport, inspect computed styles and box dimensions, and use Grid/Flex overlays. Check the cascade, intrinsic minimums, containing blocks, and overflow ancestors in that order. Toggle the suspected declaration to confirm the cause before adding overrides.
Common mistake
Adding random negative margins fixes one screenshot while breaking other widths.
Go one level deeper ↗
What evidence would tell you the issue is intrinsic sizing rather than a breakpoint?
FROM READING TO DOINGBuild your preparation plan.
- 01
Understand the box model and cascade first.
- 02
Build a responsive layout with Flexbox and Grid, then debug overflow.
- 03
Add overlays, test stacking and focus, and verify text zoom and image behavior.
Junior candidates: explain sizing, alignment, positioning, and responsive behavior with a small example.
Experienced candidates: discuss component reuse, cascade strategy, overlay constraints, and accessibility under real content.
Keep the references close.
These are editorial practice questions, not a verified list of questions asked by a particular company.