Display & Centering: Center Inline Content
Solution idea
text-align affects the inline formatting context, so it’s the simplest way to center inline content without changing document flow.
Public interview reports
These public, self-reported interview accounts informed this practice version. The exercise is modelled on reported rounds, not copied from them, and the reports are not verified official questions or endorsements.
- GoodJob: Shopee frontend engineer written test and panels, Taipei, January 2021
The 90-minute written test asked for three ways to centre horizontally and vertically, the specificity rules and how to manage CSS at scale; a 2020 campus round asked the centring question too. This drill is a practice version, not the wording.
Reported in a public Shopee interview account. Shopee frontend interview questions
Solution
Overview
text-align affects the inline formatting context, so it’s the simplest way to center inline content without changing document flow.
Approach — text-align Center + Inline-Block Chips
Add that inline-block items respect line-height, so you can adjust vertical alignment with line-height or vertical-align if needed. If the design is sensitive to whitespace gaps, remove them with HTML formatting or font-size: 0 on the parent.
<div class='box'>
<h2>
Centered Content
</h2>
<p class='chips'>
<span class='tag'>
HTML
</span>
<span class='tag'>
CSS
</span>
<span class='tag'>
UI
</span>
</p>
</div>.box {
background: #222;
color: #fff;
padding: 20px;
border: 1px solid #444;
border-radius: 10px;
max-width: 600px;
margin: 0 auto;
}
.chips {
text-align: center;
margin-top: 12px;
}
.tag {
display: inline-block;
padding: 8px 12px;
border-radius: 6px;
background: #e63946;
color: #fff;
margin-right: 8px;
font-weight: 600;
letter-spacing: 0.5px;
}
.tag:last-child {
margin-right: 0;
}Notes & Pitfalls
Only inline-level content is centered by text-align. Blocks ignore it unless they are inline or inline-block.Forgetting to remove the last chip’s right margin causes visual imbalance.
Use inline-blockfor chips to keep a single line while allowing padding and border radius.text-align: centeron the wrapper is a simple, widely supported centering method for inline content.
Resources
Similar questions
Guides
Preparing for interviews? Use Frontend Coding Challenges first, then move into a concrete Study Plan before targeted Company Prep.
Built in public
The code behind FrontendAtlas lives on GitHub. A star helps other frontend engineers find it.