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

How do replaced elements (like <img> or <input>) behave with different display values?

Behavior of Replaced Elements with Different Display Values in CSS

Replaced elements, such as <img>, <input>, <textarea>, <video>, and <iframe>, have intrinsic dimensions and content that are replaced by external sources or browser-defined rendering. Their behavior with display depends on the CSS property applied.

Key Points
  1. 1

    By default, most replaced elements behave like inline-block, allowing width and height to be set while flowing inline with text.

  2. 2

    display: block makes replaced elements start on a new line and take up the full width of their container (unless width is specified).

  3. 3

    display: inline keeps replaced elements in the text flow, but height and width may be ignored depending on the element and browser.

  4. 4

    display: inline-block allows replaced elements to remain inline while respecting width and height.

  5. 5

    Replaced elements respect margin and padding differently depending on the display value and the browser’s layout rules.

Example: Replaced Elements with Different Display

In this example, the first image flows inline with text, the second image appears on its own line as a block, and the input remains inline but respects its specified width.

Best Practices
  1. 1

    Use inline-block for replaced elements when you need them inline but still want control over width and height.

  2. 2

    Use block when you want replaced elements to occupy their own line and control layout structure.

  3. 3

    Test across browsers, as some replaced elements may render slightly differently depending on default styles.

Difficulty: 5/10
Topics: replaced elements, display property, layout behavior

Scenario Questions

0-2 years experience
  1. 1

    You need to hide an <img> but keep the space it occupies for layout purposes. Which display value would you choose and why?

  2. 2

    If you set display:block on an <input type='text'> inside a form, what visual changes do you expect compared to the default styling?

2-5 years experience
  1. 1

    A recent CSS change set all form inputs to display:inline-block and now the fields are wrapping oddly on small screens. Explain why this might happen and how you'd fix it.

  2. 2

    You added display:none to an <img> inside a flex container and the whole container collapsed. Why does that happen, and what alternative display setting could keep the layout while hiding the image?

5-8 years experience
  1. 1

    Your design system uses custom button components built from <input type='button'>. Discuss the trade‑offs of using display:inline-block versus display:block for these components across responsive breakpoints.

  2. 2

    In a navigation bar that uses flexbox, you need icons (<svg> or <img>) to align vertically with text. How does the display value of these replaced elements affect alignment, and what CSS techniques would you apply?

  3. 3

    A data‑heavy table contains hundreds of <input> elements. Changing their display property impacts rendering performance. Explain how browsers handle replaced elements with different display values and any performance considerations.

8+ years experience
  1. 1

    Your organization is migrating a legacy UI that relies on inline <img> elements inside tables to a modern component framework. How would you refactor the display handling of replaced elements to avoid layout regressions across many pages?

  2. 2

    The design team wants all icons to be <img> with display:inline-block so they can use CSS sprites. Discuss the long‑term maintenance implications of this decision and alternative approaches (e.g., background‑image, <svg>, CSS mask) regarding accessibility and theming.

  3. 3

    When building a design‑token system, you need to define default display values for replaced elements. How would you structure these tokens to cover edge cases like form controls in grid layouts, and what guidelines would you set for future developers?

Follow-up Questions

  • What edge cases would you watch for when changing the display of a replaced element?
  • How would you verify that your change didn't break existing layouts?
  • Can you describe how vertical‑align works differently for inline versus inline‑block replaced elements?