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.
By default, most replaced elements behave like inline-block, allowing width and height to be set while flowing inline with text.
display: block makes replaced elements start on a new line and take up the full width of their container (unless width is specified).
display: inline keeps replaced elements in the text flow, but height and width may be ignored depending on the element and browser.
display: inline-block allows replaced elements to remain inline while respecting width and height.
Replaced elements respect margin and padding differently depending on the display value and the browser’s layout rules.
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.
Use inline-block for replaced elements when you need them inline but still want control over width and height.
Use block when you want replaced elements to occupy their own line and control layout structure.
Test across browsers, as some replaced elements may render slightly differently depending on default styles.
You need to hide an <img> but keep the space it occupies for layout purposes. Which display value would you choose and why?
If you set display:block on an <input type='text'> inside a form, what visual changes do you expect compared to the default styling?
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.
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?
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.
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?
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.
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?
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.
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?