Give Your Website Space
In HTML 2 you built cards, images and links. Now we make them feel like a real website: add breathing room, center boxes, build a navbar and make an image card look clean.
1. Padding = Space Inside
Start with the card you already know. The text is too close to the border. padding pushes the content away from the inside edge.
padding = space between the content and its own edge.20px to 0px, 10px and 40px. Which looks best?2. Margin = Space Outside
Padding makes room inside a card. Margin makes room around it, separating the card from other things.
padding: 20px;Space inside the element.margin: 20px;Space outside the element.padding + marginCards often need both.3. Choose the Side
You can change one side at a time.
padding-top: 10px; padding-right: 20px; padding-bottom: 30px; padding-left: 40px;
margin-top: 10px; margin-right: 20px; margin-bottom: 30px; margin-left: 40px;
4. The Padding & Margin Shortcut
CSS lets you set all four sides in one line. The order goes clockwise: Top → Right → Bottom → Left.
padding: 20px; /* all 4 sides */ padding: 10px 20px; /* top/bottom | left/right */ padding: 10px 20px 30px; /* top | left/right | bottom */ padding: 10px 20px 30px 40px; /* top | right | bottom | left */
margin.5. Center the Box vs Center the Text
These look similar, but they do different jobs.
margin: auto;Centers a box such as a card.text-align: center;Centers text and other inline content inside.margin: 0;Does not center. It removes margin.margin: auto centers the card itself. text-align: center centers the text and links inside the card.text-align: center; and press RUN. The card stays in the middle, but its content moves back to the left. Put it back, then delete auto from the margin and compare.6. Percentage Width: %
You saw % in HTML 2. Here is the CSS version: a percentage makes the width depend on the space available.
300px means an exact size. 80% means 80% of the available width.7. Build a Simple Navbar
Links already sit beside each other, so we can make a clean first navbar without learning a new layout system yet.
body { margin: 0; }Removes the browser's outside body space.text-decoration: none;Useful for navbar links.margin: 15px;Separates one link from another.8. Build a Cool Image Card
Now combine HTML 2 images with CSS 2 spacing. This is a pattern you'll use constantly for games and projects.
padding inside, margin outside, margin: auto to center the card, and width: 100% to make the image fill the card.cursor: pointerMove your mouse over the PLAY button. The cursor changes to a hand, which helps tell the user that the button is clickable.cursor: pointer;, press RUN, and move your mouse over PLAY again. Then put it back.9. Three Learning Templates
Templates save time, but they should never be magic. Each one uses code you have already learned. Read it, run it, change it.
Navbar + real image + simple page content.
A reusable image card for one project.
Navbar + heading + project card.
Template 1 · Cool Cars Website
This is still very small code, but it already looks like a real website.
Template 2 · Game Card
Template 3 · My Games Page
Want to build your own website?
Choose a ready-made navbar, card, game page or website starter. Each template shows the modules it needs and the exact skills inside.
CSS 2 Core Complete ✓
If you can use the skills below, you are ready to move on. Everything after this checkpoint is extra.
paddingmargin- top / right / bottom / left shortcuts
margin: 0margin: autowidth: %text-aligntext-decorationcursor: pointer- build a simple navbar
- build a clean image card
Make It Pop
These are useful and fun, but you can skip them for now if you need to move on.
height: 100vh?100vh means 100% of the visible browser height. It makes the gradient cover the whole screen instead of only the short area containing your content and then repeating below it.box-shadow: 0 8px 22px #333;Sideways · down · blur · colour.linear-gradient(blue, purple)One colour changes into another.linear-gradient(to right, blue, purple)Make the gradient move sideways.Polished Game Website
Now use the two bonus effects in a real mini website. Everything else is code from the CSS 2 core.
100vh means the full height of the browser screen.
min-height makes the page at least that tall, but it can still grow if you add more content.
See the Box Model in DevTools
Browsers can show you the content, padding, border and margin as a diagram. Your teacher may demonstrate this now; you do not need to master DevTools for CSS 2.
Right-clickChoose Inspect.ElementsClick the card element.Box modelFind content → padding → border → margin.CSS 2 Memory Map
paddingSpace inside.marginSpace outside / between elements.margin: autoCenter a box such as a card.margin: 0Remove margin.width: 80%Flexible width.text-alignAlign content inside.text-decorationUnderline / no underline.cursor: pointerClickable mouse cursor.box-shadowBonus: shadow effect.linear-gradient()Bonus: blended background.margin: auto centers the box. text-align: center centers what's inside.Which property gives a card breathing room inside its border?
padding
Which property separates one card from another?
margin
What order does padding: 10px 20px 30px 40px use?
Top → Right → Bottom → Left.
What is the difference between margin: auto and text-align: center?
margin: auto centers the card itself. text-align: center centers the text and links inside it.
Ready for the challenge?
Match cards, fix spacing, rebuild a navbar, then make a small website yourself.