Color Mode

Icons & Graphics: Decision Framework and Pure CSS

Every interface uses small graphics: icons in toolbars, favicons, loading indicators, decorative flourishes, and illustrations. Choosing the right technology (vector SVG, raster images, pure CSS, or icon fonts) affects performance, accessibility, how easy it is to theme, and how sharp things look on high-DPI screens.

This learning activity gives you a decision framework you can reuse on real projects, then walks through pure CSS techniques for simple icons and UI chrome so you know when CSS alone is enough and when you should reach for SVG or images instead.

The Big Picture: Four Common Approaches

Most projects combine these; the skill is knowing which tool fits which job.

No single winner

Professional sites mix approaches. Your job is not to pick one technology forever; it is to pick the least costly option that meets clarity, performance, branding, and accessibility for each asset.

A Practical Decision Framework

Walk through these questions in order when you add or change a graphic.

1. Is it a photograph or rich, non-vector artwork?

Use a raster format (webp or avif when supported, with png fallback for transparency if needed). Provide responsive sources (srcset) and meaningful alt text for content images.

2. Is it a logo, icon, diagram, or simple illustration?

Prefer SVG for scalability and (when inline) CSS theming. For complex illustrations with thousands of nodes, still often SVG, but optimize and test performance.

3. Does it need to match text color or theme instantly (light/dark)?

Inline SVG with currentColor or CSS variables is ideal. Pure CSS shapes can also follow color on a parent. Raster images need separate assets or filters unless you use masks (more work).

4. Is it a tiny UI affordance (spinner, caret, divider, three-line “hamburger”)?

Pure CSS is often enough: no network request, trivial to animate. If the shape grows complex or must match a design system asset pack, switch to SVG.

5. How many icons ship on first paint?

Hundreds of separate SVGs can add HTTP overhead; bundling into a sprite or inline sprite sheet, or using HTTP/2, changes the tradeoff. (You will learn sprite and <symbol> patterns in the next readings.)

6. What do assistive technologies need?

Decorative graphics should be hidden from screen readers. Meaningful icons need <title>/<desc> or adjacent text. Icon fonts can fail when users override fonts (see below).

Quick comparison
Criterion SVG Raster Pure CSS Icon font
Scales to any size Excellent Needs multiple sizes or very large source Good for simple shapes Vector, but hinting varies
Theming with CSS Strong when inline Weak (swap assets or masks) Strong Limited via color
Accessibility pitfalls Manageable with markup Alt text and contrast Often decorative only Font overrides, speech output
Best for Icons, logos, charts Photos, textures Loaders, micro UI Legacy bundles

Pure CSS Icons: Strengths and Limits

Pure CSS is excellent when:

Pure CSS is a poor fit when:

Accessibility

A “button” that is only a CSS shape with no text must have an accessible name: aria-label, visually hidden text, or a visible label. Never rely on color alone to convey state.

Demo: Loading Spinner (Pure CSS)

A common pattern is a rotating border segment. No images required.

The live example uses a single element and @keyframes.

Loading (decorative demo; use aria-label on a real control)

        .spinner {
            width: 2rem;
            height: 2rem;
            border: 3px solid color-mix(in srgb, currentColor 25%, transparent);
            border-top-color: currentColor;
            border-radius: 50%;
            animation: spin 0.8s linear infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }
    

Pair prefers-reduced-motion in real projects: stop or slow the animation when users request reduced motion (Unit 5 patterns).

Demo: “Hamburger” Menu Icon (Three Bars)

Three horizontal bars are easy with a wrapper and pseudo-elements.


        .burger {
            position: relative;
            width: 1.5rem;
            height: 2px;
            background: currentColor;
        }

        .burger::before,
        .burger::after {
            content: "";
            position: absolute;
            left: 0;
            width: 100%;
            height: 2px;
            background: currentColor;
        }

        .burger::before {
            top: -6px;
        }

        .burger::after {
            top: 6px;
        }
    

Demo: CSS Triangle (Chevron)

The “border triangle” trick uses zero width/height and transparent borders on three sides. Useful for carets and tooltips.

Downward caret (decorative)

        .caret-down {
            width: 0;
            height: 0;
            border-left: 6px solid transparent;
            border-right: 6px solid transparent;
            border-top: 8px solid currentColor;
        }
    

Performance and Caching (Brief)

What Comes Next

The next learning activities dive into SVG fundamentals, icon systems (<symbol>, sprites), and implementation patterns (styling, external vs inline, optimization). You will connect this decision framework to concrete SVG workflows.