liveBook · Manning

Padding

As explained in Tiny CSS Projects

A CSS property that sets the space between an element's content and its border on each side.

Padding gives content breathing room inside an element, between the content and its edge or border. On a card, it keeps text from running against the sides; on a bordered date heading, it separates the text from the lines. Unlike margin, padding adds space inside the element rather than between neighboring elements. section 6.7 section 8.3.4 section 4.1.5

Use the padding shorthand to set several sides in one declaration:

  • `padding: 10px` sets all four sides to 10px. section 1.7.1
  • `padding: 25px 15px` sets top and bottom to 25px, then right and left to 15px. section 1.7.1 section 9.2.2
  • `padding: 0 24px 24px` sets the top to 0, both sides to 24px, and the bottom to 24px. Four values run clockwise: top, right, bottom, left. section 1.7.1 section 6.7

Keep a card’s content away from its edges

Start with `.card { padding: 0 24px 24px; }`. The side padding accommodates longer names, and the bottom padding lifts links away from the card’s lower edge. Leaving the top at zero avoids pushing down the image. If the top alone needs space—as it does above a strip on the back of a credit-card design—use `padding-top: 30px`. section 6.7 section 9.2.3

Choose the element that needs the space. Replacing a card header’s default margin with padding creates space inside the card; a separate margin on the card preserves the gap between cards. Browser defaults can also work against a design: a fieldset’s padding can be reset with `padding: 0`. For an inline link styled like a button, `display: inline-block` lets its padding affect the element’s height. section 8.3.4 section 10.2 section 5.4.2

Figure 9.7 Card with added padding and box model diagram

Compare the padded card with its box-model diagram: with `box-sizing: border-box`, adding padding reduces the room available to content without increasing the card face’s dimensions. section 9.2.2

How Tiny CSS Projects covers it

How deep it goes
Explains side-specific shorthand, contrasts padding with margin, and shows how border-box changes the space available to content.
Examples
Shows padded profile and credit-card faces, checkout-card headers, form controls, and call-to-action links.
What it assumes
Builds shorthand from individual side declarations while using existing HTML elements and CSS rules in visual projects.
What you can do after
Apply it through CSS shorthand or side-specific properties to space content, preserve intended layouts, and reset unwanted browser defaults.
How it connects
Connects padding to margin, margin collapse, the box model, box-sizing, and inline versus inline-block display.

Also explained in

Compare how 19 books explain padding →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.