Questions
26 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?
26 / 49

What happens if you set display: flex on the <body> tag?

Using display: flex on the <body> Tag in CSS

Setting display: flex on the <body> tag turns the entire body into a flex container, allowing its immediate children to be laid out according to Flexbox rules.

Effects on Layout
  1. 1

    All direct child elements of <body> become flex items and can be aligned, spaced, and ordered using Flexbox properties.

  2. 2

    You can use justify-content, align-items, and flex-direction to control the placement of all main page content.

  3. 3

    The body itself behaves like a block element by default, but flex container rules will control its children.

  4. 4

    Height issues may arise: if you want vertical centering or full-page layouts, you may need height: 100vh on <body> to ensure the flex container fills the viewport.

Example: Flex on Body

In this example, the <header>, <main>, and <footer> elements become flex items. They are vertically centered in the viewport because the body uses justify-content: center and align-items: center.

Best Practices
  1. 1

    Use display: flex on <body> when you want to control overall page layout using Flexbox.

  2. 2

    Set the body height explicitly (like 100vh) to enable vertical alignment.

  3. 3

    Combine with min-height or flex-grow on child elements for responsive full-page layouts.

  4. 4

    Be careful with global flex rules—they affect all direct children, so apply additional wrappers if needed for complex layouts.

Difficulty: 3/10
Topics: Flexbox layout, global page styling, layout side‑effects

Scenario Questions

0-2 years experience
  1. 1

    If you add display:flex to the <body> of a page that has a header, main, and footer, what will happen to their layout?

  2. 2

    How would you keep the footer at the bottom of the viewport after setting the body to flex?

  3. 3

    What default flex values affect the children of the body and how would you change them?

2-5 years experience
  1. 1

    We added display:flex to <body> and the page stopped scrolling. Walk me through how you'd diagnose and fix the issue.

  2. 2

    A modal that used absolute positioning is now misaligned after the body became a flex container. What steps would you take to debug it?

  3. 3

    Explain the trade‑offs of applying flex to <body> versus wrapping the page content in a dedicated flex container.

5-8 years experience
  1. 1

    In a large SPA you need a sticky header, a scrollable main area, and a footer. How would you structure CSS on <html> and <body> when the body is a flex column to avoid layout glitches on different browsers?

  2. 2

    Discuss any performance or rendering concerns that arise when the body is a flex container across many nested components.

  3. 3

    How would you design a theming system that can toggle the body between flex and block layouts without breaking existing components?

8+ years experience
  1. 1

    Your organization wants to standardize on display:flex on <body> for all new pages. What architectural risks do you see with legacy CSS, third‑party widgets, and accessibility, and how would you mitigate them?

  2. 2

    Describe a phased rollout plan for a global flex layout on <body> across multiple product teams while preserving backward compatibility.

  3. 3

    What long‑term maintenance strategies would you put in place to prevent layout regressions when the body is a flex container?

Follow-up Questions

  • What default flex properties would you need to override for a typical header‑main‑footer layout?
  • How does making the body a flex container impact scrolling on mobile browsers?
  • If a third‑party widget stops working after you set body to flex, what would you check first?