Technology interview warm-up

HTML and CSS Interview Questions and Answers

HTML and CSS interview questions and answers for UI rounds, with short answers, code scenarios, semantic markup, accessibility, layout, cascade, responsive behavior, and browser debugging.

Reviewed May 20, 2026FrontendAtlas Editor65 visible HTML and CSS questions across semantics, forms, accessibility, layout, cascade, responsive UI, code scenarios, and browser debugging

On this page

Popular clusters

Popular HTML and CSS interview question clusters

Jump to the HTML and CSS areas that define UI rounds: semantics, forms, accessibility, cascade, layout, code scenarios, browser debugging, and responsive implementation.

Short answers

Top HTML and CSS interview questions and short answers, beginner to advanced

Review HTML and CSS together as a UI round: semantic markup, forms, accessibility, layout, cascade, responsive behavior, and debugging.

HTML Beginner

What is semantic HTML?

Semantic HTML uses elements that describe the meaning and structure of content, such as header, nav, main, article, section, button, and form. It helps browsers, search engines, assistive technologies, and other developers understand the page without guessing from class names. A common failure is replacing native buttons, links, and headings with generic div elements that then need extra keyboard and accessibility work.

Practice semantic HTML →
HTML Beginner

What is the DOM?

The DOM is the browser-created object tree that represents the parsed HTML document. JavaScript reads and updates this tree, while CSS selectors match elements in it for styling. The source HTML and live DOM can differ after scripts run, so debugging often means inspecting the current DOM instead of only reading the original markup.

Accessibility Beginner

How should labels work in HTML forms?

A form control needs a durable accessible name, usually from a label associated with for and id or by wrapping the control. Labels increase the clickable target and help screen-reader users understand the field. Placeholder text is not a replacement because it disappears during input and may not be announced as a stable label.

Build labeled forms →
Accessibility Beginner

What is accessibility in HTML and CSS?

Accessibility means the UI can be understood and operated by people using keyboards, screen readers, zoom, high contrast, or other assistive technology. HTML provides much of the semantic contract, while CSS must preserve readable contrast, focus visibility, and usable layout. A design can look correct but still fail if focus order, labels, or hidden content are wrong.

Review accessibility fixes →
Accessibility Beginner

How should alt text work for images?

Alt text describes the purpose of an image when the image carries information. Decorative images should usually have empty alt text so assistive technology can skip them. The edge case is an image inside a link or button, where the alt text may need to describe the action rather than the visual pixels.

Practice links and images →
HTML Beginner

When should you use a button instead of a link?

Use a link for navigation to another URL or location, and use a button for an action on the current page. Native elements provide the expected keyboard behavior, roles, focus handling, and activation events. A fake link or fake button often breaks keyboard access unless you rebuild behavior the browser already gives you.

HTML Intermediate

How does native form validation work?

Native validation uses attributes such as required, type, min, max, pattern, and minlength to let the browser check common constraints. It reduces custom JavaScript but should be paired with clear labels and useful error text. Server-side validation is still required because client-side validation can be bypassed.

Practice form validation →
HTML Beginner

What metadata belongs in the head?

A production document should include charset, viewport, title, useful description, canonical when needed, and relevant social metadata. These tags help browsers render correctly and help crawlers understand the page. Missing viewport metadata is a common mobile bug because the layout may render at a desktop-style width on phones.

Review head metadata →
CSS Beginner

What is the CSS box model?

The box model describes how content, padding, border, and margin combine to determine an element box and spacing around it. With content-box, width applies to the content area, while border-box includes padding and border in the declared width. Many layout bugs come from forgetting which sizing model is active.

Review the box model →
CSS Intermediate

How does the CSS cascade work?

The cascade decides which declaration wins when more than one rule applies to the same property. It considers origin, importance, cascade layers, specificity, scoping proximity, and source order. Source order only wins after the earlier cascade factors are effectively tied.

Review cascade order →
CSS Intermediate

What is CSS specificity?

Specificity is the selector scoring system used when competing rules are in the same cascade layer and origin. Inline styles, IDs, classes or attributes, and element selectors contribute different weight. A common failure is fixing conflicts by adding more specific selectors until the stylesheet becomes hard to override.

Practice specificity →
CSS Beginner

When should you use Flexbox?

Flexbox is best for one-dimensional layout where items flow in a row or column and need alignment or space distribution. It works well for nav bars, button groups, media objects, and vertically centered content. The trade-off is that complex two-dimensional placement is usually clearer with Grid.

Review Flexbox →
CSS Intermediate

When should you use CSS Grid?

Grid is best for two-dimensional layout where rows and columns both matter. It lets you define tracks, gaps, named areas, and responsive templates without relying on extra wrappers. It can be overkill for a simple row of controls where Flexbox would be easier to maintain.

Compare Grid and Flexbox →
CSS Intermediate

How does CSS positioning work?

Positioning changes how an element participates in normal document flow and how offsets are calculated. Relative keeps the element in flow, absolute positions against the nearest positioned ancestor, fixed attaches to the viewport, and sticky switches behavior based on scroll. Many bugs happen because the expected containing block is not the one the browser uses.

Review positioning →
CSS Intermediate

How does z-index work?

z-index only compares elements inside the relevant stacking context. New stacking contexts can be created by positioned elements, transforms, opacity, filters, isolation, and other properties. Raising a z-index value will not beat an element in a higher parent stacking context.

Debug z-index →
Responsive + debugging Beginner

What are media queries used for?

Media queries apply CSS conditionally based on viewport, device, user preference, or environment features. They are commonly used for layout changes, reduced motion, dark mode, and print styles. Good responsive CSS changes constraints and flow, not only font sizes.

Review media queries →
Responsive + debugging Intermediate

How do responsive images work?

Responsive images use srcset, sizes, picture, and modern loading attributes to let the browser choose an appropriate resource. The goal is to avoid shipping oversized images while preserving sharpness and layout stability. Width and height or aspect-ratio should be set so the page does not jump while images load.

CSS Intermediate

What are CSS custom properties?

CSS custom properties are variables declared with names such as --space and read with var(). They cascade, inherit by default, and can change at runtime without recompiling CSS. A missing fallback or unexpected inheritance path can make a component pick up the wrong token.

CSS Intermediate

What are pseudo-classes and pseudo-elements?

Pseudo-classes select an element in a state, such as :hover, :focus-visible, :checked, or :nth-child(). Pseudo-elements style a generated part of an element, such as ::before, ::after, or ::marker. The practical edge case is focus styling: :focus-visible is usually better than removing outlines globally.

Responsive + debugging Advanced

How do you debug CSS overflow?

Start by identifying which element is wider or taller than its container, then inspect fixed widths, long unwrapped text, min-width defaults, grid tracks, and absolute positioning. Flex and grid children often need min-width: 0 or min-height: 0 to shrink as expected. Hiding overflow can mask the symptom while leaving keyboard focus or content access broken.

Practice responsive fixes →
Responsive + debugging Advanced

What causes layout shift?

Layout shift happens when content moves after initial render because dimensions, fonts, ads, images, or async UI were not reserved. Set stable dimensions, reserve space for dynamic regions, and avoid inserting content above what the user is reading. The failure mode is a page that passes visual review but feels unstable while loading.

Accessibility Intermediate

How should focus states be styled?

Focus states should be visible, consistent, and not depend only on color. Use :focus-visible to show keyboard focus without adding noisy outlines for pointer users. Removing outlines globally breaks keyboard navigation and makes interactive elements hard to locate.

CSS Beginner

What is the difference between block, inline, and inline-block?

Block elements start on a new line and usually fill the available width. Inline elements flow with text and do not accept width and height in the same way, while inline-block keeps inline flow but allows box dimensions. Confusing these display modes often causes unexpected spacing, alignment, or clickable-area bugs.

Responsive + debugging Intermediate

How do rem, em, px, and percent differ?

px is an absolute CSS pixel unit, rem is relative to the root font size, em is relative to the current element font size, and percent depends on the property and containing context. rem is often easier for consistent spacing and type scales, while em can be useful for component-relative sizing. Percent can be powerful but surprising when height or transforms use a different reference than expected.

Responsive + debugging Advanced

How do you make an HTML and CSS component responsive?

Start with semantic markup and fluid layout constraints, then add breakpoints only where the component actually needs a different structure. Use max-width, minmax(), flexible tracks, wrapping, responsive images, and stable spacing tokens. Test narrow widths, long text, zoom, keyboard focus, and overflow instead of only resizing a desktop viewport.

Practice responsive CSS →

Beginner to experienced

HTML and CSS interview questions for beginners and experienced frontend developers

Use the level chips to separate baseline browser fundamentals from production UI debugging and maintainability trade-offs.

HTML and CSS interview questions for beginners

Start with valid document structure, semantic elements, labels, forms, the box model, basic selectors, Flexbox, Grid, and media queries. The goal is to explain what the browser gives you before reaching for custom scripts or heavy abstractions.

HTML and CSS interview questions for experienced frontend developers

Move into accessibility trade-offs, cascade strategy, layout debugging, stacking contexts, responsive images, performance, stable dimensions, and browser rendering behavior. Experienced answers should connect UI constraints to maintainable markup and CSS decisions.

Semantics + forms

HTML semantics, forms, and accessibility interview questions

Cover the markup decisions that shape real UI behavior: landmarks, headings, labels, validation, tables, dialogs, keyboard access, and accessibility checks.

Beginner

How do landmarks improve a page?

Landmarks such as header, nav, main, aside, and footer divide the page into recognizable regions. They help assistive technology users jump through the page without reading every element. The page should normally have one main landmark, and landmarks should represent real regions rather than decorative wrappers.

Review semantic elements →
Beginner

How should headings be structured?

Headings create an outline that helps users scan the page and understand content hierarchy. Use heading levels for structure, not for visual size. Skipping levels or using headings only for styling can make the page harder to navigate with assistive technology.

Intermediate

When should you add ARIA?

Add ARIA when native HTML cannot express the role, state, or relationship you need. Native controls should come first because they already include keyboard and accessibility behavior. Misused ARIA can create a worse accessibility tree than plain semantic markup.

Practice accessibility review →
Intermediate

How should form errors be exposed?

Form errors should be visible, specific, and connected to the affected control. Use text near the field, update aria-describedby when helpful, and keep focus behavior predictable after submission. Color alone is not enough because users may miss the state or use assistive technology.

Build validation states →
Intermediate

How do tables stay accessible?

Data tables need real table markup, a useful caption when context is not obvious, and header cells that define row or column meaning. Complex tables may need scope or header associations. Layout tables should be avoided because they create misleading relationships for assistive technology.

Advanced

How should a dialog be implemented?

A dialog should expose modal state, focus the right starting point, keep keyboard focus inside while open, and restore focus when closed. The native dialog element can help, but the surrounding interaction still needs careful labels and escape behavior. A visually correct overlay is incomplete if background content remains reachable by keyboard.

Practice dialog accessibility →
Beginner

How do anchors and buttons affect keyboard behavior?

Anchors activate with Enter and navigate, while buttons activate with Enter or Space and trigger actions. Using the wrong element changes expected keyboard behavior and screen-reader announcement. Styling can make them look alike, but semantics should follow the user action.

Advanced

How do you test HTML accessibility quickly?

Check keyboard navigation, visible focus, labels, headings, landmarks, image text, and form errors before relying on automated tools. Then run a validator, axe or Lighthouse, and inspect the accessibility tree for names and roles. Automated checks catch many issues but cannot prove that the interaction makes sense.

Review an accessibility flow →

Layout + cascade

CSS layout, cascade, and responsive interview questions

Review the CSS decisions that usually decide UI implementation rounds: Flexbox, Grid, layers, specificity, positioning, stacking, tokens, and breakpoints.

Intermediate

How do Flexbox and Grid differ?

Flexbox lays out items along one main axis and is strongest for alignment and distribution within a row or column. Grid defines rows and columns together, so it is better for two-dimensional page or card layouts. Mixing them is normal: Grid can place regions, and Flexbox can align content inside a region.

Compare layout systems →
Advanced

How do cascade layers change CSS conflicts?

Cascade layers let you group CSS by priority before specificity is compared. A low-specificity rule in a later layer can beat a highly specific rule in an earlier layer. This is useful for separating reset, theme, component, and override CSS without escalating selectors.

Review cascade rules →
Intermediate

How do you avoid specificity wars?

Use predictable selectors, keep component scopes shallow, and reserve high specificity for real overrides. Cascade layers, custom properties, and utility classes can reduce the need for nested selectors. The failure mode is CSS that works once but becomes impossible to safely change.

Practice specificity →
Advanced

How does position sticky fail?

Sticky positioning depends on scroll containment, offsets, and available space inside the parent. It often fails when an ancestor has overflow that creates a different scroll container or when the sticky element has no room to move. Debug by inspecting ancestors and the element offsets, not just z-index.

Review positioning →
Advanced

How do stacking contexts affect overlays?

An overlay can appear behind another element even with a large z-index if it is trapped in a lower stacking context. Transforms, opacity, filters, isolation, and positioned elements can create those contexts. Fixing the parent context or DOM placement is often better than increasing z-index values.

Debug stacking →
Intermediate

How should CSS custom properties be scoped?

Global tokens should describe broad design values, while component-level custom properties should expose controlled styling hooks. Because custom properties inherit, a value can travel farther than expected. Scope names and fallbacks should make overrides intentional.

Intermediate

How do you choose breakpoints?

Choose breakpoints where the content or component starts to fail, not only common device widths. A card may need a breakpoint because text wraps poorly or controls no longer fit. Content-driven breakpoints age better than a fixed list of device sizes.

Review media queries →
Advanced

How do you keep CSS maintainable at scale?

Keep selectors predictable, avoid accidental global leakage, document tokens, and make component states explicit. Prefer small layout primitives and clear naming over deeply nested selectors. Maintainability breaks when every new UI requires a more specific override than the last one.

Code scenarios

HTML and CSS code scenario interview questions

Use these small snippets to practice reading UI bugs from markup, selectors, layout constraints, stacking contexts, image sizing, and validation boundaries.

Beginner

Why is this input hard to use with assistive technology?

<input placeholder="Email" type="email">

The input has no durable accessible label. Add a label connected with for and id so the field name remains available after the user starts typing. Placeholder text can still provide an example, but it should not be the only name.

Fix labeled forms →
Beginner

Why can this image link have a poor accessible name?

<a href="/pricing">
  <img src="arrow.png" alt="arrow">
</a>

The link name becomes the image alt text, so "arrow" does not describe the destination or action. Use alt text such as "View pricing" or add visible text. The accessible name should match what the link does.

Practice links and images →
Advanced

Why does this flex item overflow?

.row { display: flex; }
.title { white-space: nowrap; }

Flex items have an automatic minimum size that can prevent shrinking below content width. Add min-width: 0 to the flex child that must shrink, then apply overflow handling intentionally. Setting overflow hidden on the parent may hide the symptom without fixing the layout constraint.

Practice responsive fixes →
Intermediate

Why does this grid create horizontal scroll?

.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

Three fixed columns can exceed the viewport when the container is narrow. Use responsive tracks such as repeat(auto-fit, minmax(220px, 1fr)) or add a breakpoint. The fix should preserve card readability and avoid squeezing content below its usable width.

Build a responsive grid →
Advanced

Why does this modal appear behind the header?

.header { position: relative; z-index: 10; }
.page { transform: translateZ(0); }
.modal { position: fixed; z-index: 9999; }

The transformed parent can create a stacking context that changes how the fixed modal is layered. A large z-index inside one context cannot beat a different parent context. Move the overlay to a safer root or adjust the stacking context hierarchy.

Review z-index →
Beginner

Why is this button not keyboard friendly?

<div class="button" onclick="save()">Save</div>

A div does not provide button semantics, keyboard activation, disabled behavior, or the expected role. Use a real button and style it with CSS. Rebuilding native behavior with roles and key handlers is more error-prone than using the correct element.

Intermediate

Why can this hero image cause layout shift?

<img src="/hero.jpg" alt="Dashboard preview">

The browser does not know the image dimensions before it loads, so surrounding content can move when the image appears. Add width and height or an aspect-ratio so space is reserved. Responsive CSS can still scale the image after the intrinsic ratio is known.

Intermediate

Why does this required field still need server validation?

<input name="email" type="email" required>

The browser can block common invalid submissions, but users or scripts can bypass client-side validation. Server validation protects the real data boundary and should return useful errors. Client validation improves user experience, not application trust.

Practice validation →

Browser debugging

Browser rendering and UI debugging interview questions

Connect CSS and HTML decisions to browser behavior: layout recalculation, paint, click targets, missing styles, invisible content, font loading, viewports, and focus order.

Advanced

How does the browser turn HTML and CSS into pixels?

The browser parses HTML into the DOM, parses CSS into style rules, calculates computed styles, builds layout, paints, and composites layers. JavaScript or resource loading can interrupt parts of this process. Performance work starts by identifying whether the problem is style, layout, paint, compositing, or scripting.

Advanced

What is a reflow or layout recalculation?

A layout recalculation happens when the browser must recompute element geometry. It can be triggered by DOM changes, class changes, font loading, image sizing, or reading layout after writing styles. Batching reads and writes reduces repeated layout work.

Intermediate

How do you debug an element that is not clickable?

Inspect whether another element is covering it, whether pointer-events is disabled, whether the element is outside its visible box, and whether it is actually a link or button. Stacking context and overflow clipping are common causes. The fix should preserve keyboard access, not only pointer clicks.

Review stacking behavior →
Beginner

How do you debug missing styles?

Check whether the stylesheet loaded, whether the selector matches, whether another declaration wins in the cascade, and whether the property is valid for that element. DevTools computed styles show the winning and overridden declarations. The fastest path is to inspect the actual element state instead of reading the stylesheet in isolation.

Review the cascade →
Intermediate

How do you debug invisible content?

Check display, visibility, opacity, color contrast, clipping, overflow, positioning, transforms, and whether the content exists in the DOM. Content can be present but inaccessible if it is visually hidden incorrectly or removed from the accessibility tree. The fix depends on whether the content should be hidden from everyone or only visually.

Advanced

How do fonts affect layout?

Font loading can change text metrics and cause layout shifts when the final font replaces a fallback. Use good fallback stacks, font-display choices, size-adjust where appropriate, and stable layout constraints. Long labels should be tested because they often reveal font and wrapping issues.

Intermediate

How do you debug mobile viewport issues?

Check the viewport meta tag, fixed widths, min-width values, overflowing grids, absolute positioning, and controls that do not wrap. Simulate narrow widths and zoom, then test on a real device when possible. The issue is often a single child that refuses to shrink.

Review viewport metadata →
Advanced

How do you debug focus order?

Navigate with the keyboard and compare the focus order to the visual and DOM order. Positive tabindex values usually create fragile ordering and should be avoided. If focus disappears into hidden or offscreen content, the hiding and modal behavior need to be fixed.

Practice focus handling →

Responsive UI

Responsive UI implementation interview questions

Practice mobile-first constraints, container behavior, navigation, responsive grids, long content, touch targets, motion preferences, and pre-ship responsive checks.

Beginner

What does mobile-first CSS mean?

Mobile-first CSS starts with the narrowest useful layout and adds complexity as space becomes available. This usually creates fewer overrides because the base styles handle constrained screens. The edge case is a desktop-only component that still needs a usable narrow fallback.

Review responsive CSS →
Advanced

How do container queries differ from media queries?

Media queries react to the viewport or environment, while container queries react to the size or style context of a container. Container queries make reusable components adapt where they are placed. They are most useful when the same component appears in a sidebar, grid, and full-width region.

Intermediate

How should a navigation bar adapt on small screens?

The nav should preserve readable labels, reachable focus states, and clear current-location cues. Flex wrapping, overflow menus, or a disclosure pattern can work depending on item count. A responsive nav fails if it only hides links without giving users another path to them.

Build a responsive nav →
Intermediate

How should cards adapt in a responsive grid?

Cards should keep readable text, stable media ratios, and consistent action placement as columns change. Grid with minmax() and auto-fit can reduce breakpoint code while preserving minimum card width. Test long titles and missing images because they expose fragile card layouts.

Build card grids →
Advanced

How do you handle long words and untrusted text?

Long words, URLs, and user-generated strings can break otherwise clean layouts. Use overflow-wrap, min-width: 0, max-width constraints, and clear truncation rules when content must stay on one line. Truncation should not hide essential information without another way to access it.

Fix responsive overflow →
Intermediate

How do you keep touch targets usable?

Interactive controls need enough physical size and spacing to avoid accidental taps. CSS should not shrink buttons below a usable hit area just to fit a dense layout. If space is tight, wrapping or grouping controls is better than making them tiny.

Intermediate

How do reduced motion preferences affect CSS?

The prefers-reduced-motion media query lets users request less animation. Use it to remove or simplify motion that can distract, delay, or cause discomfort. Essential state changes should still be visible without relying on animation.

Review media features →
Advanced

How do you test responsive HTML and CSS before shipping?

Test narrow and wide widths, zoom, long text, keyboard navigation, image loading, and common device sizes. Inspect overflow, focus visibility, layout shift, and readable contrast. A page that only passes one viewport can still fail real users because content and device constraints vary.

Practice responsive review →

Most crucial HTML and CSS coding interview questions

Ranked by interview importance so you can start with the highest-signal implementation drills.

View full coding list

Need more implementation reps? Open the full coding list or follow a study plan.

Most crucial HTML and CSS concept questions for interviews

Ranked by interview importance to strengthen your explanation speed where it matters most.

View full concepts list

Need more concept coverage? Open the full concepts list or browse company packs.

Interview prep context

What HTML and CSS interview rounds test

HTML and CSS interview questions test whether you can connect semantic markup, accessible forms, layout systems, cascade behavior, and responsive constraints in one UI answer.

Editorial policy

What this round tests

  • Semantic HTML, forms, labels, landmarks, metadata, and browser defaults.
  • CSS layout with flexbox and grid, plus cascade, specificity, custom properties, and responsive sizing.
  • Whether you can debug overflow, alignment, stacking, and accessibility issues without guessing.

How to use these questions

  • Start with one HTML concept question and one CSS layout question in the same session.
  • Use coding prompts when your explanation is clear but the implementation still breaks under constraints.
  • Move into the UI interviews guide when accessibility, layout, or browser behavior keeps repeating as the weak area.

HTML and CSS prompts are reviewed for practical browser behavior, accessible UI decisions, and interview-ready debugging language.

Quick answers

Common questions before you start

Are these HTML and CSS interview questions for beginners and experienced developers?

Yes. The page starts with beginner HTML and CSS fundamentals, then moves into experienced frontend topics such as accessibility, cascade strategy, layout debugging, browser rendering, responsive UI, and code scenarios.

Does this page cover accessibility and forms?

Yes. It covers semantic HTML, labels, form validation, landmarks, focus states, alt text, dialog behavior, and quick accessibility testing for practical UI rounds.

Does this page cover CSS layout, cascade, and responsive UI?

Yes. It covers box model, cascade, specificity, Flexbox, Grid, positioning, z-index, media queries, responsive images, overflow debugging, and layout shift.

Where should I practice HTML and CSS coding scenarios?

Start with the code scenarios and preview prompts on this page, then open the HTML/CSS coding list for forms, links, images, semantic layouts, Flexbox nav bars, and responsive card grids.

Keep the scope tight

Start with one route first. Then expand into Question Library, Study Plans, and Company Prep only when you need them.

Recommended preparation

Recommended HTML and CSS interview preparation

Start with the interview preparation guide and shared baseline, then tighten HTML and CSS coding, concepts, and follow-up depth.

  1. Frontend interview preparation guideStart hereLearn the interview stages and scoring signals before narrowing into this technology.Process, rounds, and plan
  2. FrontendAtlas Essential 60Start with the shared shortlist to stabilize interview fundamentals before framework-specific depth.Shared frontend baseline
  3. HTML and CSS coding + concept questionsPractice HTML and CSS implementation prompts and explanation follow-ups from one filtered library view.Coding execution + concept recall
  4. HTML and CSS interview prep pathA practical guide for accessible UI prompts, semantic markup, and layout-focused rounds.Framework-specific sequencing
  5. Final-round coverageAdd system design, behavioral, and company-style follow-ups after the framework baseline is stable.System design, behavioral, company rounds