HTML + CSS quick reference - find the tool you need, then keep building.
<!DOCTYPE html> <html> <head> <title>My Website</title> <style> /* CSS goes here */ </style> </head> <body> <h1>Hello!</h1> </body> </html>
<h1>...<h6>Headings.<p>Normal paragraph text.<div>General-purpose box/group.<img src="...">Show an image.<a href="...">Link to another page/place.<button>Clickable button.<input>Box the visitor can type in.<br>Start a new line.header, nav, main, section, footer. Think of them as div-like boxes whose names explain their job.class="card" can be reused on many elements. id="menu" gives one element a unique name.paddingSpace inside the box.marginSpace outside the box.margin: autoCenter a box that has a width.width: 80%Use part of available width.line-heightSpace between lines of text.text-decorationnone removes link underline.padding: 12px 20px; /* top/bottom | left/right */ margin: 20px auto; /* space + center the box */
padding = inside. margin = outside. text-align: center centers content inside; margin: auto centers the box itself.colorText colourbackground-colorBackgroundfont-sizeText sizefont-familyFontfont-weightnormal, boldtext-alignleft, center, rightwidthHow wideheightHow tallborder2px solid navyborder-radiusRounded cornersbackgroundColour/image/gradientcursorpointer for clickable thingsproperty: value;h1 { color: navy; }
.card { background-color: white; }
#menu { border: 2px solid black; }
h1 { }Every h1.card { }Every class="card"#menu { }The one id="menu"nav a { }Links inside nav<a href="about.html">About</a>
<img src="images/logo.png" alt="Logo">
<div class="card">...</div>
<button onclick="showMenu()">Menu</button>
| Value | Use it when... |
|---|---|
| 300px | You want a fixed, exact size. |
| 80% | You want size based on the parent. |
| 100% | You want it to fill available width. |
| 100vh | You want the full browser height. |
href="..."Where a link goes.src="..."Where an image/file comes from.alt="..."Short description of an image.class="..."Reusable name for CSS/JS.id="..."Unique name for one element.placeholder="..."Hint text inside an input.Flexbox, useful CSS layout/polish, and simple JavaScript interaction.
.cards {
display: flex; gap: 16px;
flex-direction: row; justify-content: center;
align-items: center; flex-wrap: wrap;
}
justify-content works along this direction.align-items works across it.display: flex
flex-direction
justify-content
align-items
flex-wrap
wrap moves items onto another row/column when needed.gap
flex: 1 lets siblings share available space.display:flex; justify-content:space-between; align-items:center; · card row → display:flex; gap:20px; flex-wrap:wrap; · perfect centering → display:flex; justify-content:center; align-items:center;display: noneHide something completely.overflow: hiddenClip anything sticking outside a box.object-fit: coverFill an image window without stretching.box-shadowAdd depth behind cards/buttons.opacity0 invisible → 1 solid.transitionSmooth a hover/style change.:hoverStyle an element while mouse is over it.linear-gradient(...)Smooth colour background..card img {
width: 100%;
height: 150px;
object-fit: cover;
}.button { transition: .2s; }
.button:hover {
transform: translateY(-2px);
}| static | Normal/default page flow. |
| relative | Stays in normal flow. top/left can shift it from its normal spot. It also anchors absolute children. |
| absolute | Leaves normal flow. Place with top/right/bottom/left. Great for a badge or icon inside a card. |
| fixed | Stays attached to the browser window while scrolling. |
| sticky | Scrolls normally, then sticks at a chosen edge. |
.card { position: relative; }
.badge { position: absolute; top: 8px; right: 8px; }
absolute for overlays, badges and special placement, not for building the whole page.| onclick | Run code when something is clicked. |
| function | Name a set of instructions. |
| getElementById | Find an HTML element by its id. |
| .innerText | Read/change text. |
| .style | Change CSS from JavaScript. |
| .value | Read what someone typed into an input. |
| classList.toggle | Add/remove a CSS class, useful for menus and show/hide. |
<h2 id="title">Hello</h2>
<button onclick="changeTitle()">Change</button>
<script>
let title = document.getElementById("title");
function changeTitle() {
title.innerText = "Welcome!";
title.style.color = "royalblue";
}
</script>
let name = document.getElementById("name").value;.hidden { display: none; }
menu.classList.toggle("hidden");Change one setting at a time. Watch what happens, then copy the live CSS into your own website.