Skip to main content
Frontend is a free bonus on CodeMentor AI β€” the main product is Python. Register to save your progress and unlock all 290 Frontend lessons + 1,000+ Python lessons.Sign up β€” free
← 🎨 CSS as a design systemΒ·Module B1 Β· Lesson 8
TaskThree spans inside a paragraph. Make the .chip class display: inline-block with padding 4px 10px, background #e0e7ff, border-radius 999px, color #3730a3. These chips should be visually distinct pills inside the text.

display: block, inline, inline-block

75 XP7 minFREE
Theory

In 2026 β€” don't reach for inline-block to lay things out

If you arrived from an older tutorial, you may have learned that inline-block is how you make cards sit in a row. In modern CSS that's wrong: flex / grid (next module) own multi-item layout. inline-block is now only useful for *inline pieces inside text* β€” chips, badges, the occasional pill-button-inside-paragraph. Keep this lesson in mind for those β€” and only those β€” situations.

The 3 oldest display values

.thing { display: block; }         /* full-width, stacks vertically */
.thing { display: inline; }        /* sits in text flow, IGNORES width/height */
.thing { display: inline-block; }  /* flows like inline, but accepts width/height/padding */

What each does

DisplayWidth defaultWidth settable?Height settable?Wraps with text
block100% of parentyesyesno (always new line)
inlinecontentNONOyes
inline-blockcontentyesyesyes

<div>, <p>, <h1>, <section> are block by default. <span>, <a>, <strong>, <em> are inline by default.

When to use inline-block

The classic case: a "button" inside a paragraph that needs padding/width but should sit inline:

<p>Click here: <a class="btn" href="#">Sign up</a> to continue.</p>
.btn {
  display: inline-block;
  padding: 8px 16px;
  background: #3B82F6;
  color: white;
}

If .btn were just display: inline (its default), the padding would render but the background would only cover the text-line height β€” looks broken. inline-block makes the padding apply to the box properly.

Modern alternatives

  • For LAYOUT (rows of cards): use flexbox or grid (next module). Don't use inline-block for layout in 2026.
  • For inline buttons/badges/chips: inline-block is still the right call.
2 tabs
Live preview
← PreviousNext lesson β†’

Get one Python or web tip a day β€” by email

Short, hand-written, no spam. Unsubscribe in one click.