Questions
27 of 49
1What is the display property in CSS used for?
2What is the default display value for <div>, <span>, <p>, and <a> tags?
3What is the difference between display: block and display: inline?
4How does display: inline-block behave?
5What happens when you set display: none on an element?
6How is display: none different from visibility: hidden?
7Can display: none affect layout reflow or accessibility?
8What’s the effect of display: block on inline elements like <span>?
9What’s the difference between display: table and actual HTML <table> elements?
10How do replaced elements (like <img> or <input>) behave with different display values?
11How is display: flex different from display: block?
12What is the difference between display: grid and display: flex?
13What happens if you apply display: inline-flex to a container?
14What is the difference between display: contents and display: none?
15What is display: list-item, and when is it used?
16How does display: run-in work, and why is it rarely used?
17What’s the difference between display: inline-grid and display: grid?
18How can you make an element behave like both inline and block elements?
19What happens to child elements when the parent has display: contents?
20How does the display property affect box model calculations?
21How can you change a block-level element to behave like an inline element without changing its tag?
22How do you center elements using display: flex or display: grid?
23How can you hide elements but keep their layout space?
24What happens to child elements when their parent has display: none?
25How can display: contents help improve semantic markup but hurt accessibility?
26What happens if you set display: flex on the <body> tag?
27How do you use display to build responsive layouts?
28What is the difference between using display and position to arrange elements?
29How can you visually hide an element but keep it accessible for screen readers?
30How does display affect stacking and z-index behavior?
31Does display: none remove an element from the DOM?
32Can an element with display: none trigger CSS transitions or animations?
33How does display interact with CSS pseudo-elements (::before, ::after)?
34What is the difference between visibility: collapse and display: none in table elements?
35How can you make text and icons align properly using display values?
36How do block formatting contexts relate to display types?
37What happens if you apply display: table to a flex container?
38How does display behave differently for replaced vs. non-replaced elements?
39Can display be animated using CSS transitions?
40How does display affect the accessibility tree and ARIA roles?
41How can you make a <li> element appear horizontally instead of vertically?
42How do you create a two-column layout without using float or position, using only display?
43How do you make an image and text sit side by side neatly?
44How would you make a navigation menu horizontally aligned using display?
45How can you make all elements behave as border-box and block-level by default?
46How would you use display: flex to make a footer stick to the bottom?
47How can display: grid simplify responsive design compared to floats?
48When would you prefer display: inline-flex over display: flex?
49How can you use display: contents to remove extra wrappers in semantic HTML structures? How can incorrect use of display lead to accessibility or SEO problems?
27 / 49

How do you use display to build responsive layouts?

Difficulty: 6/10
Flexbox & Grid, Responsive Design, CSS Layout Architecture

Building Responsive Layouts Using CSS Display

The CSS display property is essential for building responsive layouts. By combining different display values with media queries, you can create flexible, adaptive designs.

Common Approaches
  1. 1

    display: flex – Use Flexbox for one-dimensional layouts (row or column). Flex items can wrap with flex-wrap, and alignment can be controlled with justify-content and align-items. Perfect for responsive navbars, card rows, or grids that adjust on smaller screens.

  2. 2

    display: grid – Use Grid for two-dimensional layouts. You can define explicit columns and rows with grid-template-columns and grid-template-rows, and adjust them with media queries to make layouts adapt at different breakpoints.

  3. 3

    display: inline, inline-block, inline-flex, inline-grid – These allow elements to flow inline with text or other inline elements, useful for smaller components or inline menus.

  4. 4

    display: contents – Remove unnecessary wrapper boxes while keeping children in the layout. Can simplify responsive designs but use carefully for accessibility.

Example: Responsive Flex Layout

In this example, the container uses display: flex with flex-wrap: wrap, so child elements automatically wrap to the next line when the viewport is too narrow, creating a responsive layout without changing the HTML.

Best Practices
  1. 1

    Use flex or grid for main layout sections that need to adjust across screen sizes.

  2. 2

    Combine display properties with media queries to change layout direction or column count responsively.

  3. 3

    Use inline-* values for small components that need to flow with text or inline content.

  4. 4

    Test layouts at multiple viewport sizes to ensure proper wrapping and alignment.

Scenario Questions

0-2 years experience

  1. 1Imagine you have a row of three product cards. On mobile, we want them stacked vertically, but on desktop, they should sit side-by-side and share the space equally. How would you configure the display property and its companion properties to achieve this?
  2. 2We have a navigation bar where the logo is on the left and three links are on the right. When you apply display: flex to the container, everything bunches up on the left. How do you push those links to the far right, and what happens to that layout if the screen gets too narrow?

2-5 years experience

  1. 1We're building a dashboard widget grid. The designer wants a multi-column layout that automatically wraps and fits as many columns as possible without using hardcoded media queries. How would you use CSS Grid's display properties to build this, and how do you prevent empty space when there are only one or two items?
  2. 2A developer on your team used display: flex for a complex page layout, but they are struggling because some flex items are shrinking past their content size and breaking the text alignment on smaller screens. How would you debug this, and how do you decide when to switch a container from display: flex to display: grid?

5-8 years experience

  1. 1We are designing a highly reusable, responsive 'Card' component for our enterprise design system. It needs to support internal media-query-like behavior (changing from horizontal to vertical layout) based on its container's width rather than the viewport. How would you approach this using modern CSS display properties, and what are the performance implications of container queries versus traditional media queries?
  2. 2Our legacy application uses a mix of display: inline-block and floats for its grid system, causing rendering bugs and layout shifts on slow mobile connections. If you were tasked with refactoring this core layout engine to Flexbox or Grid, how would you plan the migration to ensure zero visual regression and maintain backward compatibility for older browsers?

8+ years experience

  1. 1Our organization has 50+ micro-frontends managed by different teams, and we're seeing massive layout thrashing and inconsistent responsive behaviors because teams are nesting Flexbox and Grid layouts arbitrarily. How would you design a global layout orchestration strategy or CSS architecture to standardize responsive behavior across these teams without micro-managing their styling?
  2. 2We are migrating our core web application to support strict accessibility (WCAG 2.1 AA) and internationalization (RTL languages). How does your choice of CSS display modes (like Flexbox vs Grid) impact DOM order versus visual order, and how would you establish engineering guidelines to prevent teams from breaking screen-reader navigation while building responsive layouts?

Follow-up Questions

  • How does 'display: contents' affect the accessibility tree and flex/grid item relationships?
  • What are the performance differences between rendering a massive list with Flexbox versus CSS Grid?
  • How do you handle browser fallback support for modern CSS Grid features in a legacy enterprise app?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.