FSM Full Stack Masterclass
Platform under construction
CSS course badge

Box Model

Intermediate

Padding

Padding is inside spacing. It creates comfort between content and the visible edge of a component.

.button {
  padding-block: .75rem;
  padding-inline: 1.25rem;
}

Box Model

Padding makes components feel usable.

Padding lives between content and border. It is the reason a button feels clickable, a card feels premium and text does not crash into the edge of its container.

Unlike margin, padding belongs to the component itself. If the component moves, its padding moves with it.

Good padding often uses a spacing scale and responsive values. It should support readability, touch comfort and visual hierarchy.

Inner space

Padding keeps content away from the component edge.

Touch comfort

Buttons and links need enough padding to feel clickable.

Responsive padding

clamp() can make padding adapt without many breakpoints.

Background area

Padding increases the visible background area of a box.

Visual model

See the box before you change the CSS.

Layout debugging becomes much easier when you can point to the exact part of the box that creates the visual result: inner space, outer space, edge, size or overflow behavior.

Button comfort

Inline and block padding create a real click target.

Card breathing room

Text needs space around it to feel intentional.

Section inset

Page sections need padding so content does not touch screen edges.

Examples

Professional spacing is deliberate, not decorative guesswork.

Component-owned comfort

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  padding-inline: 1.25rem;
}

Tiny hit area

.button {
  padding: 2px 4px;
  line-height: 1;
  font-size: 12px;
}

Rules that matter

Make every spacing and sizing decision explainable.

Box model CSS should make the interface easier to reason about. When a value cannot be explained, it usually becomes a future layout bug.

Use padding for inner comfort

If text touches an edge, padding is probably missing.

Protect touch targets

Interactive controls need enough height and width to be usable.

Use logical padding

padding-block and padding-inline make intent clearer.

Use a scale

Repeated spacing values make components feel connected.

Let padding respond

clamp() helps padding feel right on mobile and desktop.

Remember box-sizing

Padding can affect final size unless border-box is in use.

Production thinking

The box model is where visual polish becomes maintainable CSS.

Why does this matter?

Padding is one of the quickest ways to separate cheap-looking UI from polished UI. It controls comfort.

Accessibility

Adequate padding helps users tap controls, read labels and see focus states.

Production note

Component padding should be deliberate and reusable. Avoid random one-off padding that only works for one label.

SEO note

Comfortable reading and clicking improves user experience, especially on mobile search traffic.

Live code lab

Change the CSS and watch the interface respond.

The preview runs in an isolated iframe. Links and forms stay inside the practice area, so you can experiment without leaving the lesson.

Mini assignment

Try this now.

  • Reduce padding-inline to 6px and describe the feeling.
  • Increase padding-block and notice the button height.
  • Use clamp() for padding-inline and keep the button responsive.

Practice assignment

Do this before moving to the next lesson.

  1. Create one button and one card.
  2. Set padding-block and padding-inline separately.
  3. Check whether the component still works with a longer label.

Try it yourself

Tune a button with padding

Live preview

Self-check

Before you continue, prove that you understand Padding.

Intermediate

Answer these questions before moving on. If the answer is vague, change the lab CSS and inspect the box again.

  1. Can you explain padding as inside spacing?
  2. Can you choose padding for a button without making it cramped?
  3. Can you explain how padding changes the visible background area?
  4. Can you combine padding with min-height for touch targets?
  5. Can you use logical padding properties?

Senior audit upgrade

Logical padding prepares layouts for more writing modes.

padding-left and padding-right work, but padding-inline and padding-block describe direction by writing flow instead of physical side.

padding-inline

Controls start and end inline space, useful for LTR and RTL.

padding-block

Controls top and bottom in horizontal writing modes.

Component comfort

Use logical properties for components that may need international layouts later.