-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
473 lines (431 loc) · 23.3 KB
/
index.html
File metadata and controls
473 lines (431 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>APCA + WCAG 2 Contrast Checker</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description"
content="Compare APCA and WCAG 2.x contrast, see previews, and explore suggestions for foreground, background, and focus colors.">
<meta name="color-scheme" content="light dark">
<!-- Open Graph / Social Media Meta Tags -->
<meta property="og:type" content="website">
<meta property="og:title" content="APCA + WCAG 2 Contrast Checker">
<meta property="og:description" content="A practical tool to evaluate color contrast with both APCA and WCAG 2.x standards. Compare metrics, preview text states, and find accessible color combinations.">
<meta property="og:url" content="https://mgifford.github.io/contrast-plus/">
<meta property="og:image" content="https://mgifford.github.io/contrast-plus/accessibility.svg">
<meta property="og:image:alt" content="Contrast Plus - APCA and WCAG Contrast Checker">
<meta property="og:site_name" content="Contrast Plus">
<!-- Twitter Card Meta Tags -->
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="APCA + WCAG 2 Contrast Checker">
<meta name="twitter:description" content="Compare APCA and WCAG 2.x contrast metrics. Preview accessible color combinations and find suggestions that meet both standards.">
<meta name="twitter:image" content="https://mgifford.github.io/contrast-plus/accessibility.svg">
<meta name="twitter:image:alt" content="Contrast Plus - APCA and WCAG Contrast Checker">
<!-- Additional SEO Meta Tags -->
<meta name="keywords" content="contrast, WCAG, APCA, accessibility, color, contrast ratio, a11y, web accessibility, design">
<meta name="author" content="Mike Gifford">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<a class="skip-link" href="#fgText">Skip to main</a>
<main id="main" class="page" data-sim="normal">
<header class="page-header">
<div class="header-top">
<div class="header-title-group">
<img src="logo.svg" alt="Contrast Plus" class="page-logo">
<h1>APCA + WCAG 2 Contrast Checker</h1>
</div>
<button id="theme-toggle" type="button" aria-label="Switch to dark mode">
<svg aria-hidden="true" class="theme-icon sun-icon" viewBox="0 0 24 24" width="20" height="20">
<circle cx="12" cy="12" r="5" fill="currentColor"/>
<path fill="currentColor" d="M12 1v3M12 20v3M4.22 4.22l2.12 2.12M17.66 17.66l2.12 2.12M1 12h3M20 12h3M4.22 19.78l2.12-2.12M17.66 6.34l2.12-2.12" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
</svg>
<svg aria-hidden="true" class="theme-icon moon-icon" viewBox="0 0 24 24" width="20" height="20">
<path fill="currentColor" d="M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z"/>
</svg>
</button>
</div>
<p>
Enter colors using any modern CSS color format supported by your browser. This tool evaluates <a href="https://www.w3.org/TR/WCAG22/#contrast-minimum">WCAG 2.x</a> & <a href="https://apcacontrast.com/">APCA Lc</a> contrast ratios.
</p>
</header>
<div class="app-layout">
<div class="col-inputs">
<section class="panel" aria-labelledby="inputs-heading">
<h2 id="inputs-heading">Inputs</h2>
<div class="input-row">
<div class="color-group">
<h3>Foreground</h3>
<div class="field">
<label for="fgText">Color value</label>
<input id="fgText" class="text-input" type="text" value="#45ad7f" autocomplete="off" aria-describedby="colorExamples">
</div>
<div class="field">
<label class="visually-hidden" for="fgPicker">Foreground color picker</label>
<div class="picker-row">
<div class="mini-group">
<div class="mini-label">Picker</div>
<input id="fgPicker" class="color-input" type="color" value="#45ad7f">
</div>
<div class="mini-group" aria-hidden="false">
<div class="mini-label">Nudge</div>
<button type="button" id="fgLighter" class="mini-btn" title="Make foreground darker" aria-label="Make foreground darker">+</button>
<button type="button" id="fgDarker" class="mini-btn" title="Make foreground lighter" aria-label="Make foreground lighter">−</button>
</div>
<div class="mini-group">
<div class="mini-label">Random</div>
<button type="button" id="randomFgDark" class="mini-btn" title="Random darker foreground" aria-label="Random darker foreground">Dark</button>
<button type="button" id="randomFgLight" class="mini-btn" title="Random lighter foreground" aria-label="Random lighter foreground">Light</button>
</div>
<button type="button" id="saveFg" class="small-btn picker-save" title="Save foreground color">Save</button>
</div>
</div>
</div>
<div class="swap-btn-container">
<button type="button" id="swapColors" class="swap-btn" title="Swap foreground and background colors" aria-label="Swap foreground and background colors">
<svg aria-hidden="true" viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M7 16V4m0 0L3 8m4-4 4 4"/>
<path d="M17 8v12m0 0 4-4m-4 4-4-4"/>
</svg>
Swap
</button>
</div>
<div class="color-group">
<h3>Background</h3>
<div class="field">
<label for="bgText">Color value</label>
<input id="bgText" class="text-input" type="text" value="hsl(159.43, 33.98%, 20.2%)" autocomplete="off">
</div>
<div class="field">
<label class="visually-hidden" for="bgPicker">Background color picker</label>
<div class="picker-row">
<div class="mini-group">
<div class="mini-label">Picker</div>
<input id="bgPicker" class="color-input" type="color" value="hsl(159.43, 33.98%, 20.2%)">
</div>
<div class="mini-group">
<div class="mini-label">Nudge</div>
<button type="button" id="bgLighter" class="mini-btn" title="Make background darker" aria-label="Make background darker">+</button>
<button type="button" id="bgDarker" class="mini-btn" title="Make background lighter" aria-label="Make background lighter">−</button>
</div>
<div class="mini-group">
<div class="mini-label">Random</div>
<button type="button" id="randomBgDark" class="mini-btn" title="Random darker background" aria-label="Random darker background">Dark</button>
<button type="button" id="randomBgLight" class="mini-btn" title="Random lighter background" aria-label="Random lighter background">Light</button>
</div>
<button type="button" id="saveBg" class="small-btn picker-save" title="Save background color">Save</button>
</div>
</div>
</div>
<div class="color-group">
<h3>Focus color</h3>
<label class="field checkbox-field">
<input id="enableThird" type="checkbox">
<span>Enable focus/hover color</span>
</label>
<div id="thirdContainer" class="third-container hidden">
<div class="field">
<label for="thirdText">Focus color value</label>
<input id="thirdText" class="text-input" type="text"
value="rebeccapurple" autocomplete="off">
</div>
<div class="field">
<label class="visually-hidden" for="thirdPicker">Focus color picker</label>
<div class="picker-row">
<div class="mini-group">
<div class="mini-label">Picker</div>
<input id="thirdPicker" class="color-input" type="color" value="#663399">
</div>
<div class="mini-group">
<div class="mini-label">Nudge</div>
<button type="button" id="thirdLighter" class="mini-btn" title="Make focus color darker" aria-label="Make focus color darker">+</button>
<button type="button" id="thirdDarker" class="mini-btn" title="Make focus color lighter" aria-label="Make focus color lighter">−</button>
</div>
<div class="mini-group">
<div class="mini-label">Random</div>
<button type="button" id="randomThirdDark" class="mini-btn" title="Random darker focus color" aria-label="Random darker focus color">Dark</button>
<button type="button" id="randomThirdLight" class="mini-btn" title="Random lighter focus color" aria-label="Random lighter focus color">Light</button>
</div>
<button type="button" id="saveThird" class="small-btn picker-save" title="Save focus color">Save</button>
<button type="button" id="findBestFocus" class="small-btn picker-find" title="Suggest focus color" aria-label="Suggest focus color">Suggestion</button>
</div>
</div>
<div id="focusCandidates" class="focus-candidates small" aria-live="polite"></div>
</div>
</div>
</div>
<p id="colorExamples" class="small"><i>
<b>Examples:</b> <code>pink</code>, <code>#0044cc</code>, <code>rgb(10 120 200)</code>,
<code>hsl(200 40% 40%)</code>, <code>lch(60 50 240)</code> & <code>oklch(0.7 0.16 250)</code>
</i></p>
<fieldset class="input-row thresholds-row">
<legend class="visually-hidden">Contrast thresholds</legend>
<div class="threshold-group">
<h3>WCAG 2.x threshold</h3>
<label>
<span>Target ratio</span>
<select id="wcagThreshold">
<option value="4.5">4.5:1 (AA normal text)</option>
<option value="3">3:1 (AA large text or UI)</option>
<option value="7">7:1 (AAA)</option>
</select>
</label>
</div>
<div class="threshold-group">
<h3>APCA threshold</h3>
<label>
<span>Target Lc</span>
<select id="apcaThreshold">
<option value="60">Lc 60 – body text (≥16 px, normal weight)</option>
<option value="45">Lc 45 – large text or UI (≥24 px or bold)</option>
<option value="75">Lc 75 – small text (14–15 px, normal weight)</option>
<option value="90">Lc 90 – very small or placeholder text</option>
</select>
</label>
</div>
</fieldset>
</section>
</div><!-- /.col-inputs -->
<div class="col-results">
<section class="panel" aria-labelledby="results-heading">
<h2 id="results-heading">Results</h2>
<div id="errorBox" class="error-box hidden" role="alert" aria-live="assertive"></div>
<table class="results-table">
<thead>
<tr>
<th scope="col">Pair</th>
<th scope="col">Colors</th>
<th scope="col">WCAG ratio</th>
<th scope="col">WCAG status</th>
<th scope="col">APCA Lc</th>
<th scope="col">APCA status</th>
</tr>
</thead>
<tbody id="resultsBody">
<!-- Filled by JS -->
</tbody>
</table>
<div id="focusSummary" class="focus-summary hidden">
<h3>Focus appearance (WCAG 2.2 2.4.13)</h3>
<p id="focusText"></p>
</div>
</section>
<section class="panel" aria-labelledby="preview-heading">
<h2 id="preview-heading">Preview</h2>
<div class="preview-controls">
<span class="small">View preview as:</span>
<fieldset class="sim-toggle-group">
<legend class="visually-hidden">Color vision simulation</legend>
<button type="button" class="sim-toggle btn-primary sim-toggle-active" data-sim="normal" aria-pressed="true">Normal</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="grayscale" aria-pressed="false">Grayscale</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="protanopia" aria-pressed="false">Protanopia</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="deuteranopia" aria-pressed="false">Deuteranopia</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="tritanopia" aria-pressed="false">Tritanopia</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="low-vision" aria-pressed="false">Low Vision</button>
<button type="button" class="sim-toggle btn-secondary" data-sim="older-vision" aria-pressed="false">Older Vision (65+)</button>
<!-- Hide not working
<button type="button" class="sim-toggle btn-secondary" data-sim="screen-glare" aria-pressed="false">Screen Glare</button>
-->
</fieldset>
</div>
<p class="small">
Both panels use your chosen colors for headings, body text, links, buttons, and simple icons.
The second panel shows focus and hover states using the third color when enabled.
</p>
<div class="preview-grid">
<div class="preview-card">
<h3>Foreground on background</h3>
<div id="previewBase" class="preview-box">
<h4 id="demoHeadingBase">Example heading</h4>
<p>
The quick brown fox jumps over the lazy dog. 1234567890.
This paragraph uses the chosen foreground and background colors.
</p>
<p>
<a id="demoLinkBase" href="#">Example link text</a>
</p>
<div class="button-variants">
<button type="button" class="btn btn-text">Text</button>
<button type="button" class="btn btn-ghost">Ghost</button>
<button type="button" class="btn btn-filled">Filled</button>
<button type="button" class="btn btn-raised">Raised</button>
</div>
<div id="barChartContainer" class="bar-chart" aria-hidden="true"></div>
<div id="previewSavedIconsBase" class="preview-saved-icons" aria-hidden="false"></div>
</div>
</div>
<div id="previewThirdCard" class="preview-card hidden">
<h3>Focus states exposed</h3>
<div id="previewThird" class="preview-box">
<h4 id="demoHeadingThird">Focus state example</h4>
<p>
This area shows how a focus or hover state could look against the
background using your third color, contrasted with the main foreground.
</p>
<p>
<a id="demoLinkThird" href="#">Focused link example</a>
</p>
<div class="button-variants">
<button type="button" class="btn btn-text">Text</button>
<button type="button" class="btn btn-ghost">Ghost</button>
<button type="button" class="btn btn-filled">Filled</button>
<button type="button" class="btn btn-raised">Raised</button>
</div>
<div id="barChartContainerThird" class="bar-chart" aria-hidden="true"></div>
<div id="previewSavedIconsThird" class="preview-saved-icons" aria-hidden="false"></div>
</div>
</div>
</div>
</section>
<section id="suggestSection" class="panel hidden" aria-labelledby="suggest-heading">
<h2 id="suggest-heading">Suggested colors that move toward both targets</h2>
<p class="small">
These suggestions adjust lightness (and, if needed, hue) to find nearby colors that
always satisfy the chosen WCAG ratio and, where possible, also meet the APCA target while staying close to your chosen colors.
</p>
<div id="suggestionBox" class="suggestion-box">
<div class="suggest-controls small">
<label class="field checkbox-field">
<input id="allowWcagOnly" type="checkbox">
<span>Allow WCAG-only suggestions (ignore APCA target)</span>
</label>
</div>
<div id="fgSuggestionBlock" class="suggest-block">
<h3>Adjust foreground (keep background)</h3>
<div id="fgSuggestions" class="swatches"></div>
<p id="fgSuggestionStatus" class="small muted" aria-live="polite"></p>
</div>
<div id="bgSuggestionBlock" class="suggest-block">
<h3>Adjust background (keep foreground)</h3>
<div id="bgSuggestions" class="swatches"></div>
<p id="bgSuggestionStatus" class="small muted" aria-live="polite"></p>
</div>
<div id="thirdSuggestionBlock" class="suggest-block hidden">
<h3>Third or focus color on background</h3>
<div id="thirdSuggestions" class="swatches"></div>
<p id="thirdSuggestionStatus" class="small muted" aria-live="polite"></p>
</div>
<p class="small" id="suggestionStatus"></p>
</div>
</section>
</div><!-- /.col-results -->
</div><!-- /.app-layout -->
<section class="panel" aria-labelledby="harmony-heading">
<h2 id="harmony-heading">Harmony Palette Generator</h2>
<p class="small">Generate a 5-color harmonious palette based on the current foreground color. (No external API used.)</p>
<div class="harmony-controls">
<button type="button" id="harmonyButton">Generate Harmony Palette</button>
<div id="harmonyNote" class="small muted">Harmony is generated by rotating hue and adjusting lightness/saturation from the foreground color to produce visually distinct but related swatches.</div>
</div>
<div id="harmonyOutput" class="harmony-grid" aria-live="polite"></div>
<h3 id="tonal-heading" class="tonal-subheading">Tonal Scale (50–950)</h3>
<p class="small">Generate a full tonal scale from the foreground color hue, varying lightness across 11 stops. Inspired by enterprise design system palettes.</p>
<div class="tonal-controls">
<button type="button" id="tonalButton">Generate Tonal Scale</button>
<div class="tonal-tint-group">
<div id="tintDesc" class="small muted">Blend the tonal scale with a brand tint color to create a cohesive palette. Set intensity to 0 for no tint.</div>
<label for="tintColor">Cohesive tint color</label>
<input type="color" id="tintColor" value="#6366f1" aria-describedby="tintDesc">
<label for="tintIntensity">Tint intensity</label>
<input type="range" id="tintIntensity" min="0" max="100" value="0" step="5" aria-describedby="tintDesc">
<output id="tintIntensityDisplay" for="tintIntensity">0%</output>
</div>
</div>
<section id="tonalOutput" class="tonal-grid" aria-live="polite" aria-label="Tonal scale swatches"></section>
<h3 id="matrix-heading" class="tonal-subheading">Accessible Contrast Matrix</h3>
<p class="small">Compare each tonal swatch against the current background color to see which combinations meet WCAG 2.x and APCA thresholds. Generate the tonal scale first.</p>
<section id="contrast-matrix-output" class="contrast-matrix-wrap" aria-live="polite" aria-label="Accessible contrast matrix"></section>
</section>
<section class="panel" aria-labelledby="saved-heading">
<h2 id="saved-heading">Saved Color Palette (<span id="paletteCount">0</span>)</h2>
<div id="paletteContainer" class="palette-list">
<p id="palettePlaceholder" class="small italic">No saved colors yet. Use the Save buttons near color inputs.</p>
<div class="palette-footer">
<button type="button" id="clearPalette">Clear all</button>
<button type="button" id="copyPalette">Copy palette</button>
</div>
</div>
</section>
<div id="liveRegion" class="visually-hidden" aria-live="polite" aria-atomic="true"></div>
<footer class="page-footer">
<p>
WCAG 2.x contrast uses the luminance formula defined in WCAG 2.2 (sRGB threshold 0.04045, per IEC 61966-2-1). APCA is loaded via a separate script;
if it fails to load, APCA results show <code>n/a</code>. Color simulations are approximate
and for visual exploration only.
</p>
<p>
This project is open source. View the code on <a href="https://github.com/mgifford/contrast-plus/">GitHub</a>.
</p>
<!-- Social Sharing Section -->
<div class="social-share">
<p>Share this tool:</p>
<div class="social-buttons">
<a class="social-btn linkedin"
href="https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fmgifford.github.io%2Fcontrast-plus%2F"
target="_blank"
rel="noopener noreferrer"
title="Share on LinkedIn"
aria-label="Share on LinkedIn">
<span>LinkedIn</span>
</a>
<a class="social-btn bluesky"
href="https://bsky.app/intent/compose?text=Check%20out%20the%20APCA%20%2B%20WCAG%202%20Contrast%20Checker%20-%20a%20practical%20tool%20for%20evaluating%20color%20contrast%20with%20both%20standards%0Ahttps%3A%2F%2Fmgifford.github.io%2Fcontrast-plus%2F"
target="_blank"
rel="noopener noreferrer"
title="Share on Bluesky"
aria-label="Share on Bluesky">
<span>Bluesky</span>
</a>
<a class="social-btn mastodon"
href="https://mastodonshare.com/?text=Check%20out%20the%20APCA%20%2B%20WCAG%202%20Contrast%20Checker%20-%20a%20practical%20tool%20for%20evaluating%20color%20contrast%20with%20both%20standards&url=https%3A%2F%2Fmgifford.github.io%2Fcontrast-plus%2F"
target="_blank"
rel="noopener noreferrer"
title="Share on Mastodon"
aria-label="Share on Mastodon">
<span>Mastodon</span>
</a>
</div>
</div>
<!-- Bluesky Footer -->
<section class="post__likes" data-bsky-container data-bsky-post-id="3m6xjotww3k2j">
<h3 class="post__likesTitle">
🦋 <span data-bsky-likes-count></span> likes on Bluesky
</h3>
<a class="post__likesCta" href="https://bsky.app/profile/ox.ca/post/3m6xjotww3k2j" target="_blank">
Like this post on Bluesky to see your face on this page
</a>
<ul data-bsky-likes class="post__likesList"></ul>
</section>
</footer>
</main>
<svg aria-hidden="true" class="visually-hidden">
<defs>
<!-- Approximate color blindness simulation filters -->
<!-- For more information see: https://ixora.io/projects/colorblindness/color-blindness-simulation-research -->
<filter id="sim-protanopia">
<feColorMatrix type="matrix" values="
0.567 0.433 0 0 0
0.558 0.442 0 0 0
0 0.242 0.758 0 0
0 0 0 1 0" />
</filter>
<filter id="sim-deuteranopia">
<feColorMatrix type="matrix" values="
0.625 0.375 0 0 0
0.7 0.3 0 0 0
0 0.3 0.7 0 0
0 0 0 1 0" />
</filter>
<filter id="sim-tritanopia">
<feColorMatrix type="matrix" values="
0.95 0.05 0 0 0
0 0.433 0.567 0 0
0 0.475 0.525 0 0
0 0 0 1 0" />
</filter>
</defs>
</svg>
<script type="module" src="app.js"></script>
<script type="module" src="bluesky-likes.js"></script>
</body>
</html>