All categories

Category

CSS

Layout, specificity, animations, modern Grid/Flex.

30 questions

30 of 30
CSS
Easy
Can you walk through the CSS box model from content to margin?

Every element is a box: content → padding → border → margin, from inside out. `box-sizing: content-box` (default) makes width/height apply to content only, so padding+border add to the rendered size. `box-sizing: border-box` makes width/height include padding+border — far more predictable, which is why most resets set it globally. Margins also collapse vertically.

4 min
CSS
Easy
What is the difference between rem, em, and px in CSS?

px is an absolute, fixed unit. em is relative to the current element's font-size and compounds when nested. rem is relative to the root (html) font-size — consistent, no compounding. Use rem for scalable, accessible sizing; em for things that should scale with their local context.

4 min
CSS
Easy
What are pseudo classes and pseudo elements in CSS?

Pseudo-classes (:hover, :focus, :nth-child) style elements in a particular STATE or position — single colon. Pseudo-elements (::before, ::after, ::first-line) style or create a specific PART of an element — double colon. One targets state, the other targets sub-parts.

4 min
CSS
Easy
What is the difference between display none and visibility hidden in CSS?

display:none removes the element entirely — no box, no space taken, not in layout, not announced to screen readers, can't be focused. visibility:hidden hides it visually but it STILL occupies its space in layout and affects siblings. opacity:0 is a third option (visible to a11y/events). Toggling display triggers reflow.

4 min
CSS
Easy
What are the CSS position values and when would you use each?

static = default flow. relative = in flow but offsettable + new positioning context. absolute = removed from flow, anchored to nearest positioned ancestor. fixed = anchored to viewport (or transformed ancestor). sticky = relative until a threshold, then fixed within scroll container.

6 min
CSS
Medium
When would you reach for absolute, fixed, or sticky positioning in a real layout?

static: default, in normal flow, ignores top/left. relative: in flow but offset from its own position, becomes a positioning context. absolute: removed from flow, positioned against the nearest positioned ancestor. fixed: removed from flow, positioned against the viewport. sticky: hybrid — in flow until it hits a scroll threshold, then sticks.

5 min
CSS
Easy
What are CSS custom properties and how would you use them in production?

CSS custom properties (`--name: value`) are real CSS variables — they cascade, inherit, can be scoped to any selector, read with `var(--name, fallback)`, and changed at runtime via JS or media queries. Unlike Sass variables (compile-time, static), they're live in the browser, which makes them ideal for theming, dark mode, and component APIs.

5 min
CSS
Medium
How do you center a div both horizontally and vertically in modern CSS?

The modern answer is Flexbox (display:flex; justify-content:center; align-items:center) or Grid (display:grid; place-items:center) on the parent. Older/edge approaches: absolute + transform translate(-50%,-50%), or margin:auto inside a flex/grid container. Know which works without knowing the element's size.

3 min
CSS
Medium
How do you assign different widths to items inside a flex container?

Control flex item width with the `flex` shorthand: `flex-grow` (share of extra space), `flex-shrink` (share of overflow reduction), `flex-basis` (starting size). `flex: 1` makes items share space equally; different grow values or explicit `flex-basis`/`width` give different widths. `flex: 0 0 200px` fixes a width; `flex: 2` vs `flex: 1` makes a 2:1 ratio.

5 min
CSS
Easy
How would you place five divs in a row without using flex, margin, or padding?

Set the divs to `display: inline-block` (or `display: inline`) — they then flow horizontally like text instead of stacking as block elements. The hint's catch: inline-block elements get whitespace gaps from newlines in the HTML; remove them by setting `font-size: 0` on the parent, putting the divs on one line, or using HTML comments between them.

4 min
CSS
Easy
hot
When should you use Flexbox versus CSS Grid?

Flexbox is one-dimensional (a row OR a column). Grid is two-dimensional (rows AND columns at once). Use flex for component layouts and toolbars, grid for page templates, dashboards, and any 2D alignment.

5 min
CSS
Easy
Where do Flexbox and CSS Grid actually shine in real product UIs?

Flexbox is one-dimensional (lay out items along a single row OR column); Grid is two-dimensional (rows AND columns together). Flexbox is content-driven and great for components (toolbars, nav, centering); Grid is layout-driven and great for page-level structure. They compose — Grid for the macro layout, Flexbox inside the cells.

5 min
CSS
Medium
Would you use Flexbox or CSS Grid for an e commerce product layout with three columns?

CSS Grid. Product grids are inherently 2D (rows AND columns of equal-sized cards), and Grid handles that natively with one rule: 'grid-template-columns: repeat(auto-fill, minmax(240px, 1fr))'. It gives equal column widths, fluid responsiveness without media queries, and aligned rows automatically. Flexbox is 1D — to fake a grid you fight wrap behavior, leftover-item alignment, and equal heights. Use Flexbox inside each card; Grid for the layout.

5 min
CSS
Hard
How would you design a responsive grid layout using CSS Grid and Flexbox?

Use CSS Grid for the responsive grid: `grid-template-columns: repeat(auto-fill, minmax(min, 1fr))` adapts column count to viewport with zero media queries; add `gap` for spacing. Use Flexbox inside each cell for its internal layout. Layer in `clamp()` for fluid sizing and a few media queries only for major layout changes.

6 min
CSS
Medium
Why does the viewport meta tag matter for mobile UI rendering?

Without the viewport meta tag, mobile browsers render at a ~980px virtual width and scale down — text becomes tiny, taps misalign, and media queries never trigger because the layout viewport ≠ visual viewport. The standard tag `<meta name="viewport" content="width=device-width, initial-scale=1">` ties layout width to device-independent pixels so responsive CSS works as designed.

3 min
CSS
Medium
How do you make a web app responsive using media queries and relative units?

Fluid layouts (flex/grid + %), relative units (`rem`/`em`/`ch`/`vw`/`vh`), breakpoints via `@media (min-width)` (mobile-first), `clamp()` for fluid type, container queries for component-local responsiveness, `<picture>`/srcset for images, and a viewport meta tag. Layer with logical properties (`margin-inline`) for i18n/RTL.

4 min
CSS
Easy
How do CSS methodologies like BEM work alongside responsive media queries?

CSS methodologies (BEM, SMACSS, OOCSS, ITCSS) impose naming and structure conventions to keep CSS scalable and avoid specificity wars. BEM (Block__Element--Modifier) keeps selectors flat and components self-contained. Responsive design uses media queries (mobile-first: base styles + `min-width` breakpoints) plus fluid units and modern intrinsic layout (clamp, auto-fill grid).

6 min
CSS
Easy
How do you build a fully responsive web application?

Beyond layout: responsive means adapting layout, content, interactions, media, and performance to the device. Mobile-first fluid layouts, container queries for components, responsive images, touch vs pointer handling, and shipping less to constrained devices.

6 min
CSS
Hard
How would you create a responsive design from scratch?

Build mobile-first with fluid layouts (flex/grid), relative units, and a small set of meaningful breakpoints driven by content — not devices. Add the viewport meta tag, use responsive images, and test on real constraints.

6 min
CSS
Medium
Why might you choose Tailwind CSS over Bootstrap or traditional CSS?

Tailwind is utility-first (compose from atomic classes); Bootstrap is component-first (pre-built components). Tailwind gives a tiny purged bundle, design consistency via a config-driven token system, no naming or context-switching, and full design freedom. Bootstrap is faster for generic UIs but produces sites that look the same and harder to customize. Traditional CSS scales poorly without conventions.

5 min
CSS
Medium
How would you manage styles in a large scale application using CSS in JS, CSS variables, or other approaches?

At scale the real problems are global scope, specificity wars, dead code, and theming. Pick a scoping strategy — CSS Modules, CSS-in-JS (runtime or zero-runtime), or utility-first (Tailwind) — layered with design tokens as CSS custom properties for theming. There's no single right answer; the senior move is matching the choice to team size, SSR needs, and performance budget.

6 min
CSS
Easy
What is your approach to achieving cross browser consistency in production CSS?

Start from a baseline: a CSS reset/normalize, then build with well-supported standards and check caniuse. Use feature detection (`@supports`) over browser sniffing, progressive enhancement, autoprefixer for vendor prefixes, fluid/intrinsic layouts that tolerate variation, and a real cross-browser test matrix (BrowserStack + the main engines). Accept pixel-perfect-everywhere is the wrong goal — robust and acceptable is.

6 min
CSS
Medium
How do you troubleshoot intermittent UI glitches across different browsers?

Make it reproducible first — gather environment data, use RUM and session replay, test across real browsers. Intermittent + cross-browser usually means a race condition, a browser-engine difference, or a third-party script/extension. Isolate by binary search, instrument the suspect, fix the root cause, add a regression test.

6 min