Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active May 21, 2025 20:45
Show Gist options
  • Save devinschumacher/95ed32c383a8cc91c0e80e5e502b6afa to your computer and use it in GitHub Desktop.
Save devinschumacher/95ed32c383a8cc91c0e80e5e502b6afa to your computer and use it in GitHub Desktop.
Common Webpage Layouts With TailwindCSS Using CSS Grid & Flex box (w/ Code Examples)
title tags
Common Webpage Layouts With TailwindCSS Using CSS Grid & Flex box (w/ Code Examples)
css
frontend
tailwind
css grid
css flex box

Creating Common Webpage Layouts With TailwindCSS Using CSS Grid & CSS Flex box (w/ Code Examples)

  • CSS Grid: for the main page layout (header, main content, sidebar, footer)
  • CSS Flexbox: for smaller components within those grid areas (like navigation menus, lists of items, or aligning content within a section)

Click the image below to watch the video πŸ‘‡

CSS Grid

  • CSS Grid Container: The parent element that defines the grid layout using rows, columns, and gaps. It controls how child elements (grid items) are arranged.
  • CSS Grid Item: A child element of a grid container. It is placed within the grid and can span across rows or columns based on the grid's setup.
Grid Container Properties Grid Item Properties
display grid-column-start
grid-template-columns grid-column-end
grid-template-rows grid-row-start
grid-template-areas grid-row-end
grid-template grid-column
grid-column-gap grid-row
grid-row-gap grid-area
grid-gap justify-self
justify-items align-self
align-items place-self
place-items order
justify-content z-index
align-content
place-content
grid-auto-columns
grid-auto-rows
grid-auto-flow
grid

CSS Flexbox

  • CSS Flexbox Container: The parent element that uses flexbox to control the layout of its child elements. It defines the flex behavior, such as direction, wrapping, and alignment.
  • CSS Flexbox Item: A direct child of a flexbox container that follows the container's flex layout.
Flexbox Container Properties Flexbox Item Properties
display order
flex-direction flex-grow
flex-wrap flex-shrink
flex-flow flex-basis
justify-content flex
align-items align-self
align-content
gap
row-gap
column-gap

Important

If you design with Tailwind, check out SERP Blocks - it's the largest component library built on Tailwind & Shadcn


serp-blocks


Fundamental/Common Responsive Layouts for Websites/UIs

  1. One-Column Layout: Header/Footer + Content
  2. Two-Column Layout: Header/Footer + Content + Sidebar(Left|Right)
  3. Three-Column Layout: Header/Footer + Content + Sidebar (Left+Right)
  4. Dashboard Layout: Header/Footer + Content + Left Sidebar(Collapsible)

One-Column Layout

One-Column Layout: Header/Footer + Content

  • A simple, stacked layout ideal for mobile devices and narrow screens
  • Content flows vertically in a single column
image

TailwindCSS Implementation: flex

<div class="flex flex-col min-h-screen">
  <header class="bg-blue-500 p-4">Header</header>
  <main class="flex-grow p-4">Content</main>
  <footer class="bg-gray-300 p-4">Footer</footer>
</div>

πŸ”— Click here to see it πŸ”— Click here to see it in HTML+ CSS

Two-Column (Right Sidebar)

Two-Column Layout: Header/Footer + Content + Sidebar(Right)

  • Common for displaying content alongside a sidebar
  • Typically switches to a single column on smaller screens
image

TailwindCSS Implementation: flex

<div class="flex flex-col min-h-screen">
  <header class="bg-blue-500 p-4">Header</header>
  <div class="flex flex-col md:flex-row flex-grow">
    <main class="flex-grow p-4 order-2 md:order-1">Content</main>
    <aside class="w-full md:w-64 p-4 bg-gray-200 order-1 md:order-2">Sidebar</aside>
  </div>
  <footer class="bg-gray-300 p-4">Footer</footer>
</div>

πŸ”— Click here to see it πŸ”— Click here to see it in HTML+ CSS

Two-Column (Left Sidebar)

Two-Column Layout: Header/Footer + Content + Sidebar(Left)

  • Common for displaying content alongside a sidebar
  • Typically switches to a single column on smaller screens

TailwindCSS Implementation: flex

<div class="flex flex-col min-h-screen">
  <header class="bg-blue-500 p-4">Header</header>
  <div class="flex flex-row flex-grow">
    <aside class="w-64 p-4 bg-gray-200 hidden sm:block">Sidebar</aside>
    <main class="flex-grow p-4">Content</main>
  </div>
  <footer class="bg-gray-300 p-4">Footer</footer>
</div>

πŸ”— Click here to see it

Three-Column Layout

Three-Column Layout: Header/Footer + Content + Sidebar (Left+Right)

  • Common for displaying documentation

TailwindCSS Implementation: grid

<div class="grid min-h-screen grid-cols-1 grid-rows-[auto,1fr,auto] md:grid-cols-[200px,1fr] lg:grid-cols-[200px,1fr,200px]">
  <header class="col-span-full bg-blue-500 p-4">Header</header>
  <aside class="hidden bg-gray-200 p-4 md:row-start-2 md:block">Left Sidebar</aside>
  <main class="row-start-2 bg-white p-4 md:col-start-2">Content</main>
  <aside class="hidden bg-gray-200 p-4 lg:row-start-2 lg:block">Right Sidebar</aside>
  <footer class="col-span-full bg-gray-300 p-4">Footer</footer>
</div>

πŸ”— Click here to see it

Dashboard Layout

Header/Footer + Content + Left Sidebar(Collapsible)

image
  • Consists of a header/footer + main content area + collapsible left sidebar (for addl. naviation)
  • Ideal for admin panels, data dashboards, and complex web applications
  • Responsive design allows the sidebar to collapse on smaller screens
  • Can be implemented effectively with CSS Grid

Grid Template Representation

display: grid;
grid-template-areas:
'nav header header'
'nav content sidebar'
'nav footer footer'

βœ’οΈ Click here to see it on codepen (Vanilla HTML/CSS)

TailwindCSS Implementation: ?

<!-- need an example of this one -->

πŸ”— Click here to see it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment