Prahlad Yeri · June 15, 2026 · 8 min read
Note: This article was written with AI assistance.
Most beginners think beautiful websites come from:
In reality, good design usually comes from:
Consider these two examples:
<h1>My Blog</h1>
<p>Hello World</p>
<button>Read More</button>
Everything touches each other.
<div class="hero">
<h1>My Blog</h1>
<p>Thoughts on technology and open source.</p>
<button>Read More</button>
</div>
.hero {
padding: 60px;
}
.hero h1 {
margin-bottom: 16px;
}
.hero p {
margin-bottom: 24px;
}
The content is identical.
Only spacing changed.
Yet it feels professional.
Things should line up.
Bad:
Title
Paragraph
Button
Good:
Title
Paragraph
Button
Do not fear empty space. Apple, Stripe, Linear, and Notion use huge amounts of whitespace.
Bad:
padding: 5px;
Better:
padding: 40px;
Make important things stand out.
h1 {
font-size: 3rem;
}
p {
color: #666;
}
Pick a spacing system:
4px
8px
16px
32px
64px
Use those everywhere.
Everything in CSS is a box.
+-------------------+
| Margin |
| +---------------+ |
| | Border | |
| | +-----------+ | |
| | | Padding | | |
| | | Content | | |
| | +-----------+ | |
| +---------------+ |
+-------------------+
Example:
.card {
margin: 20px;
padding: 20px;
border: 1px solid #ddd;
}
Outside spacing.
margin-bottom: 20px;
Creates distance between elements.
Inside spacing.
padding: 20px;
Creates distance between content and border.
Avoid fixed widths whenever possible.
Bad:
width: 1200px;
Good:
max-width: 1200px;
width: 100%;
Typical page container:
.container {
max-width: 1100px;
margin: auto;
padding: 20px;
}
The magic:
margin: auto;
Centers the container.
Typography alone can make a website feel premium.
body {
font-family:
system-ui,
sans-serif;
}
Uses the user’s native font.
body {
line-height: 1.7;
}
Avoid line-height: 1;. It looks cramped.
article {
max-width: 700px;
}
Long lines are difficult to read.
position: static;
Normal flow.
position: relative;
left: 10px;
Moves relative to original position.
position: absolute;
top: 0;
right: 0;
Placed relative to nearest positioned parent.
position: fixed;
top: 0;
Stays visible while scrolling. Useful for navbars.
position: sticky;
top: 0;
Acts normal until scrolling reaches it. Then sticks. Great for sidebars.
Before Flexbox and Grid, layouts used floats.
Example:
<div class="sidebar">
Sidebar
</div>
<div class="content">
Content
</div>
.sidebar {
float: left;
width: 25%;
}
.content {
float: left;
width: 75%;
}
Problems:
Today floats are mainly used for wrapping text around an asset:
<img src="photo.jpg">
img {
float: left;
margin-right: 20px;
}
Text wraps around image.
Flexbox changed everything. Think: Row, Column, Centering, Navigation bars, Cards, Toolbars.
<div class="row">
<div>A</div>
<div>B</div>
<div>C</div>
</div>
.row {
display: flex;
}
.row {
display: flex;
justify-content: space-between;
}
Result:
A B C
.hero {
display: flex;
justify-content: center;
align-items: center;
}
Perfect centering.
Instead of margins:
.row {
display: flex;
gap: 20px;
}
Cleaner.
.column {
display: flex;
flex-direction: column;
}
<div class="layout">
<aside>Sidebar</aside>
<main>Content</main>
</div>
.layout {
display: flex;
gap: 30px;
}
aside {
width: 250px;
}
main {
flex: 1;
}
For 2D layouts.
Example:
.grid {
display: grid;
grid-template-columns:
1fr 1fr 1fr;
gap: 20px;
}
Produces:
A B C
D E F
.grid {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(250px,1fr));
gap: 20px;
}
Automatically adjusts.
The web is mobile-first now.
<meta
name="viewport"
content="width=device-width, initial-scale=1">
Always include it.
img {
max-width: 100%;
}
@media (max-width: 768px) {
.layout {
flex-direction: column;
}
}
Desktop:
Sidebar | Content
Mobile:
Sidebar
Content
Start small.
.card {
width: 100%;
}
Then enhance:
@media (min-width: 768px) {
.card {
width: 50%;
}
}
You don’t need to be an artist. Use:
--primary: #2563eb;
--text: #222;
--muted: #666;
--border: #ddd;
--bg: #fafafa;
#24292e
#ffffff
#0969da
#ffffff
#37352f
#eb5757
#111827
#1f2937
#f9fafb
Tailwind is a utility-first CSS framework. Instead of writing:
.card {
padding: 20px;
border-radius: 10px;
background: white;
}
You write directly in your markup:
<div class="p-5 rounded-lg bg-white">
<button class="btn">
Click
</button>
.btn {
background: blue;
color: white;
padding: 10px 20px;
}
<button class="bg-blue-600 text-white px-4 py-2 rounded">
Click
</button>