Cheatsheet
Use this as a reference while working. You don't need to memorize these!
Table of Contents:
HTML
Document Structure (Boilerplate)
Every HTML document should start with this structure:
Pro Tip: In VS Code, type html:5 and press Enter to insert this boilerplate automatically.
Text Elements
<h1> to <h6>
Headings (use in order, one h1 per page)
<h1>Main Title</h1>
<p>
Paragraph of text
<p>Some text here.</p>
<strong>
Bold/important text
<strong>bold</strong>
<em>
Italic/emphasized text
<em>italic</em>
Lists
Important: <li> elements must always be inside a <ul> or <ol>.
Links and Images
href
<a>
URL or file path the link goes to
src
<img>
URL or file path of the image
alt
<img>
Description for screen readers and when image fails to load
Semantic Structure Elements
Use these elements to organize your page structure:
<header>
Top of page (logo, navigation)
<nav>
Contains navigation links
<main>
Primary content of the page
<section>
A thematic grouping of content
<footer>
Bottom of page (copyright, links)
<figure>
Container for images with captions
<figcaption>
Caption for a <figure>
Forms
Key form rules:
Every
<input>needs a<label>with a matchingfor/idpairEvery
<input>needs anameattribute for the data to be submittedUse appropriate
typeattributes:text,email,number,date,url,checkbox,radio
text
Short, open-ended text
email
Email addresses (validates format)
number
Numeric data
date
Dates (shows calendar picker)
url
URLs (validates format)
checkbox
Yes/no options
radio
Pick ONE from a few options
<textarea>
Long, multi-line text
<select>
Dropdown menu (many options)
Accessibility Quick Tips
Use headings in order — Don't skip from
h1toh4Always add
altto images — Describe what the image showsUse descriptive link text — "Read more about pricing" not "Click here"
Connect labels to inputs — Use
forandidattributesUse semantic elements —
<nav>,<main>,<section>instead of<div>everywhere
CSS
Colors
color
Sets text color
color: midnightblue;
background or background-color
Sets background color
background: azure;
Color values can be: named colors (red, blue), hex codes (#FF5733), or RGB (rgb(255, 87, 51)).
Typography (Text Styling)
font-family
Sets the font
font-family: Arial, sans-serif;
font-size
Sets text size (use rem!)
font-size: 1.5rem;
font-weight
Sets boldness
font-weight: bold;
font-style
Sets italic
font-style: italic;
text-align
Aligns text
text-align: center;
text-decoration
Adds/removes underlines
text-decoration: none;
CSS Variables
CSS Variables are reusable values you define once and use throughout your CSS. This is helpful for consistent colors, fonts, and easy updates.
Example:
Usage:
Define your variables at the top of your style.css inside the :root selector, then use them everywhere you reference colors, fonts, or repeated values.
Box Model (Spacing and Sizing)
width
Sets element width
width: 300px;
max-width
Sets maximum width
max-width: 600px;
padding
Space INSIDE the border
padding: 20px;
margin
Space OUTSIDE the border
margin: 10px;
border
Creates a border (all sides)
border: 2px solid black;
border-top, border-bottom, border-left, border-right
Border on one side
border-bottom: 2px solid black;
border-radius
Rounds corners
border-radius: 8px;
Shorthand for padding/margin:
padding: 10px;→ all sidespadding: 10px 20px;→ top/bottom, left/right
Layout
margin: auto
Centers a block element (needs a width!)
margin: auto;
list-style
Styles/removes list bullets
list-style: none;
Interactive States (Pseudo-classes)
Flexbox
display: flex
Makes the element a flex container
display: flex;
flex-direction
Sets direction: row (default), column
flex-direction: column;
justify-content
Spacing along the main axis
justify-content: space-between
align-items
Alignment along the cross axis
align-items: center;
gap
Space between flex items
gap: 20px;
Common justify-content values: flex-start, flex-end, center, space-between, space-around, space-evenly
Common align-items values: flex-start, flex-end, center, stretch (default)
Grid
display: grid
Makes the element a grid
display: grid;
grid-template-columns
Defines column sizes
grid-template-columns: 1fr 1fr;
gap
Space between grid items
gap: 20px;
The fr unit divides available space into fractions. 1fr 1fr 1fr creates 3 equal columns.
Media Queries
Last updated