LEARN TO CODE | QUICK REFERENCE
HTML & CSS CHEAT SHEET
Common elements, attributes, selectors and properties at a glance. Covers all four sections of the HTML & CSS course.
JUMP TO A TOPIC
Choose a topic below to jump straight to its reference section. Each entry pairs a short explanation with a ready-to-adapt example. HTML uses elements and attributes; CSS uses selectors and properties.
01 | PAGE STRUCTURE
| Item | Use and example |
|---|---|
| Document type |
Use the modern HTML document type.
|
| Document root |
Declare the page language.
|
| Head / body |
Metadata belongs in head; page content in body.
|
| Character encoding |
Use UTF-8 for document text.
|
| Viewport |
Let the layout match the device width.
|
| Page title |
Text for the browser tab and other contexts.
|
| Description |
Summarise the page for search engines.
|
| External CSS |
Load a stylesheet relative to this HTML file.
|
| External JavaScript |
Run a classic external script after HTML parsing.
|
| Comment |
A source note; not hidden or secret data.
|
02 | TEXT AND MEANING
| Item | Use and example |
|---|---|
| Headings |
Use heading levels to reflect document structure.
|
| Paragraph |
A paragraph of text.
|
| Strong / emphasis |
Importance / stress emphasis, not just appearance.
|
| Line / thematic break |
A necessary line break / thematic change.
|
| Code / preformatted |
Use pre to preserve whitespace in code.
|
| Quotation |
A block quotation; attribute the source visibly.
|
| Generic containers |
div groups flow content; span groups inline text.
|
| Special characters |
Write markup characters as character references.
|
Use CSS for spacing. Repeated br elements are not a page-layout system.
03 | SEMANTIC PAGE REGIONS
| Item | Use and example |
|---|---|
| header |
Introductory content for a page or section.
|
| nav |
A significant navigation region.
|
| main |
The page’s dominant content.
|
| section |
A thematic section, normally with a heading.
|
| article |
A self-contained item such as a post or project.
|
| aside |
Related, tangential content.
|
| footer |
Footer information for a page or section.
|
Choose elements for their meaning. A semantic element does not automatically supply the desired layout.
04 | LINKS, PATHS AND IMAGES
| Item | Use and example |
|---|---|
| Relative link |
Open another page in the current site.
|
| Parent folder |
Move up one folder in a relative path.
|
| Page anchor |
Link to a unique matching element ID.
|
| External new tab |
Use clear link text and a suitable rel value.
|
| Email / download |
Open a mail handler / suggest downloading a file.
|
| Image |
Give meaningful images useful alternative text.
|
| Decorative image |
An empty alt marks a purely decorative image.
|
| Caption |
Associate an image and caption.
|
Use forward slashes in web paths. CSS url(...) paths are relative to the stylesheet. download has origin restrictions; it is not a guarantee.
05 | LISTS AND TABLES
| Item | Use and example |
|---|---|
| Unordered list |
A collection without meaningful numbering.
|
| Ordered list |
A meaningful sequence or ranking.
|
| Description list |
Terms and their descriptions.
|
| Table caption |
Give a data table a descriptive caption.
|
| Table regions |
thead groups heading rows; tbody groups body rows.
|
| Row / heading / cell |
tr is a row; th is a header; td is a data cell.
|
Use tables for tabular data. Use Flexbox or Grid for page layout.
06 | FORMS AND INPUTS
| Item | Use and example |
|---|---|
| Form |
action is the destination; method controls submission.
|
| Label + input |
The label for matches the input id.
|
| Email / password |
Use an appropriate input type.
|
| Number |
Set numeric bounds and allowed step.
|
| Date / file |
Choose a date / select a file.
|
| Textarea |
A multi-line text control.
|
| Select |
Choose from options; give it a visible label.
|
| Checkbox |
Independent on/off choice; label can wrap it.
|
| Radio group |
One choice in a group sharing the same name.
|
| Fieldset + legend |
Label a related group of controls.
|
| Buttons |
Submit a form / perform another scripted action.
|
A server or JavaScript handler must implement the action. HTML alone does not send email or store records. Password inputs obscure display, not network traffic; use HTTPS.
07 | USEFUL ATTRIBUTES
| Item | Use and example |
|---|---|
| id / class |
Unique page identifier / reusable styling classes.
|
| name / value |
A form field’s submitted key / value.
|
| required |
Require a value under the control’s rules.
|
| minlength / maxlength |
Text-length constraints on supported controls.
|
| pattern |
A supported text-control pattern; explain the rule.
|
| placeholder |
A short hint; not a substitute for a label.
|
| autocomplete |
Help the browser identify the expected data.
|
| checked / selected |
Initial checkbox/radio / option selection.
|
| disabled / readonly |
Disabled fields are normally not submitted.
|
| Boolean attributes |
Presence means true; omit to make false.
|
| hidden / data-* |
Hide a region / attach custom string data.
|
Browser validation can be bypassed. A real backend must validate received data independently. readonly applies only to supported controls.
08 | MEDIA AND DISCLOSURE
| Item | Use and example |
|---|---|
| Video |
Show native controls; provide appropriate captions.
|
| Audio |
Show playback controls for an audio source.
|
| Disclosure |
A keyboard-operable expandable explanation.
|
09 | CSS SELECTORS
| Item | Use and example |
|---|---|
| Element |
Match every element of that type.
|
| Class |
Match a reusable class.
|
| ID |
Match an ID; prefer classes for reusable styles.
|
| Group |
Apply the rule to either selector.
|
| Descendant / child |
Any matching descendant / direct child.
|
| Combined classes |
Both classes must be on the same element.
|
| Attribute |
Match an attribute value.
|
| Pseudo-class |
Match a state or structural condition.
|
| Focus |
Show a visible keyboard-focus indicator.
|
| Pseudo-element |
Style a part or generated decorative content.
|
.card p is not the same as .card.featured. Pseudo-class names start with :; pseudo-elements normally use ::.
10 | COLOUR AND TYPOGRAPHY
| Item | Use and example |
|---|---|
| Text / background |
Foreground colour / background colour.
|
| Font family |
Give a preferred family and fallbacks.
|
| Size / weight |
Set text size / weight.
|
| Line height |
Unitless values scale with the font size.
|
| Alignment / decoration |
Align inline content / underline text.
|
| Case / spacing |
Change presentation without changing source text.
|
| Wrapping |
Allow long strings to wrap within their box.
|
11 | BOX MODEL AND SIZING
| Item | Use and example |
|---|---|
| Border box |
Include padding and border in declared size.
|
| Padding / margin |
Inner spacing / outside spacing.
|
| Four-value order |
Top, right, bottom, left.
|
| Two-value order |
Vertical, then horizontal.
|
| Border / rounding |
Outline the box / round its corners.
|
| Width / max-width |
Set preferred width and a maximum.
|
| Centre a block |
Use auto side margins with a constrained width.
|
| Height / min-height |
Fixed height / allow at least this height.
|
| Overflow |
Allow scrolling when content exceeds a box.
|
Content-box size excludes padding and border. Vertical block margins can collapse; Flexbox and Grid layouts behave differently.
12 | FLEXBOX
| Item | Use and example |
|---|---|
| Flex container |
Lay out direct children along a main axis.
|
| Direction / wrapping |
Choose axis direction and allow extra lines.
|
| Main-axis alignment |
Distribute children along the main axis.
|
| Cross-axis alignment |
Align children on the cross axis.
|
| Grow / shrink / basis |
A flexible child with a 16rem starting basis.
|
| Centre both ways |
Axes depend on flex-direction.
|
Flexbox is useful for navigation, toolbars and one-dimensional arrangements. Properties on a container affect its direct flex items.
13 | CSS GRID
| Item | Use and example |
|---|---|
| Two equal columns |
Two tracks that can shrink without min-content overflow.
|
| Responsive card tracks |
Fit as many minimum-sized tracks as available.
|
| Span every column |
A grid item spans all the explicit columns.
|
| Track sizing |
Specify a sidebar and flexible content track.
|
| Item alignment |
Align items within their grid areas.
|
Grid is useful for rows and columns together. fr distributes available track space; gap creates gutters between tracks.
14 | RESPONSIVE DESIGN AND IMAGES
| Item | Use and example |
|---|---|
| Small-screen rule |
Apply these rules when the viewport is at most 700px.
|
| Responsive image |
Preserve proportions and avoid oversized images.
|
| Size and centre one image |
Use an image class for deliberate sizing.
|
| Crop into a frame |
cover may crop; contain preserves the whole image.
|
| Fluid font size |
A minimum, preferred value and maximum.
|
| Relative units |
Root font / current font / viewport dimensions.
|
15 | POSITION, VISIBILITY AND EFFECTS
| Item | Use and example |
|---|---|
| Relative |
Keep normal space; establish positioning context.
|
| Absolute |
Remove from normal flow; use containing-block rules.
|
| Fixed |
Usually position relative to the viewport.
|
| Sticky |
Stick within scrolling/containing-block limits.
|
| Layer order |
Applies within stacking-context rules.
|
| Hide and remove layout |
Also normally removes content from accessibility tree.
|
| Invisible but keep layout |
Different from removing its layout space.
|
| Shadow |
Add a visual shadow.
|
| Transition |
Animate a specific changing property.
|
| Reduced motion |
Respect visitors who request less movement.
|
Absolute positioning often uses the nearest positioned ancestor, but other properties can establish containing blocks too. Avoid positioning for ordinary page flow.
16 | VARIABLES, CASCADE AND COMMON FIXES
| Item | Use and example |
|---|---|
| Custom property |
Define a reusable CSS value. Use it via var().
|
| Specificity |
Within the same origin/layer context: ID beats class, class beats
type.
|
| Source order |
If relevant priority and specificity tie, later wins.
|
| Inheritance |
Some properties, such as color, inherit. Not all do.
|
| List markers |
Use square list markers.
|
| Collapsed table borders |
Join adjacent cell borders.
|
The cascade also considers origins, importance and layers. Use browser DevTools to inspect matched rules rather than solving every conflict with !important.
17 | ACCESSIBILITY QUICK CHECK
| Item | Use and example |
|---|---|
| Meaningful links |
Make the destination clear from the label.
|
| Skip link |
Let keyboard visitors jump to main content.
|
| Visible labels |
Do not rely on a placeholder alone.
|
| Native controls |
Use buttons for actions, links for navigation.
|
| Image alternatives |
Describe useful meaning; use empty alt for decoration.
|
| Focus and contrast |
Keep focus visible; do not communicate only by colour.
|
Test by keyboard, zoom and a narrow viewport. Semantic HTML helps but does not by itself guarantee an accessible page.
18 | MINIMAL STARTER PAGE
Create index.html and styles.css in the same VS Code folder. Save both, then open or preview index.html in your browser.
index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My first page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>My project</h1>
</header>
<main>
<section class="card">
<h2>About this project</h2>
<p>A short introduction goes here.</p>
<a href="about.html">Read more</a>
</section>
</main>
</body>
</html>
styles.css
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: Arial, sans-serif;
line-height: 1.6;
color: #243332;
}
header,
main {
width: 90%;
max-width: 70rem;
margin-inline: auto;
}
.card {
margin-block: 1.5rem;
padding: 1.5rem;
border: 2px solid #24988f;
border-radius: 12px;
}
a:focus-visible {
outline: 3px solid #24988f;
outline-offset: 3px;
}
Create about.html before using the example’s Read more link. No JavaScript or extra installation is needed for this starter.
QUICK FIXES BEFORE YOU LEAVE
- CSS not loading? Check the href, filename, path and saved file.
- Selector not working? Check the class/ID spelling and cascade.
- Layout too wide? Check fixed widths, box sizing and long content.
- Image too big? Give it a class, max-width and height: auto.
- Form value missing? Check its name and disabled state.
Reference: HTML elements · CSS reference