Quick Reference

HTML5 & CSS Quick Reference Guide


Table of Contents

  1. HTML5 Quick Reference

  2. CSS Quick Reference

  3. Flexbox Cheat Sheet

  4. Grid Cheat Sheet

  5. Responsive Design

  6. Common Patterns

  7. Accessibility Checklist

  8. Troubleshooting Guide


HTML5 Quick Reference

Basic Document Structure

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Page Title</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <!-- Content here -->
</body>
</html>

Semantic HTML5 Elements

Element
Purpose
Example Use

<header>

Introductory content

Site header, article header

<nav>

Navigation links

Main menu, breadcrumbs

<main>

Primary content

Main page content (one per page)

<article>

Self-contained content

Blog post, news article

<section>

Thematic grouping

Chapter, tab panel

<aside>

Tangential content

Sidebar, related links

<footer>

Footer information

Copyright, contact info

<figure>

Self-contained media

Image with caption

<figcaption>

Caption for figure

Image description

<time>

Date/time

<time datetime="2026-01-24">

Common HTML Elements

Text Elements

Lists

Links

Images

HTML Forms Reference

Form Structure

Input Types Quick Reference

Input Type
Usage
Example

text

Single-line text

Name, username

email

Email address

password

Password field

••••••••

number

Numeric input

Age, quantity

tel

Phone number

123-456-7890

url

Website URL

https://...

date

Date picker

2026-01-24

time

Time picker

14:30

datetime-local

Date & time

2026-01-24T14:30

color

Color picker

#ff0000

range

Slider

0-100

file

File upload

Browse files

checkbox

Multiple choice

☑ Option

radio

Single choice

◉ Option

hidden

Hidden field

Not visible

Common Form Elements

Validation Attributes

Attribute
Purpose
Example

required

Field must be filled

<input required>

minlength

Minimum text length

minlength="8"

maxlength

Maximum text length

maxlength="20"

min

Minimum number

min="18"

max

Maximum number

max="100"

pattern

Regular expression

pattern="[0-9]{3}-[0-9]{4}"

placeholder

Example text

placeholder="John Doe"

title

Tooltip/validation msg

title="8+ characters"

Common Patterns

HTML Tables

Multimedia Elements


CSS Quick Reference

CSS Syntax

How to Add CSS

CSS Selectors

Selector
Example
Selects

Element

p

All <p> elements

Class

.classname

All elements with class="classname"

ID

#idname

Element with id="idname"

Universal

*

All elements

Group

h1, h2, h3

All h1, h2, and h3 elements

Descendant

div p

<p> inside <div>

Child

div > p

<p> direct child of <div>

Adjacent sibling

h1 + p

<p> immediately after <h1>

Attribute

[type="text"]

Elements with type="text"

Pseudo-class

a:hover

Link on hover

Pseudo-element

p::first-line

First line of paragraph

CSS Specificity

Priority (lowest to highest):

  1. Element selectors: p (0,0,1)

  2. Class selectors: .class (0,1,0)

  3. ID selectors: #id (1,0,0)

  4. Inline styles: style="" (1,0,0,0)

  5. !important (avoid!)

Common CSS Properties

Colors & Backgrounds

Text & Fonts

Box Model

Display & Visibility

Position

Common Layout Properties

CSS Units Reference

Unit
Description
Example

px

Pixels (absolute)

font-size: 16px;

%

Percentage of parent

width: 50%;

em

Relative to parent font-size

margin: 1em;

rem

Relative to root font-size

padding: 2rem;

vw

1% of viewport width

width: 50vw;

vh

1% of viewport height

height: 100vh;

fr

Fractional unit (Grid)

grid-template-columns: 1fr 2fr;


Flexbox Cheat Sheet

Flex Container Properties

flex-direction

justify-content (main axis alignment)

align-items (cross axis alignment)

flex-wrap

gap

Flex Item Properties

Common Flexbox Patterns


Grid Cheat Sheet

Grid Container Properties

Define Columns and Rows

Grid Template Areas

Gap

Alignment

Grid Item Properties

Common Grid Patterns


Responsive Design

Viewport Meta Tag (Required!)

Media Queries

Common Breakpoints

Device
Min Width
Example

Extra Small (phones)

< 576px

Default

Small (tablets)

576px

@media (min-width: 576px)

Medium (laptops)

768px

@media (min-width: 768px)

Large (desktops)

992px

@media (min-width: 992px)

Extra Large

1200px

@media (min-width: 1200px)

Media Query Features

Responsive Images

Responsive Typography


Common Patterns

Page Layouts

Basic Page Structure

Centered Container

Sticky Header

Full-Height Hero Section

Horizontal Navigation

Responsive Navigation

Card Layouts

Basic Card

Card Grid

Button Styles

Forms

Styled Form


Accessibility Checklist

HTML Accessibility

CSS Accessibility

Keyboard Accessibility

ARIA (when semantic HTML isn't enough)

Accessibility Testing Tools

  • WAVE: Browser extension for accessibility testing

  • axe DevTools: Browser extension for detailed accessibility audit

  • Lighthouse: Built into Chrome DevTools

  • Screen Readers:

    • NVDA (Windows, free)

    • JAWS (Windows, paid)

    • VoiceOver (Mac/iOS, built-in)

  • Keyboard Testing: Tab through your site

  • Color Contrast: WebAIM Contrast Checker


Troubleshooting Guide

Common HTML Issues

Problem
Solution

Page shows HTML code as text

Check DOCTYPE, make sure file is .html

Image not showing

Check file path, file name (case-sensitive)

Form not submitting

Check action attribute, method, button type="submit"

Special characters showing weird

Add <meta charset="UTF-8"> in head

CSS not loading

Check file path, link tag syntax

Validation errors

Use W3C validator, check all tags are closed

Common CSS Issues

Problem
Possible Causes
Solutions

Style not applying

Typo, wrong selector, specificity

Check spelling, use more specific selector

Element not visible

display: none, visibility: hidden, opacity: 0, off-screen

Check display property, position values

Layout broken

Box model issues, float problems

Use box-sizing: border-box, clear floats, use Flexbox/Grid

Text cut off

Overflow hidden, fixed height too small

Check overflow, adjust height, use min-height

Colors not working

Wrong syntax, missing #

Check color format: #FF0000 or rgb(255,0,0)

Margin/padding not working

Inline element, collapsed margins

Use display: block or inline-block

Z-index not working

Element not positioned

Add position: relative (or absolute, fixed)

Centering not working

Wrong method for element type

Block: margin: 0 auto, Flex: justify-content: center

Responsive design broken

No viewport meta tag

Add viewport meta tag to <head>

Debugging with DevTools

  1. Right-click element → Inspect

  2. Check computed styles (see what's actually applied)

  3. Toggle CSS properties on/off to test

  4. Check box model diagram

  5. Look for crossed-out styles (overridden by more specific rule)

  6. Use element selector to pick elements on page

  7. Check console for errors

  8. Test responsive with device toolbar (Ctrl+Shift+M)

CSS Debugging Checklist


Best Practices Summary

HTML Best Practices

DO:

  • Use semantic HTML5 elements

  • Include alt text on all images

  • Associate labels with form inputs

  • Use proper heading hierarchy

  • Validate HTML with W3C validator

  • Keep HTML clean and indented

  • Add comments for complex sections

  • Use lowercase for tags and attributes

DON'T:

  • Use tables for layout

  • Use <div> when semantic element exists

  • Skip heading levels

  • Use inline styles (except for testing)

  • Forget closing tags

  • Use deprecated tags

  • Omit required attributes

CSS Best Practices

DO:

  • Use external stylesheets

  • Use classes for styling

  • Use box-sizing: border-box

  • Mobile-first responsive design

  • Comment your CSS

  • Group related styles

  • Use meaningful class names

  • Validate CSS

DON'T:

  • Use inline styles

  • Use IDs for styling (use for JS)

  • Use !important (except utilities)

  • Use overly specific selectors

  • Use deprecated properties

  • Forget browser prefixes when needed

  • Use color alone to convey meaning

File Organization

Naming Conventions

HTML/CSS:

  • Use kebab-case: my-class-name

  • Be descriptive: .btn-primary not .blue-button

  • BEM (optional): .block__element--modifier

Files:

  • Lowercase, no spaces: my-page.html

  • Use hyphens: main-styles.css


Quick Tips

Performance

  • Minimize HTTP requests

  • Optimize images before upload

  • Use CSS instead of images when possible

  • Combine CSS files

  • Minify CSS for production

Browser Compatibility

  • Test in multiple browsers (Chrome, Firefox, Safari, Edge)

  • Use Can I Use (caniuse.com) to check feature support

  • Provide fallbacks for older browsers

  • Use vendor prefixes when needed

Workflow

  • Write HTML structure first

  • Add CSS styling second

  • Test responsiveness

  • Validate code

  • Check accessibility

  • Cross-browser test

  • Optimize performance

Resources

  • MDN Web Docs: developer.mozilla.org

  • W3Schools: w3schools.com

  • CSS-Tricks: css-tricks.com

  • Can I Use: caniuse.com

  • W3C Validator: validator.w3.org

  • CSS Validator: jigsaw.w3.org/css-validator


Keyboard Shortcuts (DevTools)

Shortcut
Action

F12 or Ctrl+Shift+I

Open DevTools

Ctrl+Shift+C

Element selector

Ctrl+Shift+M

Toggle device toolbar

Ctrl+Shift+J

Console panel

Ctrl+]

Next panel

Ctrl+[

Previous panel

Esc

Toggle console drawer


Regular Expressions (Pattern Attribute)

Examples:


Last updated