The playground philosophy: mobile-first, CSS-powered, learn by building.
npm run build, then refresh.
Every HTML element is a box with 4 layers, inside → out:
| Layer | What it does | Analogy |
|---|---|---|
| content | The actual text, image, etc. | The item in the box |
| padding | Space inside, around content | Bubble wrap |
| border | Edge of the element | The cardboard box |
| margin | Space outside, between elements | Space between boxes |
.card {
width: 200px;
padding: 20px; /* 20px inside on each side */
border: 5px solid; /* 5px edge on each side */
margin: 10px; /* 10px outside on each side */
}
/* Default total width: 200 + 40 + 10 = 250px */
By default, width only controls content size. Padding and border add extra width.
This is why layouts randomly overflow.
The fix — put this at the top of every project:
*, *::before, *::after {
box-sizing: border-box;
}
Now width: 200px means 200px total — content shrinks to make room for padding and border.
Layouts behave how humans expect.
/* Without border-box: 50% + padding = overflow = broken */
/* With border-box: padding fits inside 50% = works */
.column {
width: 50%;
padding: 20px;
}
Flexbox arranges children in a row or column. It replaced 15 years of float hacks.
.container {
display: flex;
}
/* Result: A B C (horizontal row) */
| Property | Controls | Common values |
|---|---|---|
| justify-content | horizontal spacing | center, space-between, space-around |
| align-items | vertical alignment | center, flex-start, stretch |
| gap | space between items | 10px, 20px, 1rem |
.container {
display: flex;
justify-content: center;
align-items: center;
}
/* Centers anything. Works every time. */
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
}
/* Result: Logo ........... Menu */
.container {
display: flex;
flex-direction: column;
gap: 16px;
}
/* Result: A
B
C */
Grid controls rows AND columns. Use it for page-level layouts.
.page {
display: grid;
grid-template-columns: 200px 1fr;
}
/* Result: Sidebar | Content */
.page {
display: grid;
grid-template-rows: auto 1fr auto;
}
/* Result: Header
Content (fills space)
Footer */
/* A real webpage uses all three: */ Page (Grid) ├ Header (Flexbox) │ ├ Logo │ └ Nav Links │ ├ Content (Grid or Flexbox) │ ├ Sidebar │ └ Main Content │ └ Footer
| # | Rule | Why |
|---|---|---|
| 1 | *, *::before, *::after { box-sizing: border-box; } | Sane sizing |
| 2 | body { margin: 0; } | Remove browser default gaps |
| 3 | display: flex; | Row layout |
| 4 | flex-direction: column; | Column layout |
| 5 | gap: 20px; | Spacing without margin hacks |
| 6 | justify-content + align-items: center; | Perfect centering |
| 7 | max-width: 900px; margin: 0 auto; | Readable centered content |
| 8 | img { max-width: 100%; } | Images scale on small screens |
| 9 | display: grid; | Page-level layout |
| 10 | min-height: 100vh; | Full-screen sections |
float, clearfix, table layouts, manual margin spacing everywhere
Modern stack: box-sizing + flexbox + grid + gap. That's the whole game.
SvelteKit doesn't replace CSS — it compiles to normal HTML + CSS + JS.
Everything above applies directly inside .svelte files.
<script>
let name = "Lucas";
</script>
<h1>Hello {name}</h1>
<style>
h1 {
color: blue;
}
</style>
| Feature | What it does |
|---|---|
| Scoped CSS | Styles can't leak between components — automatic |
| Dead CSS removal | Unused styles get stripped at build time |
| No runtime CSS | Compiled away — tiny bundles |
| {#if} / {#each} | Templating for conditions and loops |
| $state / $derived | Reactivity without useState() boilerplate |
<div class="navbar">
<h1>My App</h1>
<nav>
<a href="/">Home</a>
<a href="/docs">Docs</a>
</nav>
</div>
<style>
.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 16px;
}
</style>