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

How can you make text and icons align properly using display values?

Aligning Text and Icons Using CSS Display

The CSS display property is essential for aligning text and icons. By choosing the right display value for the container and its children, you can achieve proper horizontal and vertical alignment.

Common Approaches
  1. 1

    display: inline-flex – Allows elements to sit inline while providing flex alignment for children. Perfect for icons next to text without breaking line flow.

  2. 2

    display: flex – Makes a container a flex box. Use align-items: center to vertically align text and icons.

  3. 3

    display: inline-block – Lets elements flow inline while controlling vertical alignment using vertical-align.

  4. 4

    display: grid – Provides a two-dimensional layout for precise horizontal and vertical alignment of text and icons.

Example: Flex Alignment

Here, the icon and text are vertically centered using inline-flex and align-items: center. The gap property adds spacing between them.

Best Practices
  1. 1

    Use flex or inline-flex to align icons and text horizontally and vertically.

  2. 2

    Use align-items: center to vertically center elements in a flex container.

  3. 3

    Use gap for consistent spacing instead of individual margins.

  4. 4

    For more complex layouts, grid can precisely align multiple icons and text elements.

  5. 5

    Avoid mixing inline-block and flex in the same container to prevent misalignment.

Difficulty: 4/10
Topics: display:flex, inline-block, vertical alignment

Scenario Questions

0-2 years experience
  1. 1

    You have a button with an SVG icon and a label. How would you use CSS display properties to place the icon left of the text and keep them vertically centered?

  2. 2

    If you set the container to display:inline-block, what effect does that have on the alignment of an inline icon and its accompanying text?

  3. 3

    What happens when you use display:table-cell for the icon and the text elements, and when would that be useful?

2-5 years experience
  1. 1

    Our navigation bar mixes items with and without icons. After switching the container to display:flex, some icons appear misaligned in Chrome. How would you debug and fix the alignment?

  2. 2

    The design spec says the icon must be 24 px tall and the text baseline should line up with the icon’s vertical center. Which display value and CSS properties would you choose, and why?

  3. 3

    Why might using display:inline-block on the icon introduce extra whitespace, and how would you eliminate that whitespace?

5-8 years experience
  1. 1

    You’re leading a redesign of a shared component library that includes buttons, inputs, and cards with icons. How would you standardize alignment across the library using display values while supporting legacy browsers and theming?

  2. 2

    A performance audit shows that using display:flex on many nested components adds layout thrashing on mobile. What trade‑offs would you consider, and how might you restructure the CSS to keep alignment correct but reduce reflow?

  3. 3

    When integrating a third‑party icon font, the icons appear offset from the text in some RTL locales. How would you adjust the display strategy to handle LTR/RTL and maintain pixel‑perfect alignment?

8+ years experience
  1. 1

    Our monolithic app has thousands of hard‑coded tables and inline icons. What architectural approach would you take to replace those display:inline/table hacks with a consistent flex‑based alignment strategy, and how would you roll it out without breaking existing pages?

  2. 2

    How would you design a CSS‑in‑JS theming solution that enforces correct icon‑text alignment across multiple product teams while still allowing custom overrides of display values?

  3. 3

    If we need to support both legacy IE11 and a new React Native Web build, how would you reconcile differing display capabilities to ensure icons and text stay aligned across platforms?

Follow-up Questions

  • Can you show the exact CSS you would write for that layout?
  • What edge cases could cause the alignment to break?
  • How would you verify the solution works across different browsers and devices?