HTML + CSS
A pink, edgy, real-world reference for understanding code, fixing layouts, and making websites behave without rage-clicking random CSS values.
HTML Basics
HTML gives a webpage its structure and meaning. Think of it as the skeleton. CSS is what makes that skeleton look fabulous.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Page</title>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
<head>
Metadata, title, CSS links, meta tags, scripts.
<body>
Visible and interactive content lives here.
<!DOCTYPE html>
Tells the browser to use modern HTML standards.
Attributes, ID vs. Class
Attributes add information to an element. They appear inside the opening tag.
<img src="logo.png" alt="Company Logo" id="main-logo" class="site-logo">
# ID
One unique target.
#hero { color: hotpink; }
. Class
A reusable group or style.
.card { padding: 20px; }
Forms
Forms collect user data. Connect labels to inputs by matching for with the input's id.
<form>
<label for="email">Email</label>
<input type="email" id="email" name="email" placeholder="you@example.com" required>
<button type="submit">Send</button>
</form>
| Attribute | Purpose |
|---|---|
| name | Identifies the data when submitted. |
| placeholder | Shows a temporary hint. It is not a replacement for a label. |
| value | Sets an initial value. |
| maxlength | Limits the number of characters. |
| required | Uses built-in browser validation to require a value. |
Tables
<table>
<caption>Team Members</caption>
<tr>
<th>Name</th>
<th>Role</th>
</tr>
<tr>
<td>Jo</td>
<td>Website Wizard</td>
</tr>
</table>
Semantic HTML
Semantic elements describe what content is, not just what it looks like.
<header>
Intro or header content.
<nav>
Navigation links.
<main>
Main unique page content.
<section>
A themed group of content.
<article>
Self-contained content.
<footer>
Footer information.
Accessibility Basics
- Use useful alt text for meaningful images.
- Decorative images can use alt="".
- Use real labels for form fields.
- Use <button> for actions and <a> for navigation.
- Keep heading order logical: h1 → h2 → h3.
- Do not remove visible keyboard focus unless you replace it with something clear.
CSS Basics
selector {
property: value;
}
Selector = what you target. Property = what you change. Value = what you change it to.
| Type | Example | Where it lives |
|---|---|---|
| Inline | style="color:pink" | Inside the HTML element. |
| Internal | <style>...</style> | Inside the document's head. |
| External | <link rel="stylesheet" href="styles.css"> | A separate CSS file. |
Selectors
| Selector | Targets |
|---|---|
p | All paragraph elements. |
.card | All elements with class="card". |
#hero | The element with id="hero". |
div p | Any p somewhere inside a div. |
div > p | A p that is a direct child of div. |
.card:hover | A card while hovered. |
input:focus | An input while focused. |
.title::after | A generated pseudo-element after the title. |
Cascade, Specificity & Inheritance
When more than one CSS rule targets the same thing, the browser has to decide which declaration wins.
p { color: black; } /* element */
.note { color: purple; } /* class */
#warning { color: deeppink; } /* ID - more specific */
The Box Model
*, *::before, *::after {
box-sizing: border-box;
}
border-box makes declared width/height include padding and borders, which is usually much easier to reason about.
display
| Value | What it does |
|---|---|
| block | Starts on a new line and typically fills available width. |
| inline | Flows with text and uses only needed width. |
| inline-block | Flows inline but accepts width and height. |
| none | Removes the element from layout and display. |
| flex | Creates a Flexbox container. |
| grid | Creates a Grid container. |
visibility:hidden hides an element but keeps its space. display:none removes it from the layout.Flexbox
.container {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
gap: 20px;
flex-wrap: wrap;
}
| Property | Think of it as... |
|---|---|
| flex-direction | Which direction do the items travel? |
| justify-content | How are items spaced on the main axis? |
| align-items | How are items aligned on the cross axis? |
| flex-wrap | Can items move onto another line? |
| gap | Consistent space between items. |
CSS Grid
.card-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 24px;
}
Flexbox
Best when one main direction matters: a row OR a column.
Grid
Best when rows AND columns matter together.
Positioning + z-index
| Position | Behavior |
|---|---|
| static | Normal document flow. |
| relative | Stays in flow; can be offset and anchors absolute children. |
| absolute | Removed from normal flow; positioned against its nearest positioned ancestor. |
| fixed | Anchored to the browser viewport and stays there while scrolling. |
| sticky | Behaves normally until a scroll threshold, then sticks inside its scroll container. |
Responsive Design
Responsive design lets a page adapt to different screen sizes using flexible layouts, images, and media queries.
.cards {
display: grid;
grid-template-columns: 1fr;
}
@media (min-width: 768px) {
.cards {
grid-template-columns: repeat(3, 1fr);
}
}
min-width as more room becomes available.Responsive Images
img {
max-width: 100%;
height: auto;
}
.gallery img {
width: 100%;
aspect-ratio: 4 / 3;
object-fit: cover;
object-position: center;
}
| Property | What it does |
|---|---|
| object-fit: cover | Fills the box. Cropping is allowed. |
| object-fit: contain | Shows the whole image. Empty space may remain. |
| object-position | Controls which part of a cropped image stays visible. |
| aspect-ratio | Maintains a consistent width-to-height proportion. |
CSS Units + Modern Sizing
px
Fixed CSS pixel.
%
Relative to another size, often the parent.
rem
Relative to the root font size.
em
Relative to the current font context.
vw / vh
Relative to viewport width/height.
fr
A fraction of available Grid space.
h1 {
font-size: clamp(2rem, 5vw, 4.5rem);
}
.container {
width: min(92%, 1200px);
}
CSS Variables
:root {
--brand-pink: #ff2e9a;
--text-dark: #17141a;
--space-lg: 32px;
}
.button {
background: var(--brand-pink);
padding: 12px var(--space-lg);
}
Change the value once and every place using that variable updates.
Debugging with DevTools
| Problem | Check first |
|---|---|
| Style does nothing | Is the selector matching? Is the rule crossed out? |
| Image is missing | Path, filename case, src value, Network tab. |
| Elements overlap | Positioning, width/height, overflow, parent Flex/Grid rules. |
| Mobile looks wrong | Viewport meta tag and active media queries. |
| Spacing is weird | Computed margin/padding and the box model. |
| Wrong rule wins | Specificity and source order. |
Bootstrap & Theme CSS
Framework classes already carry CSS. Your custom rules are layered on top of them, which is why a theme can sometimes appear to “fight” you.
<div class="row">
<div class="col-lg-4">One</div>
<div class="col-lg-4">Two</div>
<div class="col-lg-4">Three</div>
</div>
Quick Self-Test
Bonus: File paths that save your sanity
images/logo.png starts from the current file's location. ../images/logo.png goes up one folder first. /images/logo.png starts from the site root. On many servers, logo.JPG and logo.jpg are different filenames.
Bonus: Link vs Button
Use a link when the user is going somewhere. Use a button when the user is doing something.