All questions
Showing of 110Explain the CSS cascade and specificity
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The cascade decides which declaration wins when several rules set the same property on one element. It sorts them by origin and importance first, so author styles beat browser defaults, and then by cascade layer. Only then does specificity decide, and if specificity ties, the declaration that comes later in the source wins.
Specificity is a weight with three columns, compared from left to right:
- IDs, such as
#nav - classes, attributes and pseudo-classes, such as
.btn,[type="text"]and:hover - elements and pseudo-elements, such as
pand::before
The first column that differs decides. One ID beats any number of classes, so #nav a outranks a selector of eleven classes. The universal selector * and :where() add nothing.
An inline style attribute beats any selector in a normal author stylesheet. !important lifts a declaration above all normal declarations, whatever their specificity, so use it sparingly.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between display: none and visibility: hidden?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
display: none removes the element from the layout, so it takes no space and the content around it closes the gap. visibility: hidden keeps the element's box in the layout and only stops drawing it, so an empty space stays where it was.
They also differ for children. A child of a visibility: hidden parent can set visibility: visible and appear again, while nothing inside a display: none element renders.
In two ways they behave the same:
- Neither one can be clicked or take keyboard focus.
- Both leave the accessibility tree, so neither hides text visually while keeping it for screen readers.
Toggling display makes the browser recalculate the layout, because the page reflows around the gap. Toggling visibility only repaints.
opacity: 0 is a third option. It keeps the space and still receives clicks, which is why fade effects often pair it with visibility.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the difference between margin and padding
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Padding is space inside an element's border, between the border and the content, while margin is space outside the border that pushes neighboring elements away.
Where each one sits explains how they behave:
- The background color fills the padding. The margin is always transparent.
- Padding adds to the rendered size under the default
content-box. Withbox-sizing: border-box, padding sits inside the declared width instead. Margin never counts toward the width. - Vertical margins between blocks can collapse into one gap. Padding never collapses.
- Margin can be negative or
auto, andmargin: 0 autocenters a block that has a width. Padding cannot be negative.
Use padding to give the content room inside its box, and margin to space boxes apart.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the different types of CSS selectors
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
CSS selectors pick out elements or parts of elements by their features, their place in the document, or their state.
- Element, class and ID selectors match names such as
div,.classnameand#idname. - Attribute selectors match on an attribute, as in
[type="text"]. - Combinators relate two elements.
- The descendant combinator in
div pmatches at any depth. - The child combinator in
div > pmatches direct children only. - The adjacent sibling in
h2 + pis thepright after an H2 heading. - The general sibling in
h2 ~ pis any laterpsibling of an H2 heading.
- The descendant combinator in
- A pseudo-class such as
:hovermatches a state, and a pseudo-element such as::beforetargets part of an element.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How does the universal selector (*) work and when should you use it?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The universal selector * matches every element. On its own it adds nothing to specificity. In your own stylesheet, any type, class or ID rule for the same property overrides a bare *. Its two common uses are a reset at the top of a stylesheet and a rule for everything inside a container.
/* Reset all margins and padding */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Target all descendants */
.container * {
font-family: Arial, sans-serif;
}
The reset zeroes the browser's default spacing and switches every box to border-box. It wins over browser defaults because author styles beat them whatever their specificity. Because * does not match pseudo-elements, resets often list *, *::before, *::after.
Use it sparingly, because it can affect performance and override styles you did not intend. It sets the value directly on each element, which beats any value that element would inherit. And .container * has the class's specificity, so it also beats type rules such as code { font-family: monospace; } inside the container.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the CSS box model
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The box model says every element renders as a rectangle built from four layers, from the inside out:
- Content, where the text and images sit, sized by
widthandheight. - Padding, clear space between the content and the border.
- Border, the line drawn around the padding.
- Margin, transparent space outside the border that separates the box from its neighbors.
The space a box takes up is the content plus padding, border and margin on both sides. With the default box-sizing: content-box, width sets only the content, so padding and border are added on top. A box with width: 200px, padding: 20px and a 5px border renders 250px wide before its margins.
Setting box-sizing: border-box makes width include the padding and border, so the same box stays 200px wide. Margins always sit outside, and vertical margins between blocks can collapse into one gap.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the different values for the overflow property?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
overflow takes five values that decide whether content bigger than its box spills out, gets clipped, or scrolls.
visible, the default, lets content spill outside the box.hiddenclips content at the padding edge with no scrollbars, though script can still scroll it.scrollclips and always shows scrollbars, even when nothing overflows.autoclips and shows scrollbars only when content overflows.clipclips likehiddenbut allows no scrolling at all, even from script.
Every value except visible and clip creates a new block formatting context. So overflow: hidden contains floats and stops margin collapsing with children, while clip does neither.
overflow is shorthand for overflow-x and overflow-y, so overflow: hidden auto sets each axis on its own.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you center an element both horizontally and vertically?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Make the parent a flex or grid container and let it align the child. Three methods are common, and the first two are the usual choice today.
Flexbox centers on both axes: justify-content aligns along the main axis and align-items along the cross axis.
.container {
display: flex;
justify-content: center;
align-items: center;
}
Grid centers with a single alignment declaration. place-items: center sets align-items and justify-items together.
.container {
display: grid;
place-items: center;
}
Absolute positioning fits an element that must sit on top of other content, such as a modal. top and left move its top-left corner to the middle of the positioned parent, and translate pulls it back by half its own size.
.element {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
Flexbox and grid center a child of any size and keep it in normal flow. The absolute method takes the element out of flow, and its parent needs a position other than static.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are the different positioning values and how do they work?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The position property decides whether an element stays in normal flow and what its offset properties are measured from. It has five values:
static, the default, keeps the element in normal flow and ignores offsets.relativekeeps its space in the flow and shifts the element visually.absolutetakes the element out of the flow and places it against its nearest positioned ancestor, or the initial containing block.fixedtakes the element out of the flow and places it against the viewport, so it stays put while the page scrolls.stickyacts likerelativeuntil scrolling reaches its offset, then sticks there, but only while its containing block is still on screen.
A sticky element sticks inside its nearest scrolling ancestor, so overflow: hidden on a parent can stop it working.
A fixed element is placed against an ancestor instead of the viewport when that ancestor has a transform, filter or perspective.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are media queries and how do you use them?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
A media query applies a block of CSS only while the device or viewport matches a condition, such as a minimum width. The browser re-checks the condition as the window resizes, so the styles switch live.
/* Mobile first approach */
.container {
width: 100%;
}
/* Tablet */
@media (min-width: 768px) {
.container {
width: 750px;
}
}
/* Desktop */
@media (min-width: 1024px) {
.container {
width: 1000px;
}
}
The example is mobile first. The base rule styles the smallest screens, and each min-width block layers on changes once the viewport is wide enough. On a wide screen both blocks match, and the desktop width wins because it comes later with the same specificity.
The features queried most are the viewport's width and height. orientation and resolution cover screen shape and pixel density. Media queries also test user preferences such as prefers-color-scheme, and media types such as print. Conditions combine with and, and a comma between queries means or.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What is the difference between min-width and max-width in media queries?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
min-width applies its styles when the viewport is at least that wide, and max-width applies them when the viewport is at most that wide. Both include the value itself.
/* Mobile first */
@media (min-width: 768px) { /* Tablet and up */ }
/* Desktop first */
@media (max-width: 767px) { /* Mobile only */ }
The choice sets the direction you build in. With mobile first, the base styles target small screens and min-width queries add layout as the screen grows. With desktop first, the base styles target large screens and max-width queries undo or simplify them as it shrinks.
Mobile first is generally preferred, partly for performance, because phones never apply the rules inside the wider blocks. It also keeps the base styles simple, since small screens start from a single column with nothing to override. Desktop first piles up overrides, because each smaller breakpoint undoes the one above it.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
Explain the viewport meta tag and its importance
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
The viewport meta tag tells a mobile browser how wide to lay out the page and how far to zoom. Without it, a phone lays the page out in a virtual viewport, usually 980px wide, then shrinks it to fit, so text renders tiny.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
width=device-widthmakes the layout viewport match the device's width in CSS pixels.initial-scale=1.0opens the page at normal zoom instead of zoomed out.user-scalable=noblocks pinch zoom. Avoid it, because it stops people with low vision from enlarging the text.
Responsive CSS depends on this tag. Media queries test the layout viewport, so without it a phone matches the desktop breakpoints. On phones with a notch, adding viewport-fit=cover extends the page under it, and env(safe-area-inset-top) and its siblings pad content back into view.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you make images responsive?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Make the image fluid so it shrinks with its container, then use srcset to let the browser download a file sized for the screen.
img {
max-width: 100%;
height: auto;
}
max-width: 100% stops an image from overflowing a narrow container, and height: auto keeps its aspect ratio as it scales.
<img src="image-400.jpg"
srcset="image-400.jpg 400w,
image-800.jpg 800w,
image-1200.jpg 1200w"
sizes="(max-width: 600px) 400px,
(max-width: 1000px) 800px,
1200px"
alt="Description">
srcset lists the same image at several widths, and sizes tells the browser how wide it will display at each breakpoint. The browser weighs that against the screen's pixel density and downloads only the best match. For a different crop on small screens, <picture> with <source media> handles art direction.
When an image must fill a fixed frame, aspect-ratio reserves the box and object-fit: cover crops the image to fill it.
CSS background images use media queries, or image-set() for pixel density, to swap files.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
What are vendor prefixes and are they still necessary?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
Vendor prefixes are engine-specific prefixes on property names that browsers used for experimental CSS, and today they are rarely needed. Each engine had its own:
-webkit-for Chrome, Safari and newer Edge-moz-for Firefox-ms-for Internet Explorer and Edge before Chromium-o-for old Opera
.element {
-webkit-transform: rotate(45deg); /* Safari/Chrome */
-moz-transform: rotate(45deg); /* Firefox */
-ms-transform: rotate(45deg); /* IE */
transform: rotate(45deg); /* Standard */
}
The standard declaration goes last, so any browser that supports it uses it.
Browsers now ship experimental features behind flags instead, and modern CSS features need fewer prefixes. A few properties still require one, such as -webkit-line-clamp. Use a tool like Autoprefixer to add prefixes automatically, only where your supported browsers need them.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you use CSS @import and what are its limitations?
Answer it yourself first - out loud, or typed below.
How should your speech become text?
Listening… your words appear above as you speak - tap Stop when you're done.
Recording · cr - tap Stop & transcribe when you're done.
Transcribing with AI…
Voice:
Last attempt -
@import pulls another stylesheet into the current one, and the imported rules apply as if they were written at that point in the file.
/* Must be at top of stylesheet */
@import url("base.css");
@import url("components.css") screen and (min-width: 768px);
@import "utilities.css" layer(utilities);
/* Regular styles after imports */
.custom {
color: red;
}
The main limitation is speed. The browser only discovers an @import after it downloads and parses the file that contains it, so the files load one after another. Rendering stays blocked until the imported CSS arrives. Separate <link> tags in the HTML download in parallel, so they are better for performance.
The rule must come before every other rule in the file, except @charset and @layer statements, or the browser ignores it. Imports can be conditional on a media query or a supports() condition, and the browser can skip a file whose condition fails. layer() puts the imported rules into a cascade layer.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
How do you style placeholder text?
What are screen reader-only CSS classes?
What is the difference between inline, inline-block and block elements?
How does CSS inheritance work, and which properties are inherited?
What is the difference between resetting and normalizing CSS?
How is responsive design different from adaptive design?
What is box-sizing and what are its values?
What is Flexbox and what problems does it solve?
What are CSS custom properties (CSS variables) and how do you use them?
What is the difference between :nth-child() and :nth-of-type()?
Explain attribute selectors and their variations
What are pseudo-elements and how do they differ from pseudo-classes?
How do margins collapse and how can you prevent it?
Explain min-width, max-width, and how they interact with width
Explain the main axis and cross axis in Flexbox
What are the flex properties (flex-grow, flex-shrink, flex-basis)?
What is CSS Grid and how does it differ from Flexbox?
Explain grid-template-areas and how to use it
What is the difference between fr unit and percentage in CSS Grid?
Explain the z-index property and stacking context
What are CSS units and when should you use each?
What is the clamp() function and how is it useful for responsive design?
What is the difference between CSS transitions and animations?
Explain the CSS transition properties
What are CSS keyframes and how do you use them?
Explain the animation properties in CSS
What are CSS transforms and what types are available?
What is the transform-origin property?
How do you create a CSS-only flip card effect?
What are CSS gradients and how do you create them?
Explain CSS filters and their effects
What are CSS counters and how do you implement them?
Explain the object-fit and object-position properties
How do you handle browser compatibility issues in CSS?
How do you use @supports for feature detection?
What is the difference between graceful degradation and progressive enhancement?
How do you test CSS across different browsers?
What is BEM methodology and how do you implement it?
What are CSS modules and how do they work?
Explain the OOCSS (Object-Oriented CSS) methodology
What is the difference between CSS-in-JS and traditional CSS?
What is Atomic CSS and when would you use it?
What are CSS logical properties and why are they useful?
How do CSS nesting rules work?
What are CSS environment variables and how do you use them?
How do CSS math functions work?
What is color-scheme and how does it work with dark mode?
How do you create a sticky footer that stays at bottom?
How do you create equal-height columns?
How do you create responsive typography?
How do you implement a CSS-only accordion?
How do you create a CSS tooltip?
How do you style form inputs consistently across browsers?
How do you create custom radio buttons and checkboxes?
How do you implement form validation styling with CSS?
How do you create CSS for print media?
What are CSS page break properties?
How does CSS support accessibility?
How do you debug CSS layout issues?
What CSS linting rules should you follow?
How do CSS scroll-snap properties work?
What is the CSS light-dark() function?
What is a block formatting context and how does it work?
What do the :is(), :where() and :not() pseudo-classes do?
What are the advantages and disadvantages of CSS preprocessors?
How would you implement a design that uses non-standard fonts?
Explain 3D transforms and the perspective property
What is the clip-path property and how do you use it?
How do CSS masks work?
What are CSS container queries and how do they work?
What is the :has() selector and how is it useful?
How do you implement CSS custom media queries?
What is CSS Subgrid and how does it work?
What are the latest CSS features and how do you stay updated?
What is the will-change property and when should you use it?
How do you create smooth 60fps animations?
What is the isolation property and when would you use it?
How can you optimize CSS for better performance?
What is Critical CSS and how do you implement it?
How do CSS containment and the contain property work?
What are the performance implications of different CSS properties?
How do you organize CSS in large projects?
Explain CSS cascade layers (@layer)
What is CSS anchor positioning and how does it work?
What are CSS color functions and color spaces?
How do CSS scroll-driven animations work?
What is the CSS @scope rule?
How do you implement a masonry layout with CSS?
What is the CSS Paint API and how does it work?
How do you implement CSS architecture for design systems?
How do you handle CSS specificity conflicts in large applications?
How do you optimize CSS for Core Web Vitals?
What are CSS custom highlights and how do you use them?
How do CSS trigonometric functions work?
How does a browser decide which elements match a CSS selector?
This answer is part of Pro.
The full written answer, with the trade-offs and follow-ups an interviewer will probe.
No matches
Try a different filter or search term.
CSS3 in pictures.
A quick recap of CSS3 in 33 short animated pictures, one idea at a time. About 8 min to get the whole topic back in your head before you walk in. Pause any picture, slow it down, or step through it.
Pro The first chapter is free to play. The other 28 pictures come with Pro.
CSS3 cheatsheet
- Cascade & selectors01
- Box model & positioning02
- Flexbox & Grid03
- Responsive design04
- Transitions & animations05
- Theming, color & effects06
- Forms, print & accessibility07
- Performance08
- Architecture & tooling09
- Browser support & debugging10
- The model11
- + 5 more inside
This picture is part of Pro. The first chapter is free to play; the other 28 pictures come with Pro.
Get Pro · $10/mo Already Pro? Sign in95 of 110 CSS3 answers are in Pro.
Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.
- Full answers + code
- AI explanations, simpler or deeper
- 1,000 AI credits / month
- Cancel anytime
Change topic
Pick a different technology or stack. Your current topic stays put until you choose a new one.
MEAN
MongoDB, Express, Angular, Node.jsMERN
MongoDB, Express, React, Node.jsDjango
Python Full-Stack DevelopmentRuby on Rails
Convention over ConfigurationServerless on AWS
Serverless Architecture on AWSInterviewers also test these - they're common to every stack, whichever one you picked above.
Flutter Mobile
Flutter Cross-Platform Mobile DevelopmentInterviewers also test these - they're common to every stack, whichever one you picked above.
Spring Boot
Enterprise Java Development.NET
Microsoft EcosystemVue
Vue.js, Vite, TypeScript, Tailwind, Node.jsGo Backend
Golang, gRPC, PostgreSQL, Redis, RabbitMQInterviewers also test these - they're common to every stack, whichever one you picked above.
FastAPI
Python, FastAPI, SQLAlchemy, PostgreSQLReact Native
React, TypeScript, Redux, FirebaseiOS Native
Swift, SwiftUI, UIKit, FirebaseAndroid Native
Java, Jetpack Compose, FirebaseDevOps / Platform
Docker, Kubernetes, Terraform, CI/CDInterviewers also test these - they're common to every stack, whichever one you picked above.
AI Engineer
LLMs, RAG, Agents, EvalsAI-Powered Developer
Claude Code, Copilot, Agentic WorkflowsCore SWE Interview Prep
Data structures, algorithms, OS, concurrency, networking, gitInterviewers also test these - they're common to every stack, whichever one you picked above.
Interviewers also test these - they're common to every stack, whichever one you picked above.