liveBook · Manning

Auto

As explained in Web Design Playground, Second Edition

The CSS auto value lets the browser determine a property's value according to its layout rules and available content.

The CSS auto value lets the browser choose a property's size or spacing instead of forcing a fixed measurement. Think of it as saying, “You decide—but use the layout rules and available content.” section 9.2 section 13.3

Common jobs for auto include:

  • Set height automatically so an element grows naturally to contain its content. section 9.2
  • Set an image's height to auto so its original aspect ratio remains intact when its width changes. section 14.7
  • Use horizontal margins set to auto to center an element when its width is defined. section 9.6
  • Let grid columns or rows take sizes determined by the other track values and available layout space. section 13.3

Keep an image from getting squashed

img { max-width: 100%; height: auto; } As the parent container becomes narrower, the image scales down while the browser calculates a matching height. No pancake-shaped images required. section 14.7

img {
    max-width: 100%;
    height: auto;
}

Inspect the compact fluid-image rule that combines max-width: 100% with height: auto. section 14.7

How Web Design Playground, Second Edition covers it

How deep it goes
Explains practical sizing and spacing effects with examples, but does not descend into browser layout internals.
Examples
Demonstrates fluid images, centered elements, automatically sized grid tracks, and content-driven block heights.
What it assumes
Assumes familiarity with CSS declarations and measurement units while clarifying block elements, containers, and browser defaults.
What you can do after
Apply it via CSS to create fluid images, center fixed-width elements, and allow layouts to adapt to content and available space.
How it connects
Connects auto with width, height, margins, grid layout, responsive web design, and aspect ratio.

Also explained in

Compare how 4 books explain auto →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Design Playground, Second Edition. The section links point to the parts of the book it draws on.