|
1 | | -# No JavsScript, No cry |
| 1 | +# HTML Over JS |
2 | 2 |
|
3 | 3 | A comprehensive demonstration of how native HTML elements solve 90% of common UI problems without JavaScript frameworks. |
4 | 4 |
|
5 | 5 | ## Author |
| 6 | + |
6 | 7 | Michael W. Czechowski <[email protected]> |
7 | 8 |
|
8 | 9 | ## Overview |
| 10 | + |
9 | 11 | This project exposes the absurdity of JavaScript wheel-reinvention and demonstrates the path to enlightened web development through semantic markup and progressive enhancement. |
10 | 12 |
|
11 | | -## Topics Covered |
| 13 | +--- |
| 14 | + |
| 15 | +## Native HTML Solutions |
| 16 | + |
| 17 | +### Priority 1: Core UI Patterns |
| 18 | + |
| 19 | +The most commonly reinvented patterns that HTML already solves perfectly. |
| 20 | + |
| 21 | +#### Modal Dialogs |
| 22 | +- **JS Problem**: Focus trapping, ESC handling, backdrop clicks, memory leaks, z-index wars |
| 23 | +- **HTML Solution**: `<dialog>` with `.showModal()` and `.close()` |
| 24 | +- **Features**: Automatic focus management, ESC to close, backdrop via `::backdrop`, form integration with `method="dialog"` |
| 25 | + |
| 26 | +#### Collapsible Content & Accordions |
| 27 | +- **JS Problem**: Complex event handling, manual ARIA, broken keyboard navigation |
| 28 | +- **HTML Solution**: `<details>` and `<summary>` |
| 29 | +- **Features**: Built-in toggle, exclusive groups via `name` attribute, keyboard accessible, screen reader support |
| 30 | + |
| 31 | +#### Form Validation |
| 32 | +- **JS Problem**: Custom regex, manual error display, inconsistent UX across browsers |
| 33 | +- **HTML Solution**: HTML5 constraint validation API |
| 34 | +- **Features**: `required`, `pattern`, `minlength/maxlength`, `min/max`, `type="email|url|tel"`, `:valid/:invalid` CSS, `setCustomValidity()` |
| 35 | + |
| 36 | +#### Autocomplete & Search |
| 37 | +- **JS Problem**: Custom dropdowns, keyboard navigation bugs, focus management |
| 38 | +- **HTML Solution**: `<input>` with `<datalist>` |
| 39 | +- **Features**: Native OS integration, keyboard navigation, fuzzy matching, works with any input type |
| 40 | + |
| 41 | +#### Progress Indicators |
| 42 | +- **JS Problem**: Manual width calculations, custom ARIA updates, animation jank |
| 43 | +- **HTML Solution**: `<progress>` for tasks, `<meter>` for measurements |
| 44 | +- **Features**: Semantic meaning, automatic screen reader announcements, indeterminate state, CSS styling via `::-webkit-progress-bar` |
| 45 | + |
| 46 | +--- |
| 47 | + |
| 48 | +### Priority 2: Form & Input Elements |
| 49 | + |
| 50 | +Native inputs that replace entire JavaScript libraries. |
| 51 | + |
| 52 | +#### Date & Time Pickers |
| 53 | +- **JS Problem**: Massive libraries (jQuery UI, Flatpickr), mobile UX issues, localization nightmares |
| 54 | +- **HTML Solution**: `type="date|time|datetime-local|month|week"` |
| 55 | +- **Features**: OS-native UI, touch-optimized, `min/max` constraints, automatic localization |
| 56 | + |
| 57 | +#### Range Sliders |
| 58 | +- **JS Problem**: Custom drag handling, touch support, visual feedback |
| 59 | +- **HTML Solution**: `type="range"` |
| 60 | +- **Features**: `min/max/step`, keyboard control, `list` for tick marks via datalist, CSS styling |
| 61 | + |
| 62 | +#### Color Pickers |
| 63 | +- **JS Problem**: Complex color space math, custom palettes, touch handling |
| 64 | +- **HTML Solution**: `type="color"` |
| 65 | +- **Features**: OS-native picker, returns hex value, eyedropper tool (on supported browsers) |
| 66 | + |
| 67 | +#### File Uploads |
| 68 | +- **JS Problem**: Drag-drop zones, file type validation, preview generation |
| 69 | +- **HTML Solution**: `type="file"` with `accept` and `multiple` |
| 70 | +- **Features**: MIME type filtering, camera/capture on mobile, form integration |
| 71 | + |
| 72 | +#### Output Display |
| 73 | +- **JS Problem**: Manual DOM updates for calculated values |
| 74 | +- **HTML Solution**: `<output>` element |
| 75 | +- **Features**: Semantic calculation result, `for` attribute links to inputs, form association |
| 76 | + |
| 77 | +#### Rich Text Editing |
| 78 | +- **JS Problem**: Complex editor libraries (Quill, TinyMCE, CKEditor) |
| 79 | +- **HTML Solution**: `contenteditable` attribute |
| 80 | +- **Features**: Native editing, `execCommand()` for formatting, `input` events, works on any element |
| 81 | + |
| 82 | +--- |
| 83 | + |
| 84 | +### Priority 3: Semantic Structure |
| 85 | + |
| 86 | +Stop using divs for everything. Semantic elements improve SEO, accessibility, and code clarity. |
| 87 | + |
| 88 | +#### Page Layout |
| 89 | +- **JS Problem**: Generic div soup with ARIA roles bolted on |
| 90 | +- **HTML Solution**: `<header>`, `<nav>`, `<main>`, `<article>`, `<section>`, `<aside>`, `<footer>` |
| 91 | +- **Features**: Implicit ARIA landmarks, screen reader navigation, document outline |
| 92 | + |
| 93 | +#### Content Grouping |
| 94 | +- **JS Problem**: Complex image galleries with caption management |
| 95 | +- **HTML Solution**: `<figure>` and `<figcaption>` |
| 96 | +- **Features**: Semantic association, works for images, code blocks, quotes, diagrams |
| 97 | + |
| 98 | +#### Data Tables |
| 99 | +- **JS Problem**: JavaScript table libraries for basic tabular data |
| 100 | +- **HTML Solution**: `<table>` with `<caption>`, `<thead>`, `<tbody>`, `<tfoot>`, `<th scope>` |
| 101 | +- **Features**: Proper screen reader navigation, sortable via CSS `:nth-child`, responsive with minimal CSS |
| 102 | + |
| 103 | +#### Form Grouping |
| 104 | +- **JS Problem**: Custom form sections with manual labeling |
| 105 | +- **HTML Solution**: `<fieldset>` and `<legend>` |
| 106 | +- **Features**: Visual grouping, semantic association, disabled state propagation to all children |
| 107 | + |
| 108 | +#### Description Lists |
| 109 | +- **JS Problem**: Custom key-value displays with divs |
| 110 | +- **HTML Solution**: `<dl>`, `<dt>`, `<dd>` |
| 111 | +- **Features**: Semantic term-definition pairs, multiple definitions per term, metadata display |
| 112 | + |
| 113 | +--- |
12 | 114 |
|
13 | | -### 🎯 Collapsible Content |
14 | | -- **JavaScript Problem**: Complex event handling, manual ARIA management, broken accessibility |
15 | | -- **HTML Solution**: `<details>` and `<summary>` elements with built-in keyboard navigation and screen reader support |
| 115 | +### Priority 4: Interactive Features |
16 | 116 |
|
17 | | -### 🪟 Modal Dialogs |
18 | | -- **JavaScript Problem**: Focus trapping, ESC key handling, backdrop clicks, memory leaks |
19 | | -- **HTML Solution**: Native `<dialog>` element with automatic focus management and ARIA semantics |
| 117 | +Modern HTML and CSS features that replace JavaScript interactions. |
20 | 118 |
|
21 | | -### 📝 Form Validation |
22 | | -- **JavaScript Problem**: Custom regex patterns, manual error display, inconsistent UX |
23 | | -- **HTML Solution**: HTML5 input types (`email`, `url`, `tel`) with built-in validation and proper error handling |
| 119 | +#### Popover & Tooltips |
| 120 | +- **JS Problem**: Tippy.js, Floating UI, z-index management, positioning logic |
| 121 | +- **HTML Solution**: `popover` attribute with `popovertarget` |
| 122 | +- **Features**: Auto-positioning, light dismiss, no JS required, anchor positioning (coming) |
24 | 123 |
|
25 | | -### 📊 Progress Indicators |
26 | | -- **JavaScript Problem**: Manual width calculations, custom ARIA updates, animation performance issues |
27 | | -- **HTML Solution**: Native `<progress>` element with semantic meaning and automatic screen reader announcements |
| 124 | +#### Scroll Snap |
| 125 | +- **JS Problem**: Carousel libraries, swipe handling, momentum physics |
| 126 | +- **HTML Solution**: CSS `scroll-snap-type` and `scroll-snap-align` |
| 127 | +- **Features**: Native momentum, touch-optimized, keyboard scrollable, works with any layout |
28 | 128 |
|
29 | | -### 📅 Date Pickers |
30 | | -- **JavaScript Problem**: Massive libraries (jQuery UI), complex keyboard navigation, mobile UX issues |
31 | | -- **HTML Solution**: Native date inputs (`date`, `datetime-local`, `time`, `month`, `week`) with OS integration |
| 129 | +#### Lazy Loading |
| 130 | +- **JS Problem**: Intersection Observer wrappers, placeholder images |
| 131 | +- **HTML Solution**: `loading="lazy"` on `<img>` and `<iframe>` |
| 132 | +- **Features**: Browser-managed, viewport-aware, no layout shift with proper dimensions |
32 | 133 |
|
33 | | -### 🪗 Accordions |
34 | | -- **JavaScript Problem**: Framework overkill, complex state management, massive bundle sizes |
35 | | -- **HTML Solution**: `<details>`/`<summary>` elements with zero JavaScript required |
| 134 | +#### Responsive Images |
| 135 | +- **JS Problem**: JavaScript-based responsive image loading |
| 136 | +- **HTML Solution**: `<picture>`, `srcset`, `sizes` |
| 137 | +- **Features**: Art direction, format selection (WebP/AVIF), resolution switching |
36 | 138 |
|
37 | | -### 🔍 Search & Autocomplete |
38 | | -- **JavaScript Problem**: Custom dropdown management, keyboard navigation bugs, focus issues |
39 | | -- **HTML Solution**: `<datalist>` element with native OS integration and built-in accessibility |
| 139 | +#### Anchor Links & Scroll |
| 140 | +- **JS Problem**: Smooth scroll libraries, scroll position management |
| 141 | +- **HTML Solution**: `id` + `<a href="#id">` with CSS `scroll-behavior: smooth` |
| 142 | +- **Features**: Deep linking, browser history, keyboard accessible |
40 | 143 |
|
41 | | -## Key Benefits of Native HTML |
| 144 | +#### Disclosure Widgets |
| 145 | +- **JS Problem**: FAQ accordions, expandable cards |
| 146 | +- **HTML Solution**: `<details open>` with `<summary>` |
| 147 | +- **Features**: Initial state control, toggle events, exclusive groups |
42 | 148 |
|
43 | | -- ✅ **Zero JavaScript dependencies** |
44 | | -- ✅ **Built-in accessibility and ARIA support** |
45 | | -- ✅ **Consistent cross-browser behavior** |
46 | | -- ✅ **SEO-friendly semantic markup** |
47 | | -- ✅ **Progressive enhancement ready** |
48 | | -- ✅ **Reduced bundle sizes and faster loading** |
49 | | -- ✅ **Native keyboard navigation** |
50 | | -- ✅ **Screen reader compatibility out of the box** |
| 149 | +--- |
| 150 | + |
| 151 | +### Priority 5: Accessibility & Enhancement |
| 152 | + |
| 153 | +Native HTML features that improve accessibility without ARIA. |
| 154 | + |
| 155 | +#### Abbreviations |
| 156 | +- **JS Problem**: Custom tooltip implementations for acronyms |
| 157 | +- **HTML Solution**: `<abbr title="...">` |
| 158 | +- **Features**: Browser/OS native tooltip, screen reader expansion |
| 159 | + |
| 160 | +#### Quotations |
| 161 | +- **JS Problem**: Styled blockquotes with attribution divs |
| 162 | +- **HTML Solution**: `<blockquote cite="">`, `<q>`, `<cite>` |
| 163 | +- **Features**: Semantic quotes, automatic quotation marks for `<q>`, citation links |
| 164 | + |
| 165 | +#### Text Highlighting |
| 166 | +- **JS Problem**: Custom search highlighting with spans |
| 167 | +- **HTML Solution**: `<mark>` |
| 168 | +- **Features**: Semantic highlighting, default yellow background, screen reader announcement |
| 169 | + |
| 170 | +#### Time & Dates |
| 171 | +- **JS Problem**: Human-readable dates with hidden ISO values |
| 172 | +- **HTML Solution**: `<time datetime="...">` |
| 173 | +- **Features**: Machine-readable dates, search engine understanding, localization potential |
| 174 | + |
| 175 | +#### Data Attributes |
| 176 | +- **JS Problem**: Storing data in hidden inputs or global JS objects |
| 177 | +- **HTML Solution**: `data-*` attributes |
| 178 | +- **Features**: DOM-accessible via `dataset`, CSS targeting via `[data-*]`, no JS required for basic use |
| 179 | + |
| 180 | +#### Meter vs Progress |
| 181 | +- **JS Problem**: Confusing gauges vs loading states |
| 182 | +- **HTML Solution**: `<meter>` for measurements, `<progress>` for tasks |
| 183 | +- **Features**: `<meter>` has `low/high/optimum`, color changes automatically, semantic distinction |
| 184 | + |
| 185 | +--- |
| 186 | + |
| 187 | +### Priority 6: Media & Embedding |
| 188 | + |
| 189 | +Native solutions for media handling. |
| 190 | + |
| 191 | +#### Video & Audio |
| 192 | +- **JS Problem**: Custom players (Video.js, Plyr) |
| 193 | +- **HTML Solution**: `<video>` and `<audio>` with `controls` |
| 194 | +- **Features**: Native controls, `<track>` for captions, `<source>` for formats, poster images |
| 195 | + |
| 196 | +#### Embedded SVG |
| 197 | +- **JS Problem**: Icon libraries, SVG sprite management |
| 198 | +- **HTML Solution**: Inline `<svg>` or `<img src="*.svg">` |
| 199 | +- **Features**: CSS styling for inline SVG, accessibility via `<title>` and `<desc>`, animation with CSS/SMIL |
| 200 | + |
| 201 | +#### Picture-in-Picture |
| 202 | +- **JS Problem**: Custom floating video implementations |
| 203 | +- **HTML Solution**: `<video>` with `requestPictureInPicture()` |
| 204 | +- **Features**: OS-level floating, works while navigating away, minimal JS |
| 205 | + |
| 206 | +#### Responsive iframes |
| 207 | +- **JS Problem**: Aspect ratio calculations |
| 208 | +- **HTML Solution**: `<iframe>` with CSS `aspect-ratio` |
| 209 | +- **Features**: Native aspect ratio, lazy loading, permission policies |
| 210 | + |
| 211 | +--- |
| 212 | + |
| 213 | +## CSS-Only Solutions |
| 214 | + |
| 215 | +These patterns often use JavaScript but can be achieved with pure CSS: |
| 216 | + |
| 217 | +| Pattern | CSS Solution | |
| 218 | +|---------|--------------| |
| 219 | +| Dropdowns | `:focus-within` + sibling selectors | |
| 220 | +| Tabs | Radio buttons + `:checked` + adjacent sibling | |
| 221 | +| Dark Mode | `prefers-color-scheme` + CSS custom properties | |
| 222 | +| Sticky Headers | `position: sticky` | |
| 223 | +| Parallax | `background-attachment: fixed` or `scroll-timeline` | |
| 224 | +| Animations | `@keyframes` + `transition` | |
| 225 | +| Tooltips | `::before/::after` + `:hover/:focus` | |
| 226 | +| Hamburger Toggle | Checkbox + `:checked` + label | |
| 227 | +| Counters | CSS `counter()` for numbered lists | |
| 228 | +| Feature Detection | `@supports` queries | |
| 229 | + |
| 230 | +--- |
| 231 | + |
| 232 | +## Key Benefits |
| 233 | + |
| 234 | +- **Zero JavaScript dependencies** for core functionality |
| 235 | +- **Built-in accessibility** - ARIA semantics included |
| 236 | +- **Cross-browser consistency** - browser-tested implementations |
| 237 | +- **SEO-friendly** - semantic markup understood by crawlers |
| 238 | +- **Progressive enhancement** - works without JS, enhanced with it |
| 239 | +- **Reduced bundle size** - no framework overhead |
| 240 | +- **Native keyboard navigation** - Tab, Enter, Space, Escape |
| 241 | +- **Screen reader compatibility** - out of the box |
| 242 | +- **Mobile optimized** - touch-friendly native controls |
| 243 | +- **Future-proof** - platform standards outlast frameworks |
| 244 | + |
| 245 | +--- |
51 | 246 |
|
52 | 247 | ## Philosophy |
53 | 248 |
|
54 | 249 | > "The best code is no code. The second best code is semantic HTML that leverages decades of browser engineering and accessibility research." |
55 | 250 |
|
56 | 251 | Stop fighting the platform. HTML already solved these problems. Embrace semantic markup and progressive enhancement for a better, more accessible web. |
57 | 252 |
|
| 253 | +--- |
| 254 | + |
| 255 | +## Resources |
| 256 | + |
| 257 | +- [Code Crispies](https://codecrispi.es/) - Interactive HTML/CSS learning platform |
| 258 | +- [MDN Web Docs](https://developer.mozilla.org/) - Definitive HTML reference |
| 259 | +- [Can I Use](https://caniuse.com/) - Browser support tables |
| 260 | +- [The HTML Spec](https://html.spec.whatwg.org/) - Living standard |
| 261 | + |
| 262 | +--- |
| 263 | + |
58 | 264 | ## Getting Started |
59 | 265 |
|
60 | 266 | ```bash |
61 | 267 | npm start |
62 | 268 | ``` |
63 | 269 |
|
64 | | -Serves the demo on `http://localhost:1312` |
| 270 | +Serves the demo on `http://localhost:1312` |
| 271 | + |
| 272 | +--- |
65 | 273 |
|
66 | 274 | ## The Choice |
67 | 275 |
|
68 | 276 | - Continue fighting the platform with complex JavaScript implementations |
69 | 277 | - **Or embrace the zen of semantic HTML and progressive enhancement** |
70 | 278 |
|
71 | | -The web platform is your friend. Stop reinventing the wheel. |
| 279 | +The web platform is your friend. Stop reinventing the wheel. |
0 commit comments