inline-block combines inline flow with block-like sizing, useful for chips, tags, and compact UI elements.
Key behavior
- Sits inline with text like inline elements.
- Accepts width/height/padding like block elements.
- Whitespace between elements in HTML affects gaps.
Pitfall
Unexpected horizontal gaps come from literal whitespace/newlines between inline-block elements.
Important interview questions and answers
- Q: When pick inline-block over flex?
A: Small independent elements where full flex container behavior is unnecessary. - Q: Why do inline-block chips have mystery gaps?
A: HTML whitespace rendering between inline-level boxes. - Q: Better default for component groups?
A: Flex with gap is usually cleaner.
Pitfall: Check cascade order—author stylesheet loses to inline styles and !important surprises.