10 Modern CSS Layouts for Websites – 2026
10 Modern CSS Layouts for Websites – 2026

Frameworks like Tailwind and Bootstrap ship with thousands of classes you’ll never use. Your browser still parses every line. That’s dead weight, tanking your PageSpeed score before you write one component.
Modern CSS doesn’t need that. Grid, Flexbox, and Container Queries handle any layout natively. Zero dependencies. Zero bloat. Hundred percent scores. Your stylesheet stays lean and readable.
Layout Name | Use-Case | Primary Technique | Speed Impact |
|---|---|---|---|
Bento Grid | Portfolio/landing page tiles | CSS Grid with | No render-blocking; pure CSS |
Holy Grail SaaS Dashboard | Admin panels with sidebar + header | Grid + named template columns | Single reflow; no JS layout shifts |
Auto-Fit Product Card Grid | E-commerce/card listings |
| Responsive with zero media queries |
Core Layouts for High-Performance Pages
The Perfect Mobile-First Hero (Flexbox)
Flexbox was made for one-dimensional layouts. A hero section is exactly that, one column on mobile, two columns on wider screens. No hacks, no float clearing, no grid overkill.
flex-direction: column Stacks content naturally on small screens. One @media query flips it to row. That’s the entire layout. You get alignment control, gap spacing, and full responsiveness in under 15 lines.
Want to experiment with clean, fast code? Try this zero-latency Live Code Tester.
<!-- HTML -->
<section class="hero">
<div class="hero__content">
<h1>Build fast. Ship lean.</h1>
<p>Modern CSS layouts without the framework weight.</p>
<a href="#" class="btn">Get Started</a>
</div>
<div class="hero__image">
<img src="hero.webp" alt="App preview" width="600" height="400" />
</div>
</section>
/* CSS */
.hero {
display: flex;
flex-direction: column;
align-items: center;
gap: 2rem;
padding: 4rem 1.5rem;
}
.hero__content {
flex: 1;
max-width: 540px;
}
.hero__image {
flex: 1;
width: 100%;
}
.hero__image img {
width: 100%;
height: auto;
display: block;
border-radius: 0.75rem;
}
@media (min-width: 768px) {
.hero {
flex-direction: row;
padding: 6rem 4rem;
}
}
The Bento Grid Showcase (CSS Grid)
Bento layouts are everywhere in 2026. Apple popularized them. Every SaaS landing page runs one now. The trick is grid-template-areas It maps your layout visually, right inside the CSS.
You name each zone. No wrapper divs, no nested containers, no extra markup. Each card snaps into its named area. Resize the viewport, and the grid adapts without touching a single HTML attribute.
<!-- HTML -->
<section class="bento">
<div class="bento__card bento__card--hero">
<h2>Ship in days, not weeks.</h2>
</div>
<div class="bento__card bento__card--stat">
<span class="stat">99%</span>
<p>PageSpeed score</p>
</div>
<div class="bento__card bento__card--feature">
<h3>Zero dependencies</h3>
<p>Pure CSS. No build step.</p>
</div>
<div class="bento__card bento__card--visual">
<img src="preview.webp" alt="Code preview" width="400" height="300" />
</div>
</section>
/* CSS */
.bento {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-template-rows: auto;
grid-template-areas:
"hero hero stat"
"hero hero feature"
"visual visual feature";
gap: 1rem;
padding: 2rem;
}
.bento__card--hero { grid-area: hero; }
.bento__card--stat { grid-area: stat; }
.bento__card--feature { grid-area: feature; }
.bento__card--visual { grid-area: visual; }
.bento__card {
background: #f9f9f9;
border-radius: 1rem;
padding: 2rem;
border: 1px solid #e5e5e5;
}
.stat {
font-size: 3rem;
font-weight: 700;
display: block;
}
.bento__card--visual img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 0.5rem;
display: block;
}
@media (max-width: 640px) {
.bento {
grid-template-columns: 1fr;
grid-template-areas:
"hero"
"stat"
"feature"
"visual";
}
}
The Auto-Fit Product/Service Card Grid (Grid)
repeat(auto-fit, minmax()) is one of the most underused tools in CSS. It builds a fully responsive card grid. No media queries. No JavaScript. The browser handles column count automatically.
Set a minimum card width. The grid fills available space and wraps when columns can’t fit. Cards never stretch below your minimum. It works for three cards or three hundred. Same code.
<!-- HTML -->
<section class="card-grid">
<article class="card">
<img src="product-1.webp" alt="Product one" width="400" height="300" />
<div class="card__body">
<h3>Product Name</h3>
<p>Short description of what this product does.</p>
<a href="#" class="btn">View Details</a>
</div>
</article>
<article class="card">
<img src="product-2.webp" alt="Product two" width="400" height="300" />
<div class="card__body">
<h3>Product Name</h3>
<p>Short description of what this product does.</p>
<a href="#" class="btn">View Details</a>
</div>
</article>
<article class="card">
<img src="product-3.webp" alt="Product three" width="400" height="300" />
<div class="card__body">
<h3>Product Name</h3>
<p>Short description of what this product does.</p>
<a href="#" class="btn">View Details</a>
</div>
</article>
</section>
/* CSS */
.card-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
padding: 2rem;
}
.card {
background: #fff;
border: 1px solid #e5e5e5;
border-radius: 0.75rem;
overflow: hidden;
display: flex;
flex-direction: column;
}
.card img {
width: 100%;
height: 200px;
object-fit: cover;
display: block;
}
.card__body {
padding: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.75rem;
flex: 1;
}
.card__body .btn {
margin-top: auto;
display: inline-block;
padding: 0.6rem 1.2rem;
background: #111;
color: #fff;
text-decoration: none;
border-radius: 0.4rem;
font-size: 0.9rem;
}
Dynamic Page and App Layout Structures
The Holy Grail SaaS Dashboard (Grid Sidebar + Main Content)
Every SaaS app runs this layout. Fixed header, persistent sidebar, scrollable main area, optional right panel. Grid handles all four zones in one rule. No absolute positioning or JS involved.
The key is grid-template-areas. Each zone gets a name. Content fills its space without bleeding into others. The sidebar stays fixed while the main content scrolls independently. This is structural CSS doing real work.
<!-- HTML -->
<div class="dashboard">
<header class="dashboard__header">
<span class="logo">AppName</span>
<nav class="top-nav">
<a href="#">Notifications</a>
<a href="#">Account</a>
</nav>
</header>
<aside class="dashboard__sidebar">
<nav class="side-nav">
<a href="#">Overview</a>
<a href="#">Analytics</a>
<a href="#">Projects</a>
<a href="#">Settings</a>
</nav>
</aside>
<main class="dashboard__main">
<h1>Overview</h1>
<p>Main content goes here. Scrollable. Independent of sidebar.</p>
</main>
<aside class="dashboard__panel">
<h2>Activity</h2>
<p>Right panel for secondary context or widgets.</p>
</aside>
</div>
/* CSS */
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html, body {
height: 100%;
}
.dashboard {
display: grid;
height: 100vh;
grid-template-columns: 220px 1fr 260px;
grid-template-rows: 60px 1fr;
grid-template-areas:
"header header header"
"sidebar main panel";
}
.dashboard__header {
grid-area: header;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 1.5rem;
background: #fff;
border-bottom: 1px solid #e5e5e5;
position: sticky;
top: 0;
z-index: 10;
}
.dashboard__sidebar {
grid-area: sidebar;
background: #fafafa;
border-right: 1px solid #e5e5e5;
padding: 1.5rem 1rem;
overflow-y: auto;
}
.side-nav {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.side-nav a {
display: block;
padding: 0.6rem 0.75rem;
border-radius: 0.4rem;
text-decoration: none;
color: #444;
font-size: 0.9rem;
}
.side-nav a:hover {
background: #efefef;
color: #111;
}
.dashboard__main {
grid-area: main;
padding: 2rem;
overflow-y: auto;
}
.dashboard__panel {
grid-area: panel;
background: #fafafa;
border-left: 1px solid #e5e5e5;
padding: 1.5rem 1rem;
overflow-y: auto;
}
.top-nav {
display: flex;
gap: 1rem;
}
.top-nav a {
text-decoration: none;
color: #555;
font-size: 0.9rem;
}
/* Collapse to single column on mobile */
@media (max-width: 768px) {
.dashboard {
grid-template-columns: 1fr;
grid-template-rows: 60px auto 1fr auto;
grid-template-areas:
"header"
"sidebar"
"main"
"panel";
height: auto;
}
.dashboard__sidebar,
.dashboard__panel {
border: none;
border-bottom: 1px solid #e5e5e5;
}
}
The Split-Screen Landing Page (Flexbox)
Split-screen layouts work well for comparisons, before/after sections, or dual CTAs. On a desktop, two halves sit side by side at exactly 50% each. Neither panel compresses the other.
On mobile, that symmetric split would be unreadable. Each panel drops into a full-width block instead. One @media rule handles it. No additional wrappers or layout overrides needed.
<!-- HTML -->
<section class="split">
<div class="split__panel split__panel--left">
<div class="split__content">
<span class="eyebrow">For Teams</span>
<h2>Collaborate without the chaos.</h2>
<p>Built for teams that need structure without overhead.</p>
<a href="#" class="btn btn--light">Start Free Trial</a>
</div>
</div>
<div class="split__panel split__panel--right">
<div class="split__content">
<span class="eyebrow">For Solo Builders</span>
<h2>Ship faster on your own.</h2>
<p>Lightweight tools for developers who move fast.</p>
<a href="#" class="btn btn--dark">See Solo Plan</a>
</div>
</div>
</section>
/* CSS */
.split {
display: flex;
min-height: 100vh;
}
.split__panel {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
padding: 4rem 2rem;
}
.split__panel--left {
background: #111;
color: #fff;
}
.split__panel--right {
background: #f4f4f4;
color: #111;
}
.split__content {
max-width: 420px;
display: flex;
flex-direction: column;
gap: 1.25rem;
}
.eyebrow {
font-size: 0.75rem;
font-weight: 600;
letter-spacing: 0.1em;
text-transform: uppercase;
opacity: 0.6;
}
.split__content h2 {
font-size: clamp(1.5rem, 3vw, 2.25rem);
line-height: 1.2;
}
.split__content p {
font-size: 1rem;
line-height: 1.6;
opacity: 0.8;
}
.btn {
display: inline-block;
padding: 0.75rem 1.5rem;
border-radius: 0.4rem;
font-size: 0.9rem;
text-decoration: none;
width: fit-content;
}
.btn--light {
background: #fff;
color: #111;
}
.btn--dark {
background: #111;
color: #fff;
}
/* Stack on mobile */
@media (max-width: 640px) {
.split {
flex-direction: column;
min-height: auto;
}
.split__panel {
padding: 3rem 1.5rem;
}
}
The Dynamic Pricing Table (Flexbox Layout)
Pricing tables break when card heights differ. One card has three features, another has seven. Without proper flexbox setup, the row looks ragged and untrustworthy. Buyers notice misaligned layouts.
align-items: stretch makes every card fill the row height equally. Push the CTA button to the bottom using margin-top: auto the flex child. Cards always align, regardless of content length.
<!-- HTML -->
<section class="pricing">
<h2 class="pricing__title">Simple Pricing</h2>
<div class="pricing__grid">
<div class="pricing__card">
<div class="pricing__top">
<h3>Starter</h3>
<p class="price"><span>$0</span> / month</p>
<p class="desc">Good for indie projects and learning.</p>
</div>
<ul class="features">
<li>3 projects</li>
<li>1GB storage</li>
<li>Community support</li>
</ul>
<a href="#" class="btn btn--outline">Get Started Free</a>
</div>
<div class="pricing__card pricing__card--featured">
<div class="pricing__top">
<span class="badge">Most Popular</span>
<h3>Pro</h3>
<p class="price"><span>$29</span> / month</p>
<p class="desc">For professionals and growing teams.</p>
</div>
<ul class="features">
<li>Unlimited projects</li>
<li>50GB storage</li>
<li>Priority support</li>
<li>Custom domains</li>
<li>Analytics dashboard</li>
</ul>
<a href="#" class="btn btn--solid">Start Pro Trial</a>
</div>
<div class="pricing__card">
<div class="pricing__top">
<h3>Enterprise</h3>
<p class="price"><span>$99</span> / month</p>
<p class="desc">For large teams with compliance needs.</p>
</div>
<ul class="features">
<li>Everything in Pro</li>
<li>500GB storage</li>
<li>Dedicated support</li>
<li>SSO & audit logs</li>
</ul>
<a href="#" class="btn btn--outline">Contact Sales</a>
</div>
</div>
</section>
/* CSS */
.pricing {
padding: 4rem 1.5rem;
text-align: center;
}
.pricing__title {
font-size: 2rem;
margin-bottom: 2.5rem;
}
.pricing__grid {
display: flex;
align-items: stretch;
gap: 1.25rem;
justify-content: center;
flex-wrap: wrap;
}
.pricing__card {
display: flex;
flex-direction: column;
background: #fff;
border: 1px solid #e5e5e5;
border-radius: 0.75rem;
padding: 2rem 1.5rem;
width: 280px;
text-align: left;
}
.pricing__card--featured {
border-color: #111;
box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}
.pricing__top {
margin-bottom: 1.5rem;
}
.badge {
display: inline-block;
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
background: #111;
color: #fff;
padding: 0.25rem 0.6rem;
border-radius: 999px;
margin-bottom: 0.75rem;
}
.pricing__card h3 {
font-size: 1.1rem;
font-weight: 600;
margin-bottom: 0.5rem;
}
.price {
font-size: 0.95rem;
color: #555;
margin-bottom: 0.5rem;
}
.price span {
font-size: 2rem;
font-weight: 700;
color: #111;
}
.desc {
font-size: 0.875rem;
color: #777;
}
.features {
list-style: none;
padding: 0;
margin: 0 0 1.5rem;
display: flex;
flex-direction: column;
gap: 0.6rem;
flex: 1;
}
.features li {
font-size: 0.875rem;
color: #444;
padding-left: 1.25rem;
position: relative;
}
.features li::before {
content: "✓";
position: absolute;
left: 0;
color: #111;
font-weight: 700;
}
/* Push CTA to bottom regardless of feature count */
.btn {
display: block;
text-align: center;
padding: 0.75rem 1rem;
border-radius: 0.4rem;
font-size: 0.9rem;
text-decoration: none;
margin-top: auto;
}
.btn--outline {
border: 1px solid #111;
color: #111;
background: transparent;
}
.btn--solid {
background: #111;
color: #fff;
border: 1px solid #111;
}
/* Stack on mobile */
@media (max-width: 640px) {
.pricing__grid {
flex-direction: column;
align-items: center;
}
.pricing__card {
width: 100%;
max-width: 360px;
}
}
Advanced Responsive Utilities
The Sticky Sidebar Blog Post Layout (Grid + Sticky)
Long-form blog posts need a reading layout that stays out of the way. Grid handles the column split cleanly. The sidebar tracks scroll position without JavaScript. One CSS property does it.
position: sticky keeps the sidebar anchored while the article scrolls past it. Set top to match your header height. Use align-self: start on the sidebar or sticky won’t activate. That detail breaks most implementations.
<!-- HTML -->
<div class="blog-layout">
<article class="blog-layout__post">
<h1>How to Build Fast Layouts with Pure CSS</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.</p>
<h2>Section One</h2>
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident.</p>
<h2>Section Two</h2>
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum. Curabitur pretium tincidunt lacus. Nulla gravida orci a odio nullam varius.</p>
<h2>Section Three</h2>
<p>Nullam varius, turpis molestie dictum semper, ex libero ullamcorper purus. Maecenas condimentum nunc nec elit auctor euismod. Sed interdum libero ut metus.</p>
</article>
<aside class="blog-layout__sidebar">
<div class="sidebar-widget">
<h3>Table of Contents</h3>
<nav>
<a href="#">Section One</a>
<a href="#">Section Two</a>
<a href="#">Section Three</a>
</nav>
</div>
<div class="sidebar-widget">
<h3>About the Author</h3>
<p>Solo developer. Writing about CSS, performance, and shipping things.</p>
</div>
</aside>
</div>
/* CSS */
.blog-layout {
display: grid;
grid-template-columns: 1fr 280px;
grid-template-areas: "post sidebar";
gap: 3rem;
max-width: 1100px;
margin: 0 auto;
padding: 3rem 1.5rem;
align-items: start;
}
.blog-layout__post {
grid-area: post;
max-width: 680px;
line-height: 1.8;
}
.blog-layout__post h1 {
font-size: clamp(1.6rem, 3vw, 2.25rem);
line-height: 1.2;
margin-bottom: 1.5rem;
}
.blog-layout__post h2 {
font-size: 1.3rem;
margin: 2rem 0 0.75rem;
}
.blog-layout__post p {
color: #444;
font-size: 1rem;
}
.blog-layout__sidebar {
grid-area: sidebar;
position: sticky;
top: 1.5rem; /* Adjust to match your fixed header height */
align-self: start; /* Critical — sticky fails without this */
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.sidebar-widget {
background: #f9f9f9;
border: 1px solid #e5e5e5;
border-radius: 0.6rem;
padding: 1.25rem;
}
.sidebar-widget h3 {
font-size: 0.85rem;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 0.06em;
margin-bottom: 0.75rem;
color: #111;
}
.sidebar-widget nav {
display: flex;
flex-direction: column;
gap: 0.4rem;
}
.sidebar-widget nav a {
font-size: 0.875rem;
color: #555;
text-decoration: none;
padding: 0.25rem 0;
border-bottom: 1px solid #efefef;
}
.sidebar-widget nav a:last-child {
border-bottom: none;
}
.sidebar-widget nav a:hover {
color: #111;
}
.sidebar-widget p {
font-size: 0.875rem;
color: #666;
line-height: 1.6;
}
/* Collapse sidebar below post on mobile */
@media (max-width: 768px) {
.blog-layout {
grid-template-columns: 1fr;
grid-template-areas:
"post"
"sidebar";
gap: 2rem;
}
.blog-layout__sidebar {
position: static;
}
}
Watch Video: Don’t miss out! Check out my latest YouTube video for in-depth insights and exciting content. Click here to watch ByteScript MZA now!
The Minimalist Footer Framework (Flexbox Row-Wrap)
Footer link columns collapse badly on narrow screens when built with floats or fixed-width grids. flex-wrap: wrap solves it. Each column becomes a flex child. They wrap naturally at your set minimum width.
You don’t control which row a column lands on. The browser does. That’s the point. Set flex: 1 1 180px per column. Four columns on desktop become two rows on tablet and one on mobile.
<!-- HTML -->
<footer class="footer">
<div class="footer__inner">
<div class="footer__brand">
<span class="footer__logo">YourBrand</span>
<p>Clean, fast websites without the framework overhead.</p>
</div>
<div class="footer__col">
<h4>Product</h4>
<ul>
<li><a href="#">Features</a></li>
<li><a href="#">Pricing</a></li>
<li><a href="#">Changelog</a></li>
<li><a href="#">Roadmap</a></li>
</ul>
</div>
<div class="footer__col">
<h4>Resources</h4>
<ul>
<li><a href="#">Documentation</a></li>
<li><a href="#">API Reference</a></li>
<li><a href="#">Tutorials</a></li>
<li><a href="#">Status</a></li>
</ul>
</div>
<div class="footer__col">
<h4>Company</h4>
<ul>
<li><a href="#">About</a></li>
<li><a href="#">Blog</a></li>
<li><a href="#">Careers</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
<div class="footer__bottom">
<p>© 2026 YourBrand. All rights reserved.</p>
<div class="footer__legal">
<a href="#">Privacy</a>
<a href="#">Terms</a>
<a href="#">Cookies</a>
</div>
</div>
</footer>
/* CSS */
.footer {
background: #111;
color: #ccc;
padding: 4rem 1.5rem 2rem;
}
.footer__inner {
display: flex;
flex-wrap: wrap;
gap: 2rem;
max-width: 1100px;
margin: 0 auto;
padding-bottom: 3rem;
border-bottom: 1px solid #2a2a2a;
}
.footer__brand {
flex: 1 1 220px;
display: flex;
flex-direction: column;
gap: 0.75rem;
}
.footer__logo {
font-size: 1.1rem;
font-weight: 700;
color: #fff;
}
.footer__brand p {
font-size: 0.875rem;
line-height: 1.6;
color: #888;
}
.footer__col {
flex: 1 1 160px; /* Each column wraps at 160px minimum */
}
.footer__col h4 {
font-size: 0.75rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #fff;
margin-bottom: 1rem;
}
.footer__col ul {
list-style: none;
padding: 0;
margin: 0;
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.footer__col ul a {
font-size: 0.875rem;
color: #888;
text-decoration: none;
transition: color 0.15s ease;
}
.footer__col ul a:hover {
color: #fff;
}
.footer__bottom {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: 1rem;
max-width: 1100px;
margin: 2rem auto 0;
}
.footer__bottom p {
font-size: 0.8rem;
color: #555;
}
.footer__legal {
display: flex;
gap: 1.25rem;
}
.footer__legal a {
font-size: 0.8rem;
color: #555;
text-decoration: none;
}
.footer__legal a:hover {
color: #fff;
}
The Container Query Card (Modern CSS)
Viewport-based media queries style components based on screen width. That’s the wrong signal. A card in a narrow sidebar needs different styling than the same card in a wide main column. Same viewport, different context.
Container queries fix this. Wrap the card in a container. Query that container’s width instead. The card responds to where it lives, not how big the screen is. Browser support is solid from 2023 onward.
<!-- HTML -->
<div class="card-container card-container--narrow">
<div class="cq-card">
<img src="product.webp" alt="Product image" width="400" height="300" />
<div class="cq-card__body">
<span class="cq-card__tag">New</span>
<h3>Product Title</h3>
<p>A short description that adapts based on the parent container width.</p>
<a href="#" class="cq-card__btn">View Product</a>
</div>
</div>
</div>
<!-- Same card, wider container context -->
<div class="card-container card-container--wide">
<div class="cq-card">
<img src="product.webp" alt="Product image" width="400" height="300" />
<div class="cq-card__body">
<span class="cq-card__tag">New</span>
<h3>Product Title</h3>
<p>A short description that adapts based on the parent container width.</p>
<a href="#" class="cq-card__btn">View Product</a>
</div>
</div>
</div>
/* CSS */
/* Step 1: Define the container */
.card-container {
container-type: inline-size;
container-name: card;
}
/* Demo widths — in production these come from your grid */
.card-container--narrow {
max-width: 280px;
}
.card-container--wide {
max-width: 680px;
}
/* Base card style — stacked layout (narrow default) */
.cq-card {
display: flex;
flex-direction: column;
border: 1px solid #e5e5e5;
border-radius: 0.75rem;
overflow: hidden;
background: #fff;
}
.cq-card img {
width: 100%;
height: 180px;
object-fit: cover;
display: block;
}
.cq-card__body {
padding: 1.25rem;
display: flex;
flex-direction: column;
gap: 0.6rem;
}
.cq-card__tag {
font-size: 0.7rem;
font-weight: 700;
letter-spacing: 0.08em;
text-transform: uppercase;
color: #777;
}
.cq-card__body h3 {
font-size: 1rem;
font-weight: 600;
color: #111;
}
.cq-card__body p {
font-size: 0.875rem;
color: #666;
line-height: 1.5;
}
.cq-card__btn {
display: inline-block;
padding: 0.5rem 1rem;
background: #111;
color: #fff;
text-decoration: none;
border-radius: 0.35rem;
font-size: 0.85rem;
width: fit-content;
margin-top: 0.25rem;
}
/* Step 2: Query the container, not the viewport */
@container card (min-width: 480px) {
.cq-card {
flex-direction: row; /* Switch to horizontal layout in wide containers */
align-items: stretch;
}
.cq-card img {
width: 240px;
height: auto;
flex-shrink: 0;
}
.cq-card__body {
padding: 1.75rem;
justify-content: center;
}
.cq-card__body h3 {
font-size: 1.2rem;
}
}
The Centered Empty-State / 404 Hero (Flexbox Center)
Empty states and 404 pages get treated as afterthoughts. They shouldn’t be. A user hit a dead end. Your layout should hold their attention and redirect them fast. Centering everything helps focus it.
Two flexbox rules do the job. Set the container to min-height: 100vh display: flex. Add align-items: center and justify-content: center. Content locks dead center every time, on every screen, with no calculation needed.
<!-- HTML -->
<main class="empty-state">
<div class="empty-state__content">
<span class="empty-state__code">404</span>
<h1>Page not found.</h1>
<p>That URL doesn't exist. It may have moved or been deleted.</p>
<div class="empty-state__actions">
<a href="/" class="btn btn--primary">Back to Home</a>
<a href="/sitemap" class="btn btn--ghost">View Sitemap</a>
</div>
</div>
</main>
/* CSS */
.empty-state {
display: flex;
align-items: center;
justify-content: center;
min-height: 100vh;
padding: 2rem 1.5rem;
background: #fff;
text-align: center;
}
.empty-state__content {
display: flex;
flex-direction: column;
align-items: center;
gap: 1rem;
max-width: 480px;
}
.empty-state__code {
font-size: clamp(5rem, 15vw, 9rem);
font-weight: 800;
line-height: 1;
color: #ebebeb;
letter-spacing: -0.04em;
display: block;
user-select: none;
}
.empty-state__content h1 {
font-size: clamp(1.4rem, 3vw, 2rem);
font-weight: 700;
color: #111;
margin: 0;
}
.empty-state__content p {
font-size: 1rem;
color: #777;
line-height: 1.6;
margin: 0;
}
.empty-state__actions {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
justify-content: center;
margin-top: 0.5rem;
}
.btn {
display: inline-block;
padding: 0.7rem 1.4rem;
border-radius: 0.4rem;
font-size: 0.9rem;
text-decoration: none;
font-weight: 500;
transition: opacity 0.15s ease;
}
.btn:hover {
opacity: 0.8;
}
.btn--primary {
background: #111;
color: #fff;
}
.btn--ghost {
background: transparent;
color: #111;
border: 1px solid #ddd;
}
/* Already responsive — flex centers on all screen sizes */
/* Only tweak needed: reduce code number on very small screens */
@media (max-width: 360px) {
.empty-state__code {
font-size: 4.5rem;
}
}
How to Implement Custom CSS in WordPress Without Theme Filler
Injecting Layout Rules via Custom HTML Blocks
Kadence gives you a Custom HTML block. Use it. Drop your semantic HTML structure directly into it. Your grid container, your flex wrapper, your card markup. WordPress doesn’t touch it.
Then add a second Custom HTML block just above it. Write your <style> tag there. Scope every rule with a unique class. Nothing leaks into global styles. Nothing conflicts with Kadence’s own output.
Bypassing Plugin Architecture and Global Overheads
Every plugin you activate adds CSS to your <head>. Most of it covers edge cases you’ll never hit. Your layout rules don’t need to live there. Scoped block-level styles load only where the block renders.
This matters for PageSpeed. Unused CSS is a render-blocking weight. When your layout styles are scoped to one block, the browser parses less on load. Smaller critical path. Faster first contentful paint. No plugin needed.
Maintaining Clean Code Layout Standards
Purging Outdated CSS Techniques
Legacy code accumulates quietly. float: left wrappers, clearfix hacks, and inline width overrides — none of these belong in a modern layout. They fight against Grid and Flexbox instead of working beside them.
Audit your stylesheet annually. Search for float, display: table, and negative margin tricks. Delete them. Replace with one clean Grid or Flexbox rule. Your specificity chain shortens, and your layout becomes predictable again.
Struggling with Responsive Layout Breakdowns?
Broken layouts cost real money. Visitors leave within three seconds when content shifts, columns collapse incorrectly, or cards misalign on mobile. That’s not a design problem. It’s a structural one. Bad CSS architecture is the root.
Struggling with bloated framework code or responsive breakdown? Get professional custom CSS architecture and speed optimization consulting to clean your code-level bottlenecks. One focused audit removes years of accumulated layout debt fast.
Essential Resources for Creators:
- Need to test React code fast? See our top pick for the Best Online React Compiler 2026.
- Stuck between coding and no-code? Find your answer in Web Development vs Website Builders (2026 Guide).
- See these principles in action: Explore how I applied advanced engineering to build The Blueprint Respiro Premium Shopify.






