Course contentsShow
← Web Development
Lesson 617 of 2,98211. Utility-First CSS with TailwindFree lesson

Layout Utilities: Display, Position, and Float

Learn Tailwind's display (block, flex, grid, hidden) and positioning (relative, absolute, fixed, sticky) classes.

Layout Utilities: Display, Position, and Float

You'll learn how Tailwind's display, positioning, and float classes let you control element layout with single, descriptive class names.

What Are Layout Utilities?

Instead of writing custom CSS like display: flex; or position: absolute;, Tailwind provides ready-made classes that apply these fundamental layout properties. You simply add the class to your HTML element, and the styling happens instantly.

Display Classes

These control how an element renders:

  • block — Element takes full width, stacks vertically
  • inline-block — Element flows with text but accepts width/height
  • flex — Enables flexbox layout
  • grid — Enables grid layout
  • hidden — Hides the element completely

Example: <div class="flex"> turns a div into a flex container without writing a single line of CSS.

Position Classes

These control where an element sits:

  • static — Default flow (no special positioning)
  • relative — Positioned relative to its normal position
  • absolute — Removed from flow, positioned relative to nearest positioned ancestor
  • fixed — Stays in place during scrolling
  • sticky — Switches between relative and fixed based on scroll position

Think of it like layers: absolute and fixed elements "float" above the normal document flow, while relative stays grounded but can be nudged.

Float Classes

Though less common in modern layouts, Tailwind includes:

  • float-left — Element floats to the left
  • float-right — Element floats to the right
  • float-none — Removes floating

These were traditionally used for wrapping text around images.

Why This Matters

Instead of context-switching to CSS files, you apply layout behavior directly in your markup. <header class="sticky"> immediately tells you and other developers the element's positioning behavior.

Key Takeaway: Tailwind's layout utilities replace verbose CSS declarations with intuitive class names, letting you build responsive layouts without leaving your HTML.