Tailwind CSS 4.1 Three Column Full Screen Layout
To achieve a three-column layout that fills the entire page height, we need to ensure both the outer container and each column have 100% height. In Tailwind CSS 4.1, follow these steps:
- Set the root elements (
html,body) toheight: 100%to allow subsequent elements to expand based on viewport height. - Use flexbox layout with the outer container (flex container) set to viewport height (
h-screen). - Configure three flex columns: fixed-width left/right columns, a fluid center column, and automatic height stretching (default
align-items: stretchensures equal height).
Core Code:
<!DOCTYPE html>
<html lang="en" class="h-full">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Full Height Three Columns</title>
<script src="https://cdn.tailwindcss.com/4.1.0"></script>
</head>
<body class="h-full">
<!-- Outer flex container with viewport height -->
<div class="flex h-screen">
<!-- Left fixed column -->
<div class="w-64 bg-gray-200 shrink-0">
Fixed width (256px)
</div>
<!-- Fluid center column -->
<div class="flex-1 bg-gray-300">
Fluid width
</div>
<!-- Right fixed column -->
<div class="w-64 bg-gray-200 shrink-0">
Fixed width (256px)
</div>
</div>
</body>
</html>
Implementation Principles:
- Set root elements to 100% height:
h-fullclass (equivalent toheight: 100%) makes the body fill the viewport height. - Outer container settings:
flex: Enables flexbox layouth-screen: Sets container height to viewport height (100vh)
- Column height behavior:
Flexbox's defaultalign-items: stretchautomatically expands column heights to match the container's height (full screen). No manual height required. - Fixed-width columns:
w-64: Fixed width of 256pxshrink-0: Prevents column shrinkage when space is limited
- Fluid center column:
flex-1: Occupies all remaining available space
Important Notes:
- If content exceeds a column's height:
Columns will expand (due toalign-items: stretch), causing scrollbars. For internal scrolling, addoverflow-autoto a nested container within the column. - For non-fullscreen layouts:
Ensure the parent container has explicit height, then set the layout container toflex h-fullto inherit the parent's height.