Coding practice
CSS Coding Questions
15 hands-on challenges with prompts and solution sketches for CSS interview rounds.
Challenge set
15 coding questions
1. Center with Flexbox
cssCenter a child both horizontally and vertically.
.stage {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
} 2. CSS Grid Cards
cssCreate a responsive card grid.
.cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
gap: 1rem;
} 3. Sticky Header
cssMake a header stick to the top.
.site-header {
position: sticky;
top: 0;
z-index: 100;
background: #fff;
} 4. Clamp Typography
cssUse fluid font sizing with clamp.
.hero-title {
font-size: clamp(1.75rem, 4vw, 3rem);
line-height: 1.15;
} 5. Aspect Ratio Media
cssPreserve 16:9 for media.
.media {
aspect-ratio: 16 / 9;
width: 100%;
object-fit: cover;
} 6. Custom Checkbox
cssStyle a custom checkbox with accent-color.
input[type="checkbox"] {
accent-color: #da0037;
width: 1.1rem;
height: 1.1rem;
} 7. Dark Mode Query
cssApply dark theme styles with prefers-color-scheme.
@media (prefers-color-scheme: dark) {
:root {
color-scheme: dark;
--bg: #111;
--text: #f5f5f5;
}
} 8. Truncate Text
cssTruncate a single line with ellipsis.
.truncate {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
} 9. Container Query Card
cssChange card layout with container queries.
.card-wrap {
container-type: inline-size;
}
@container (min-width: 28rem) {
.card {
display: flex;
gap: 1rem;
}
} 10. Focus Visible Ring
cssAdd accessible focus styles.
:focus-visible {
outline: 3px solid #da0037;
outline-offset: 2px;
} 11. CSS Variables Theme
cssDefine brand tokens with custom properties.
:root {
--primary: #da0037;
--surface: #f5f5f5;
--text: #171717;
}
body {
background: var(--surface);
color: var(--text);
} 12. Skeleton Loading
cssCreate a shimmer-like skeleton block without animation libraries.
.skeleton {
background: #e5e5e5;
border-radius: 0.5rem;
min-height: 1rem;
} 13. Logical Properties
cssUse logical spacing for RTL-friendly layout.
.panel {
margin-inline: auto;
padding-block: 1.5rem;
padding-inline: 1rem;
} 14. Scroll Snap Gallery
cssBuild a horizontal snap gallery.
.gallery {
display: flex;
gap: 1rem;
overflow-x: auto;
scroll-snap-type: x mandatory;
}
.gallery > * {
scroll-snap-align: start;
flex: 0 0 80%;
} 15. Print Styles
cssHide chrome and expand content for print.
@media print {
.site-header,
.site-footer {
display: none;
}
main {
width: 100%;
}
}