Reference Guide

HTML5 & CSS Reference Guide


Table of Contents

  1. HTML5 Document Structure

  2. Semantic HTML5 Elements

  3. Common HTML Elements

  4. HTML Forms

  5. HTML Tables

  6. Multimedia Elements

  7. CSS Basics

  8. CSS Selectors

  9. CSS Box Model

  10. CSS Display & Position

  11. Flexbox

  12. CSS Grid

  13. Responsive Design

  14. Accessibility

  15. Common Patterns

  16. Troubleshooting Guide


HTML5 Document Structure

Basic Template

Essential Meta Tags

Linking Resources


Semantic HTML5 Elements

Page Structure

Complete Example

Other Semantic Elements


Common HTML Elements

Text Elements

Lists

Images


HTML Forms

Basic Form Structure

Text Input Types

Number and Date Inputs

Selection Inputs

Other Input Types

Form Validation Attributes

Button Types

Complete Form Example


HTML Tables

Basic Table

Table with All Sections

Spanning Cells


Multimedia Elements

Video

Audio

iframe (Embedding)


CSS Basics

Three Ways to Add CSS

1. External CSS (BEST)

2. Internal CSS

3. Inline CSS (Avoid)

CSS Syntax

CSS Comments

CSS Variables


CSS Selectors

Basic Selectors

Combining Selectors

Relationship Selectors

Attribute Selectors

Pseudo-classes

Pseudo-elements

Specificity (Order of Priority)


CSS Box Model

Box Model Components

Width and Height

Padding

Border

Margin

Box Sizing

Size Calculations

Without border-box:

With border-box:


CSS Display & Position

Display Property

Visibility

Position Property

Z-index (Stacking Order)

Common Positioning Patterns

Centering with Absolute:

Full Screen Overlay:

Badge on Corner:


Flexbox

Flex Container

Flex Direction

Justify Content (Main Axis)

Align Items (Cross Axis)

Flex Wrap

Gap (Spacing)

Flex Items

Flex Grow:

Flex Shrink:

Flex Basis:

Flex Shorthand:

Align Self:

Order:

Common Flexbox Patterns

Horizontal Navigation:

Centered Content:

Sidebar Layout:

Equal Cards:


CSS Grid

Grid Container

Grid Template Columns

Grid Template Rows

Gap

Grid Template Areas

Grid Items

Grid Column:

Grid Row:

Grid Area (Shorthand):

Alignment

Justify Items (Horizontal):

Align Items (Vertical):

Justify Content (Grid in Container):

Align Content:

Common Grid Patterns

Basic Page Layout:

Image Gallery:

12-Column Grid:


Responsive Design

Viewport Meta Tag (REQUIRED)

Media Queries Syntax

Common Breakpoints

Media Query Features

Responsive Images

Responsive Typography

Responsive Grid

Hiding Elements


Accessibility

Semantic HTML

Alt Text

Form Labels

Heading Hierarchy

Color Contrast

Focus Styles

ARIA Attributes

Keyboard Accessibility


Common Patterns

Centering

Horizontal Center (Block):

Horizontal Center (Text):

Vertical & Horizontal (Flexbox):

Vertical & Horizontal (Grid):

Vertical & Horizontal (Absolute):

Horizontal Navigation:

Card Grid

Hero Section


Troubleshooting Guide

CSS Not Working

1. Check file path

2. Check specificity

3. Check for typos

4. Clear browser cache

  • Hard refresh: Ctrl+Shift+R (Windows) or Cmd+Shift+R (Mac)

Element Not Showing

1. Check display property

2. Check visibility

3. Check if hidden by parent

4. Check z-index

Layout Issues

1. Box model problems

2. Margin collapse

3. Overflow issues

Responsive Issues

1. Viewport not set

2. Images too large

3. Fixed widths

Validation Errors

Use validators:

  • HTML: https://validator.w3.org/

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

Common HTML errors:


Quick Tips

Performance

  • Minimize HTTP requests

  • Compress images

  • Use CSS instead of images when possible

  • Minify CSS and HTML for production

  • Use lazy loading for images: <img loading="lazy">

Best Practices

  • Always use semantic HTML

  • External CSS over inline/internal

  • Mobile-first responsive design

  • Validate your code

  • Comment your code

  • Use consistent naming conventions

  • Keep CSS organized (by component or section)

  • Test in multiple browsers

  • Test with keyboard navigation

  • Check color contrast

Browser DevTools Shortcuts

  • F12 - Open DevTools

  • Ctrl+Shift+C - Element selector

  • Ctrl+Shift+M - Device toolbar (responsive mode)

  • Ctrl+Shift+I - Inspect element

Resources

  • MDN Web Docs - developer.mozilla.org

  • W3Schools - w3schools.com

  • CSS-Tricks - css-tricks.com

  • Can I Use - caniuse.com (browser compatibility)

  • W3C Validators - validator.w3.org


Regular Expression Patterns

Common Form Patterns


Color Reference

Named Colors (Selection)

Color Formats


Units Reference

Absolute Units

Relative Units

When to Use

Last updated