Course

Web Development
  • 1.1 Introduction to the Web
  • 2.1 HTML Basics
  • 2.2 Text & Content
  • 2.3 Layout & Grouping
  • 2.4 Lists & Tables
  • 2.5 Media & Embedding
  • 2.6 Forms
  • 2.7 Semantic HTML
  • 2.8 Accessibility & SEO
  • 3.1 CSS Introduction
  • 3.2 CSS Syntax
  • 3.3 CSS Selectors
  • 3.4 Typography
  • 3.5 Colors & Backgrounds
  • 3.6 Text Styling
  • 3.7 Box Model
  • 3.8 Units
  • 3.9 Display & Positioning
  • 3.10 Layout Systems
  • 3.11 Responsive Design
  • 3.12 Animations
  • 3.13 Modern CSS
  • 3.14 Performance & Accessibility
  • 3.15 Tailwind CSS Basics
  • 4.1 Introduction to JavaScript
  • 4.2 Variables & Scope
  • 4.3 Data Types
  • 4.4 Type Conversion
  • 4.5 Operators
  • 4.6 Control Flow
  • 4.7 Loops
  • 4.8 Functions
  • 4.9 Advanced Functions
  • 4.10 Objects & Arrays
  • 4.11 The this Keyword

3.14 Performance & Accessibility

Updated Jul 20, 2026

3.14 Performance & Accessibility

Updated Jul 20, 2026

A modern website should not only look good but also be:

  • Fast
  • Responsive
  • Accessible
  • User-Friendly
  • SEO-Friendly

In this lesson, we'll cover two important aspects of frontend development:

  1. CSS Performance
  2. Accessibility Best Practices

CSS Performance

CSS Performance focuses on making styles load and render efficiently.

Well-optimized CSS leads to:

  • Faster Page Load
  • Better User Experience
  • Improved SEO
  • Lower Memory Usage
  • Better Performance on Mobile Devices

Why CSS Performance Matters

Poorly optimized CSS can cause:

  • Slow Rendering
  • Laggy Animations
  • Layout Shifts
  • High Memory Usage
  • Poor User Experience

Optimizing your CSS helps websites load faster and feel smoother.


Minimize CSS File Size

Large CSS files take longer to download.

Bad Example

.button {

    background: blue;

}

.card {

    background: white;

}

/* Hundreds of unused styles */

Good Practice

Remove:

  • Unused CSS
  • Dead Styles
  • Duplicate Rules

Smaller CSS files download faster.


Use External CSS Files

Instead of writing CSS inside every HTML page, use an external stylesheet.

<link
rel="stylesheet"
href="styles.css"
>

Benefits:

  • Browser Caching
  • Reusable Styles
  • Smaller HTML Files
  • Faster Loading on Future Visits

Reduce Selector Complexity

Complex selectors take longer for browsers to evaluate.

Avoid

body main section article div p span {

    color: red;

}

Better

.text {

    color: red;

}

Simple selectors are easier to read and more efficient.


Avoid Excessive Nesting

Deeply nested selectors make CSS harder to maintain.

Bad

.container .content .card .title {

    color: blue;

}

Good

.card-title {

    color: blue;

}

Use Efficient Selectors

Prefer class selectors.

Fast

.button {}

.card {}

.nav-link {}

Avoid unnecessary complex selectors.

div > ul > li > a {}

Optimize Images

Background images should be optimized.

Bad

.hero {

    background-image: url("large-image.png");

}

Better

.hero {

    background-image: url("hero.webp");

}

Recommended formats:

  • WebP
  • AVIF
  • Compressed JPEG

Smaller images improve loading speed.


Avoid Expensive CSS Properties

Some CSS properties trigger layout recalculations.

Expensive

  • width
  • height
  • top
  • left
  • margin

Better for Animations

  • transform
  • opacity

Example

Bad

.card:hover {

    top: -10px;

}

Good

.card:hover {

    transform: translateY(-10px);

}

Use Hardware-Accelerated Animations

Modern browsers optimize animations using:

  • transform
  • opacity

Example

.card {

    transition: transform 0.3s ease;

}

These animations are smoother and require less processing power.


Minify CSS

Before deploying a website, CSS should be minified.

Before

.card {

    padding: 20px;

}

After

.card{padding:20px}

Benefits:

  • Smaller Files
  • Faster Downloads
  • Reduced Bandwidth

Use CSS Variables

Avoid repeating values throughout your stylesheet.

Instead of

.button {

    background: #2563EB;

}

.card {

    border-color: #2563EB;

}

Use

:root {

    --primary: #2563EB;

}

.button {

    background: var(--primary);

}

.card {

    border-color: var(--primary);

}

Benefits:

  • Consistent Design
  • Easier Maintenance
  • Less Repetition

Reduce Repaints & Reflows

Every visual update requires the browser to:

Calculate Layout
        ↓
Paint Pixels
        ↓
Render Screen

Avoid triggering unnecessary layout recalculations.

Prefer:

  • transform
  • opacity

Avoid animating:

  • width
  • height
  • margin

Lazy Load Images

Images below the visible area should load only when needed.

<img
src="image.jpg"
loading="lazy"
alt="Image"
>

Benefits:

  • Faster Initial Load
  • Reduced Bandwidth
  • Better Performance

CSS Performance Checklist

✔ Remove Unused CSS

✔ Minify CSS

✔ Use CSS Variables

✔ Optimize Images

✔ Prefer Transform & Opacity

✔ Avoid Deep Selectors

✔ Cache CSS Files


Accessibility (A11Y)

Accessibility ensures websites are usable by everyone, including people with disabilities.

This includes users with:

  • Visual Impairments
  • Motor Disabilities
  • Hearing Disabilities
  • Cognitive Disabilities

Why Accessibility Matters

Benefits include:

  • Better User Experience
  • Legal Compliance
  • Improved SEO
  • Larger Audience
  • Better Website Quality

Use Semantic HTML

Avoid generic elements when semantic elements exist.

Bad

<div class="header">

</div>

Good

<header>

</header>

Benefits:

  • Better Structure
  • Improved Screen Reader Support
  • Better SEO

Proper Heading Structure

Bad

<h1>Main Title</h1>

<h4>Section</h4>

Good

<h1>Main Title</h1>

<h2>Section</h2>

<h3>Subsection</h3>

Proper heading order creates a logical content hierarchy.


Add Alt Text to Images

Bad

<img src="logo.png">

Good

<img
src="logo.png"
alt="Company Logo"
>

Benefits:

  • Screen Reader Support
  • Better SEO
  • Images remain understandable if they fail to load

Use Labels for Forms

Bad

<input type="email">

Good

<label for="email">

    Email

</label>

<input
id="email"
type="email"
>

Labels improve usability and accessibility.


Ensure Keyboard Navigation

Users should be able to navigate using only the keyboard.

Common keys:

  • Tab
  • Shift + Tab
  • Enter
  • Space

Good

<button>

    Submit

</button>

Avoid

<div onclick="submit()">

    Submit

</div>

Maintain Color Contrast

Poor contrast makes text difficult to read.

Bad

Light Gray Text
on White Background

Good

Dark Text
on White Background

High contrast improves readability.


Don't Rely Only on Color

Avoid communicating information using only colors.

Bad

Red = Error

Green = Success

Better

❌ Error

✅ Success

Or provide descriptive text alongside colors.


Provide Focus Indicators

Keyboard users need to know which element is currently selected.

Good

button:focus {

    outline: 2px solid blue;

}

Avoid

button:focus {

    outline: none;

}

Use Readable Font Sizes

Avoid very small text.

Bad

font-size: 10px;

Recommended

font-size: 16px;

Body text should generally be at least 16px.


Responsive Typography

Text should adapt to different screen sizes.

font-size: clamp(
1rem,
2vw,
1.25rem
);

This improves readability across devices.


Accessible Buttons

Bad

<div>

    Click Me

</div>

Good

<button>

    Click Me

</button>

Buttons provide built-in keyboard and accessibility support.


Accessible Links

Bad

<a>

    Read More

</a>

Good

<a href="/article">

    Read More

</a>

Links should always have a valid destination.


ARIA Attributes

ARIA (Accessible Rich Internet Applications) provides additional information to assistive technologies when HTML alone is not enough.

Example

<button
aria-label="Close Menu"
>

    ✕

</button>

Common ARIA Attributes

Attribute Purpose
aria-label Accessible label
aria-hidden Hide from screen readers
aria-expanded Expand/Collapse state
aria-describedby Additional description

Use ARIA only when semantic HTML cannot provide the required accessibility.


Accessibility Testing Tools

Popular accessibility tools include:

  • Lighthouse
  • axe DevTools
  • WAVE
  • Screen Readers

These tools help identify accessibility issues before deployment.


Accessibility Checklist

✔ Use Semantic HTML

✔ Maintain Proper Heading Structure

✔ Add Alt Text

✔ Label Form Controls

✔ Support Keyboard Navigation

✔ Ensure Good Color Contrast

✔ Show Focus Indicators

✔ Use Responsive Typography

✔ Use ARIA Only When Necessary


Performance vs Accessibility

Great websites achieve both.

Example

<img
src="hero.webp"
alt="Students learning HTML"
loading="lazy"
>

Benefits

Performance

  • Optimized Image
  • Lazy Loading

Accessibility

  • Descriptive Alt Text

Real-World Example

:root {

    --primary: #2563EB;

}

.button {

    background: var(--primary);

    transition: transform 0.3s ease;

}

.button:hover {

    transform: translateY(-2px);

}

.button:focus {

    outline: 2px solid blue;

}

This example provides:

  • Good Performance
  • Better Accessibility
  • Easier Maintenance

Summary

Topic Purpose
CSS Performance Faster websites
Minification Smaller CSS files
CSS Variables Reusable values
Transform & Opacity Efficient animations
Semantic HTML Better accessibility
Alt Text Accessible images
Labels Accessible forms
Focus States Keyboard navigation
Color Contrast Better readability
ARIA Enhanced accessibility

Key Takeaway

A professional frontend developer should build websites that are:

Fast
     +
Accessible
     +
Responsive
     +
Maintainable

Modern frontend development commonly uses:

  • transform
  • opacity
  • clamp()
  • CSS Variables

Combined with:

  • Semantic HTML
  • Alt Text
  • Labels
  • Focus Indicators
  • ARIA Attributes

Following these best practices helps create websites that are faster, more accessible, SEO-friendly, and usable by everyone.

3.13 Modern CSS3.15 Tailwind CSS Basics