CSS3 interview questions and answers on modern styling features
CSS3 interview questions focus on the features that arrived after CSS 2.1 as separate modules: richer selectors, rounded corners and shadows, gradients, web fonts, 2D and 3D transforms, transitions, keyframe animations and media queries. Interviewers check that you can write them from memory, explain how they behave (what can be animated, what fill-mode does, how nth-child counts) and use them responsibly, with fallbacks and respect for reduced-motion settings.
By Evin JohnPublished 8 min read
What interviewers mean by CSS3
Job posts and interview lists still say "HTML5 and CSS3", especially for front-end freshers, UI developers and full-stack roles with a template layer. In practice the question is whether you know the modern styling toolbox beyond colors and floats. This page covers the CSS3-era modules in depth. The cascade, specificity order, flexbox and grid detail, stacking contexts and CSS architecture are on the broader CSS interview questions page, and markup questions on HTML interview questions.
- Quick recallName the property for rounded corners, the shorthand order for box-shadow, how to load a custom font, what a vendor prefix is.
- Write it liveA card hover effect with a transition, a loading spinner with keyframes, a striped table with nth-child, a gradient button.
- Explain behaviorWhy a transition does not run, why an animation snaps back at the end, why a transform does not affect layout.
- JudgmentFallbacks for older browsers, motion and accessibility, and which properties are cheap to animate.
CSS3 fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is CSS3, and how does it differ from CSS2? | History | After CSS 2.1 the language was split into modules (selectors, backgrounds, transforms, media queries and so on), each advancing at its own pace and level. CSS3 is the informal name for that first wave of modules. |
| Is there a CSS4? | Versioning | Not as a single release. Some modules are at level 4 or 5 (selectors level 4, media queries level 5), but the language itself is no longer versioned as a whole. |
| Name ten features that came with CSS3. | Breadth | border-radius, box-shadow, text-shadow, multiple backgrounds, background-size, gradients, rgba and hsla colors, opacity, @font-face, transforms, transitions, animations, media queries, box-sizing, multi-column layout and flexbox. |
| What does box-sizing: border-box change? | Box model | Width and height include padding and border, so a 300px box with 20px padding stays 300px wide. Many resets apply it to every element. |
| What is the difference between ::before and :before? | Pseudo-elements | Double colons mark pseudo-elements (generated parts like ::before, ::first-line) and single colons pseudo-classes (states like :hover). Browsers accept the single-colon form for the old pseudo-elements for compatibility. |
| How do you round only the top corners of a card? | Borders | border-radius: 8px 8px 0 0, or the longhands border-top-left-radius and border-top-right-radius. A slash sets different horizontal and vertical radii. |
| What are the parts of box-shadow? | Shadows | Optional inset, horizontal offset, vertical offset, blur radius, spread radius and color. Several shadows can be listed with commas, painted first on top. |
| rgba() versus opacity? | Transparency | rgba makes one color transparent, so text inside stays solid. opacity fades the element and all its children and creates a new stacking context. |
| background-size: cover versus contain? | Backgrounds | cover scales the image to fill the box, cropping overflow. contain fits the whole image inside, possibly leaving empty space. |
| How do you load a custom font? | Fonts | An @font-face rule with a family name and src pointing to font files (WOFF2 first), then use the name in font-family. Add font-display to control what shows while it loads. |
| How do you truncate one line of text with an ellipsis? | Text | white-space: nowrap; overflow: hidden; text-overflow: ellipsis; on a block with a width. Multi-line clamping needs a different approach. |
CSS3 selector questions
- **What do
[href^="https"],[href$=".pdf"]and[class*="btn"]match?** Attributes that start with, end with and contain a value. Addibefore the closing bracket for case-insensitive matching where supported. - nth-child versus nth-of-type?
nth-childcounts all siblings, then checks the type;nth-of-typecounts only siblings of the same element type.p:nth-child(2)matches nothing if the second child is an h2. - How do you style every row except the first?
tr:not(:first-child), ortr + trwith the adjacent sibling combinator.:not()in CSS3 took one simple selector; newer browsers accept lists. - What is the general sibling combinator?
h2 ~ pmatches every p after an h2 with the same parent, not only the next one (h2 + p). - What do :checked, :disabled and :target do? Match checked inputs, disabled controls, and the element whose id matches the URL fragment. They make some interactions possible without JavaScript, such as a tab that opens from a link.
- What does :empty match? Elements with no children at all, including no text. A single space inside counts as content in CSS3, which surprises people.
function nth(a, b, count) {
const hits = [];
for (let i = 1; i <= count; i++) {
if (a === 0) { if (i === b) hits.push(i); continue; }
const n = (i - b) / a;
if (Number.isInteger(n) && n >= 0) hits.push(i);
}
return hits;
}
console.log(nth(2, 1, 10)); // 2n+1: [1, 3, 5, 7, 9] (same as odd)
console.log(nth(3, 0, 10)); // 3n: [3, 6, 9]
console.log(nth(-1, 3, 10)); // -n+3: [1, 2, 3] (the first three)
console.log(nth(1, 4, 10)); // n+4: [4, 5, 6, 7, 8, 9, 10]Transforms, transitions and animations
.toast {
opacity: 0;
transform: translateY(1rem);
transition: opacity 200ms ease-out, transform 200ms ease-out;
}
.toast.is-visible {
opacity: 1;
transform: translateY(0);
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.08); }
}
.badge--new {
animation: pulse 1.2s ease-in-out 3 both;
}
@media (prefers-reduced-motion: reduce) {
.toast, .badge--new {
transition: none;
animation: none;
}
}
@supports not (gap: 1rem) {
.chips > * + * { margin-left: 0.5rem; }
}| Question | What it tests | What a strong answer shows |
|---|---|---|
| Transition or animation? | Choosing | A transition runs between two states when a property changes, usually on hover or a class toggle. An animation runs keyframes on its own, can loop, and needs no state change to start. |
| Why does my transition not run? | Debugging | The property is not animatable (display), the start and end values are not both computed (height to auto), the transition sits only on the hover rule so it runs one way, or the class is added in the same frame the element is inserted. |
| What does animation-fill-mode do? | Animation end | forwards keeps the last keyframe after the animation ends, backwards applies the first keyframe during the delay, both does both. Without it the element snaps back to its normal style. |
What does the 3 and both mean in animation: pulse 1.2s ease-in-out 3 both? | Shorthand | Three iterations and fill-mode both. The first time value is duration, a second one would be the delay. |
| Does a transform move other elements? | Layout | No. Transforms are applied after layout, so neighbors stay where they were. That is also why they are cheap to animate. |
| What is transform-origin? | Transforms | The point a rotate or scale happens around, the center by default. A menu that grows from its top edge needs transform-origin: top. |
| Why does transform order matter? | Composition | Functions apply right to left in effect: translateX(100px) rotate(45deg) and rotate(45deg) translateX(100px) end in different places, because the second moves along the rotated axis. |
| What do perspective and backface-visibility do? | 3D | Perspective sets how strong the 3D depth looks for children. backface-visibility hidden hides an element when it is turned away, used for card flip effects. |
| What timing functions exist? | Easing | Keywords (ease, linear, ease-in, ease-out, ease-in-out), cubic-bezier() for custom curves and steps() for frame-by-frame effects such as sprite sheets. |
| How do you react when an animation ends in JavaScript? | Events | Listen for transitionend or animationend. A transition on two properties fires transitionend twice, once per property, so check event.propertyName. |
Media queries, prefixes and support
- What can a media query test besides width? Orientation, resolution, hover and pointer capability, and user preferences such as reduced motion and color scheme. Newer features came in later levels, so check support before relying on one.
- Why write `@media (min-width: 48em)` instead of pixels? Em-based breakpoints follow the user's font size setting, so the layout changes when text gets larger, not only when the window does.
- What is a vendor prefix? A browser-specific name such as
-webkit-or-moz-used while a feature was experimental. Most are no longer needed for the CSS3 features above; teams let a tool such as Autoprefixer add whatever their browser list still requires instead of writing them by hand. - What does @supports do? Applies rules only if the browser understands a property and value, so you can layer an enhancement on top of a working baseline.
@supports not (...)targets the fallback case. - Graceful degradation or progressive enhancement? Enhancement starts from a version that works everywhere and adds features where supported; degradation starts from the full design and patches older browsers. Interviewers usually want enhancement, plus a reason.
- How do gradients work, and are they images? linear-gradient and radial-gradient generate images, so they go in background-image and layer with other backgrounds. Repeating variants make stripes; conic gradients came later than the first CSS3 wave.
- What does the multi-column module do?
columnsorcolumn-countflows text into newspaper-style columns, withcolumn-gapandbreak-inside: avoidto keep cards whole. It is for flowing content, not page layout.
Senior and scenario questions
- A hover effect stutters on low-end phones. What do you change? Animate only transform and opacity, which can be handled by the compositor, instead of width, top or box-shadow; check in the browser's performance panel; and use will-change sparingly and only for elements about to animate. The layout and paint side is covered on the CSS page.
- Design wants a panel to slide open to its natural height. How? height to auto does not transition in older approaches. Options: animate max-height with a safe upper bound (simple, imperfect timing), use a transform-based reveal, or measure the height in JavaScript. Say the trade-off and check what current browsers support for animating to intrinsic sizes.
- How do you make animations accessible? Respect
prefers-reduced-motionby removing or reducing large movement, avoid flashing, keep content readable without the animation, and never hide information only inside an animation. - A shadow makes scrolling slow on a long list. Why? Large blurred shadows are expensive to paint, especially when repainted on scroll. Use smaller blur, a pseudo-element with the shadow whose opacity you animate, or fewer shadowed elements.
- The custom font flashes or text is invisible for a second. What is happening? The browser is swapping from a fallback or hiding text until the font loads. Preload the main font, serve WOFF2, choose a font-display value on purpose and pick a fallback with similar metrics.
- A spinner made with keyframes keeps running behind a modal and drains battery. What do you do? Pause it with
animation-play-state: pausedor remove the class when hidden, and do not keep infinite animations running off screen.
Fictional example
- Interviewer
- Make this product card lift slightly and get a stronger shadow on hover. Talk me through it.
- Candidate
- I would put a transition on the card for transform and the shadow, then on hover apply translateY of a few pixels upward. Animating box-shadow itself repaints each frame, so I would draw the stronger shadow on a ::after pseudo-element that starts at opacity 0 and fade that in, since opacity and transform are cheap. I would apply the same lift on :focus-within so keyboard users get it, wrap the movement in a reduced-motion query that keeps only the shadow change, and check it in the performance panel on a throttled CPU.
CSS3 practice plan
- Day 1: write from memory: a rounded card with two shadows, a gradient button, a custom font with font-display, and a one-line ellipsis.
- Day 2: selector drills: zebra rows, every third item, all but the last, links to PDFs, a CSS-only tab using :target.
- Day 3: five transitions and three keyframe animations, including one that holds its end state and one triggered by a class from JavaScript.
- Day 4: add reduced-motion rules and @supports fallbacks to everything you built, then test with motion settings turned on.
- Day 5: profile a janky animation in the browser and fix it by switching to transform and opacity.
- Days 6 and 7: explain each scenario above aloud in under a minute, and review the cascade and layout topics on the CSS page.
Live CSS rounds mix typing with talking, and the explanation is what interviewers remember. Natively, an AI interview assistant for Mac and Windows, transcribes a mock front-end round on your computer so you can review whether you explained why you chose transform over top. In practice sessions it can read a design or a broken layout from a screenshot and suggest an approach, help with coding questions, and with Pro or the free trial use the résumé and job description you add. Notes and transcripts are kept for review.
Questions people ask
What CSS3 questions are asked in interviews?
What CSS3 added over CSS2, box-sizing, border-radius and box-shadow, gradients, rgba versus opacity, @font-face, attribute and structural selectors, transforms, transitions versus animations, keyframes, media queries, vendor prefixes and @supports.
What is the difference between a CSS3 transition and an animation?
A transition runs between two values when a property changes, such as on hover or a class toggle. An animation runs @keyframes on its own, can loop and does not need a state change to start.
What are the new features of CSS3?
Rounded corners, shadows, multiple backgrounds, gradients, rgba and hsla colors, web fonts, 2D and 3D transforms, transitions, keyframe animations, media queries, new selectors, multi-column layout and flexbox.
Is CSS3 different from CSS?
CSS3 is the informal name for the modules that followed CSS 2.1. Today CSS is developed module by module, so interviewers use CSS3 to mean the modern feature set rather than a separate language.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
