-
Notifications
You must be signed in to change notification settings - Fork 12
/
glance.html
635 lines (582 loc) · 47.3 KB
/
glance.html
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
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
<!DOCTYPE html><html lang="en"><head>
<meta charset="utf-8">
<meta name="generator" content="ReSpec 35.1.1">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<style>
dfn{cursor:pointer}
.dfn-panel{position:absolute;z-index:35;min-width:300px;max-width:500px;padding:.5em .75em;margin-top:.6em;font-family:"Helvetica Neue",sans-serif;font-size:small;background:#fff;background:var(--indextable-hover-bg,#fff);color:#000;color:var(--text,#000);box-shadow:0 1em 3em -.4em rgba(0,0,0,.3),0 0 1px 1px rgba(0,0,0,.05);box-shadow:0 1em 3em -.4em var(--tocsidebar-shadow,rgba(0,0,0,.3)),0 0 1px 1px var(--tocsidebar-shadow,rgba(0,0,0,.05));border-radius:2px}
.dfn-panel:not(.docked)>.caret{position:absolute;top:-9px}
.dfn-panel:not(.docked)>.caret::after,.dfn-panel:not(.docked)>.caret::before{content:"";position:absolute;border:10px solid transparent;border-top:0;border-bottom:10px solid #fff;border-bottom-color:var(--indextable-hover-bg,#fff);top:0}
.dfn-panel:not(.docked)>.caret::before{border-bottom:9px solid #a2a9b1;border-bottom-color:var(--indextable-hover-bg,#a2a9b1)}
.dfn-panel *{margin:0}
.dfn-panel b{display:block;color:#000;color:var(--text,#000);margin-top:.25em}
.dfn-panel ul a[href]{color:#333;color:var(--text,#333)}
.dfn-panel>div{display:flex}
.dfn-panel a.self-link{font-weight:700;margin-right:auto}
.dfn-panel .marker{padding:.1em;margin-left:.5em;border-radius:.2em;text-align:center;white-space:nowrap;font-size:90%;color:#040b1c}
.dfn-panel .marker.dfn-exported{background:#d1edfd;box-shadow:0 0 0 .125em #1ca5f940}
.dfn-panel .marker.idl-block{background:#8ccbf2;box-shadow:0 0 0 .125em #0670b161}
.dfn-panel a:not(:hover){text-decoration:none!important;border-bottom:none!important}
.dfn-panel a[href]:hover{border-bottom-width:1px}
.dfn-panel ul{padding:0}
.dfn-panel li{margin-left:1em}
.dfn-panel.docked{position:fixed;left:.5em;top:unset;bottom:2em;margin:0 auto;max-width:calc(100vw - .75em * 2 - .5em - .2em * 2);max-height:30vh;overflow:auto}
</style>
<title>Web Sustainability Guidelines (WSG) 1.0 at a Glance</title>
<style id="respec-mainstyle">
@keyframes pop{
0%{transform:scale(1,1)}
25%{transform:scale(1.25,1.25);opacity:.75}
100%{transform:scale(1,1)}
}
a.internalDFN{color:inherit;border-bottom:1px solid #99c;text-decoration:none}
a.externalDFN{color:inherit;border-bottom:1px dotted #ccc;text-decoration:none}
a.bibref{text-decoration:none}
.respec-offending-element:target{animation:pop .25s ease-in-out 0s 1}
.respec-offending-element,a[href].respec-offending-element{text-decoration:red wavy underline}
@supports not (text-decoration:red wavy underline){
.respec-offending-element:not(pre){display:inline-block}
.respec-offending-element{background:url(data:image/gif;base64,R0lGODdhBAADAPEAANv///8AAP///wAAACwAAAAABAADAEACBZQjmIAFADs=) bottom repeat-x}
}
#references :target{background:#eaf3ff;animation:pop .4s ease-in-out 0s 1}
cite .bibref{font-style:normal}
a[href].orcid{padding-left:4px;padding-right:4px}
a[href].orcid>svg{margin-bottom:-2px}
ol.tof,ul.tof{list-style:none outside none}
.caption{margin-top:.5em;font-style:italic}
#issue-summary>ul{column-count:2}
#issue-summary li{list-style:none;display:inline-block}
details.respec-tests-details{margin-left:1em;display:inline-block;vertical-align:top}
details.respec-tests-details>*{padding-right:2em}
details.respec-tests-details[open]{z-index:999999;position:absolute;border:thin solid #cad3e2;border-radius:.3em;background-color:#fff;padding-bottom:.5em}
details.respec-tests-details[open]>summary{border-bottom:thin solid #cad3e2;padding-left:1em;margin-bottom:1em;line-height:2em}
details.respec-tests-details>ul{width:100%;margin-top:-.3em}
details.respec-tests-details>li{padding-left:1em}
.self-link:hover{opacity:1;text-decoration:none;background-color:transparent}
aside.example .marker>a.self-link{color:inherit}
.header-wrapper{display:flex;align-items:baseline}
:is(h2,h3,h4,h5,h6):not(#toc>h2,#abstract>h2,#sotd>h2,.head>h2){position:relative;left:-.5em}
:is(h2,h3,h4,h5,h6):not(#toch2)+a.self-link{color:inherit;order:-1;position:relative;left:-1.1em;font-size:1rem;opacity:.5}
:is(h2,h3,h4,h5,h6)+a.self-link::before{content:"§";text-decoration:none;color:var(--heading-text)}
:is(h2,h3)+a.self-link{top:-.2em}
:is(h4,h5,h6)+a.self-link::before{color:#000}
@media (max-width:767px){
dd{margin-left:0}
}
@media print{
.removeOnSave{display:none}
}
</style>
<meta name="color-scheme" content="light">
<meta name="description" content="This page provides a paraphrased summary of the Web Sustainability Guidelines (WSG) 1.0. For the normative technical specification, see https://w3c.github.io/sustyweb/.">
<style>
var{position:relative;cursor:pointer}
var[data-type]::after,var[data-type]::before{position:absolute;left:50%;top:-6px;opacity:0;transition:opacity .4s;pointer-events:none}
var[data-type]::before{content:"";transform:translateX(-50%);border-width:4px 6px 0 6px;border-style:solid;border-color:transparent;border-top-color:#222}
var[data-type]::after{content:attr(data-type);transform:translateX(-50%) translateY(-100%);background:#222;text-align:center;font-family:"Dank Mono","Fira Code",monospace;font-style:normal;padding:6px;border-radius:3px;color:#daca88;text-indent:0;font-weight:400}
var[data-type]:hover::after,var[data-type]:hover::before{opacity:1}
</style>
<script id="initialUserConfig" type="application/json">{
"editors": [
{
"name": "Alexander Dawson",
"url": "https://alexanderdawson.com/",
"w3cid": 49702
},
{
"name": "Ines Akrap",
"url": "https://inesakrap.com/",
"company": "Storyblok"
},
{
"name": "Mike Gifford",
"url": "https://civicactions.com/",
"company": "CivicActions"
},
{
"name": "Tim Frick",
"url": "https://www.mightybytes.com/",
"company": "Mightybytes",
"w3cid": 62394
}
],
"edDraftURI": "https://w3c.github.io/sustyweb/glance.html",
"github": "https://github.com/w3c/sustyweb/",
"group": "sustyweb",
"latestVersion": "https://w3c.github.io/sustyweb/glance.html",
"localBiblio": {
"8BT": {
"title": "Carbon Footprint of the Internet Over Time Since 1990",
"date": "18 March 2024",
"href": "https://8billiontrees.com/carbon-offsets-credits/carbon-footprint-of-the-internet/",
"status": "Informational",
"publisher": "Georgette Kilgore",
"id": "8bt"
},
"COUNTRY": {
"title": "Internet - growing to surpass television - should be powered with clean energy",
"date": "05 August 2013",
"href": "https://www.greenpeace.org/usa/internet-growing-to-suprass-television-should-be-powered-with-clean-energy/",
"status": "Informational",
"publisher": "David Pomerantz",
"id": "country"
},
"DATA": {
"title": "Data Centres and Data Transmission Networks",
"date": "11 July 2023",
"href": "https://www.iea.org/energy-system/buildings/data-centres-and-data-transmission-networks",
"status": "Informational",
"publisher": "IEA",
"id": "data"
},
"EUC": {
"title": "Questions and Answers: EU action plan on digitalising the energy system",
"date": "18 October 2022",
"href": "https://ec.europa.eu/commission/presscorner/detail/en/qanda_22_6229",
"status": "Informational",
"publisher": "EU Commission",
"id": "euc"
},
"HUMANE": {
"title": "Manifesto for a Humane Web",
"date": "13 May 2024",
"href": "https://humanewebmanifesto.com/",
"status": "Informational",
"publisher": "Michelle Barker",
"id": "humane"
},
"ICT-IMPACT": {
"title": "The real climate and transformative impact of ICT: A critique of estimates, trends, and regulations",
"date": "10 September 2021",
"href": "https://www.cell.com/patterns/pdfExtended/S2666-3899(21)00188-4",
"status": "Informational",
"publisher": "Charlotte Freitag, Mike Berners-Lee, Kelly Widdicks, Bran Knowles, Gordon S. Blair, and Adrian Friday",
"id": "ict-impact"
},
"MANIFESTO": {
"title": "Sustainable Web Manifesto",
"date": "01 May 2019",
"href": "https://www.sustainablewebmanifesto.com/",
"status": "Informational",
"publisher": "Tom Greenwood, Tim Frick, Mike Gifford, Andrew Boardman, Jack Amend, Matt Hocking, Jack Lenox, René Post, Chris Adams, James Christie, Jerome Toole, Chris Butterworth, Josh Stopper, Alex Hughes, Pete Markiewicz",
"id": "manifesto"
},
"PAGE-WEIGHT": {
"title": "Page Weight",
"date": "29 August 2023",
"href": "https://httparchive.org/reports/page-weight?start=2015_12_01&end=latest&view=list",
"status": "Informational",
"publisher": "HTTP Archive",
"id": "page-weight"
}
},
"specStatus": "CG-DRAFT",
"publishISODate": "2024-08-22T00:00:00.000Z",
"generatedSubtitle": "Draft Community Group Report 22 August 2024"
}</script>
<link rel="stylesheet" href="https://www.w3.org/StyleSheets/TR/2021/cg-draft"></head>
<body class="h-entry informative"><div class="head">
<h1 id="title" class="title">Web Sustainability Guidelines (WSG) 1.0 at a Glance</h1>
<p id="w3c-state">
<a href="https://www.w3.org/standards/types#reports">Draft Community Group Report</a>
<time class="dt-published" datetime="2024-08-22">22 August 2024</time>
</p>
<dl>
<dt>Latest published version:</dt><dd>
<a href="https://w3c.github.io/sustyweb/glance.html">https://w3c.github.io/sustyweb/glance.html</a>
</dd>
<dt>Latest editor's draft:</dt><dd><a href="https://w3c.github.io/sustyweb/glance.html">https://w3c.github.io/sustyweb/glance.html</a></dd>
<dt>Editors:</dt><dd class="editor p-author h-card vcard" data-editor-id="49702">
<a class="u-url url p-name fn" href="https://alexanderdawson.com/">Alexander Dawson</a>
</dd><dd class="editor p-author h-card vcard">
<a class="u-url url p-name fn" href="https://inesakrap.com/">Ines Akrap</a> (<span class="p-org org h-org">Storyblok</span>)
</dd><dd class="editor p-author h-card vcard">
<a class="u-url url p-name fn" href="https://civicactions.com/">Mike Gifford</a> (<span class="p-org org h-org">CivicActions</span>)
</dd><dd class="editor p-author h-card vcard" data-editor-id="62394">
<a class="u-url url p-name fn" href="https://www.mightybytes.com/">Tim Frick</a> (<span class="p-org org h-org">Mightybytes</span>)
</dd>
<dt>Feedback:</dt><dd>
<a href="https://github.com/w3c/sustyweb/">GitHub w3c/sustyweb</a>
(<a href="https://github.com/w3c/sustyweb/pulls/">pull requests</a>,
<a href="https://github.com/w3c/sustyweb/issues/new/choose">new issue</a>,
<a href="https://github.com/w3c/sustyweb/issues/">open issues</a>)
</dd>
</dl>
<p class="copyright">
<a href="https://www.w3.org/policies/#copyright">Copyright</a>
©
2024
the Contributors to the Web Sustainability Guidelines (WSG) 1.0 at a Glance
Specification, published by the
<a href="https://www.w3.org/groups/cg/sustyweb">Sustainable Web Design Community Group</a> under the
<a href="https://www.w3.org/community/about/agreements/cla/">W3C Community Contributor License Agreement (CLA)</a>. A human-readable
<a href="https://www.w3.org/community/about/agreements/cla-deed/">summary</a>
is available.
</p>
<hr title="Separator for header">
</div>
<section id="abstract" class="introductory"><h2>Abstract</h2>
<p>This page provides a paraphrased summary of the Web Sustainability Guidelines (<abbr title="Web Sustainability Guidelines">WSG</abbr>) 1.0. For the normative technical specification, see <a href="https://w3c.github.io/sustyweb/">https://w3c.github.io/sustyweb/</a>.</p>
<p>It aims to be a helpful entry point for individuals and stakeholders who have an interest in digital sustainability and the work undertaken by the <a href="https://www.w3.org/groups/cg/sustyweb">Sustainable Web Design Community Group</a>.</p>
<p>While this document does provide a quick summary of numerous key aspects of the <abbr title="Web Sustainability Guidelines">WSG</abbr> specification, it must be established that it in no way should be used as a replacement for following the guidelines and success criteria as laid out in the complete, long-form specification. Reasons for this include that this summary is neither intended to be in-depth nor feature-complete. Therefore, its role as an overview to help orientate stakeholders to the specification's purpose in no way provides conformance to Web Sustainability criteria.</p>
<p>Help improve this page by sharing your ideas, suggestions, or comments via <a href="https://github.com/w3c/sustyweb/issues/">GitHub issues</a>.</p>
</section>
<section class="informative" id="introduction"><div class="header-wrapper"><h2 id="x1-introduction"><bdi class="secno">1. </bdi>Introduction</h2><a class="self-link" href="#introduction" aria-label="Permalink for Section 1."></a></div><p><em>This section is non-normative.</em></p>
<section id="context"><div class="header-wrapper"><h3 id="x1-1-context"><bdi class="secno">1.1 </bdi>Context</h3><a class="self-link" href="#context" aria-label="Permalink for Section 1.1"></a></div>
<p>The digital industry is now responsible for between 2-5% of global emissions [<cite><a class="bibref" data-link-type="biblio" href="#bib-ict-impact" title="The real climate and transformative impact of ICT: A critique of estimates, trends, and regulations">ICT-IMPACT</a></cite>] [<cite><a class="bibref" data-link-type="biblio" href="#bib-euc" title="Questions and Answers: EU action plan on digitalising the energy system">EUC</a></cite>] [<cite><a class="bibref" data-link-type="biblio" href="#bib-8bt" title="Carbon Footprint of the Internet Over Time Since 1990">8BT</a></cite>], more than that of the aviation industry. Since the Paris Agreement, average web page sizes have increased by over 70% on desktop and 140% on mobile [<cite><a class="bibref" data-link-type="biblio" href="#bib-page-weight" title="Page Weight">PAGE-WEIGHT</a></cite>]. Between 2015 and 2021, internet visitors increased by 60%, whilst internet traffic increased by 440% [<cite><a class="bibref" data-link-type="biblio" href="#bib-data" title="Data Centres and Data Transmission Networks">DATA</a></cite>]. In essence, if the Internet were a country it would be one of the top five polluters. [<cite><a class="bibref" data-link-type="biblio" href="#bib-country" title="Internet - growing to surpass television - should be powered with clean energy">COUNTRY</a></cite>]</p>
</section>
<section id="summary"><div class="header-wrapper"><h3 id="x1-2-summary"><bdi class="secno">1.2 </bdi>Summary</h3><a class="self-link" href="#summary" aria-label="Permalink for Section 1.2"></a></div>
<p>The Web Sustainability Guidelines (<abbr title="Web Sustainability Guidelines">WSG</abbr>) 1.0 explains how to design and implement digital products and services that put people and the planet first. The guidelines are best practices based on measurable, evidence-based research; aimed at end-users, website creators, product owners, stakeholders, tool authors, educators, and policymakers. The guidelines are in line with both the Sustainable Web Manifesto [<cite><a class="bibref" data-link-type="biblio" href="#bib-manifesto" title="Sustainable Web Manifesto">MANIFESTO</a></cite>] and Manifesto for a Humane Web [<cite><a class="bibref" data-link-type="biblio" href="#bib-humane" title="Manifesto for a Humane Web">HUMANE</a></cite>].</p>
</section>
<section id="highlights"><div class="header-wrapper"><h3 id="x1-3-highlights"><bdi class="secno">1.3 </bdi>Highlights</h3><a class="self-link" href="#highlights" aria-label="Permalink for Section 1.3"></a></div>
<p>Knowing where to start, especially with a document as long and dense as the WSGs is quite a challenge. You may wish to scan through a supplement such as our <a href="https://w3c.github.io/sustyweb/quickref.html">quick reference</a> which provides a checklist-based overview of every guideline. Or if you just want a couple of important tasks you can dive right into them. If so, consider the below as a few of our highlights (though please note, that this doesn't reduce the importance of the others).</p>
<details>
<summary>Show / Hide highlights by category.</summary>
<p>The below will have a high impact on your product or service's digital sustainability:</p>
<dl>
<dt>User Experience Design</dt>
<dd><ul>
<li><a href="https://w3c.github.io/sustyweb/#assess-and-research-visitor-needs">2.2</a> - Assess and Research Visitor Needs</li>
<li><a href="https://w3c.github.io/sustyweb/#create-a-lightweight-experience-by-default">2.6</a> - Create a Lightweight Experience by Default</li>
<li><a href="https://w3c.github.io/sustyweb/#incorporate-compatibility-testing-into-each-release-cycle">2.29</a> - Incorporate Compatibility Testing Into Each Release-Cycle</li>
</ul></dd>
<dt>Web Development</dt>
<dd><ul>
<li><a href="https://w3c.github.io/sustyweb/#rigorously-assess-third-party-services">3.7</a> - Rigorously Assess Third-Party Services</li>
<li><a href="https://w3c.github.io/sustyweb/#manage-dependencies-appropriately">3.17</a> - Manage Dependencies Appropriately</li>
<li><a href="https://w3c.github.io/sustyweb/#align-technical-requirements-with-sustainability-goals">3.21</a> - Align Technical Requirements With Sustainability Goals</li>
</ul></dd>
<dt>Hosting, Infrastructure and Systems</dt>
<dd><ul>
<li><a href="https://w3c.github.io/sustyweb/#choose-a-sustainable-hosting-provider">4.1</a> - Choose a Sustainable Hosting Provider</li>
<li><a href="https://w3c.github.io/sustyweb/#optimize-browser-caching">4.2</a> - Optimize Browser Caching</li>
<li><a href="https://w3c.github.io/sustyweb/#compress-your-files">4.3</a> - Compress Your Files</li>
</ul></dd>
<dt>Business Strategy and Product Management</dt>
<dd><ul>
<li><a href="https://w3c.github.io/sustyweb/#have-an-ethical-and-sustainability-product-strategy">5.1</a> - Have an Ethical and Sustainability Product Strategy</li>
<li><a href="https://w3c.github.io/sustyweb/#estimate-a-product-or-service-s-environmental-impact">5.5</a> - Estimate a Product or Service's Environmental Impact</li>
<li><a href="https://w3c.github.io/sustyweb/#implement-continuous-improvement-procedures">5.12</a> - Implement Continuous Improvement Procedures</li>
</ul></dd>
</dl>
</details>
</section>
</section>
<section id="sotd" class="override introductory"></section><nav id="toc"><h2 class="introductory" id="table-of-contents">Table of Contents</h2><ol class="toc"><li class="tocline"><a class="tocxref" href="#abstract">Abstract</a></li><li class="tocline"><a class="tocxref" href="#introduction"><bdi class="secno">1. </bdi>Introduction</a><ol class="toc"><li class="tocline"><a class="tocxref" href="#context"><bdi class="secno">1.1 </bdi>Context</a></li><li class="tocline"><a class="tocxref" href="#summary"><bdi class="secno">1.2 </bdi>Summary</a></li><li class="tocline"><a class="tocxref" href="#highlights"><bdi class="secno">1.3 </bdi>Highlights</a></li></ol></li><li class="tocline"><a class="tocxref" href="#overview"><bdi class="secno">2. </bdi>Overview</a><ol class="toc"><li class="tocline"><a class="tocxref" href="#user-experience-design"><bdi class="secno">2.1 </bdi>User Experience Design</a></li><li class="tocline"><a class="tocxref" href="#web-development"><bdi class="secno">2.2 </bdi>Web Development</a></li><li class="tocline"><a class="tocxref" href="#hosting-infrastructure-and-systems"><bdi class="secno">2.3 </bdi>Hosting, Infrastructure and Systems</a></li><li class="tocline"><a class="tocxref" href="#business-strategy-and-product-management"><bdi class="secno">2.4 </bdi>Business Strategy and Product Management</a></li></ol></li><li class="tocline"><a class="tocxref" href="#acknowledgments"><bdi class="secno">A. </bdi>Acknowledgments</a><ol class="toc"><li class="tocline"><a class="tocxref" href="#participants-of-the-swd-cg-active-in-the-development-of-this-document"><bdi class="secno">A.1 </bdi>Participants of the SWD-CG Active in the Development of This Document</a></li></ol></li><li class="tocline"><a class="tocxref" href="#references"><bdi class="secno">B. </bdi>References</a><ol class="toc"><li class="tocline"><a class="tocxref" href="#informative-references"><bdi class="secno">B.1 </bdi>Informative references</a></li></ol></li></ol></nav>
<section id="overview"><div class="header-wrapper"><h2 id="x2-overview"><bdi class="secno">2. </bdi>Overview</h2><a class="self-link" href="#overview" aria-label="Permalink for Section 2."></a></div>
<p>The guidelines should be seen as a starting point in a sustainability journey; they cover the following:</p>
<section id="user-experience-design"><div class="header-wrapper"><h3 id="x2-1-user-experience-design"><bdi class="secno">2.1 </bdi>User Experience Design</h3><a class="self-link" href="#user-experience-design" aria-label="Permalink for Section 2.1"></a></div>
<p>Covering research and ideation, journey design, content and assets, and quality assurance.</p>
<details>
<summary>Show / Hide available guidance.</summary>
<p>In relation to <strong>research and ideation</strong>, make sure you:</p>
<ul>
<li>Map all areas where your digital product <a href="https://w3c.github.io/sustyweb/#undertake-systemic-impacts-mapping">could impact people and the planet</a>.</li>
<li>Assess all <a href="https://w3c.github.io/sustyweb/#account-for-stakeholder-issues">stakeholder issues</a> as well as <a href="https://w3c.github.io/sustyweb/#assess-and-research-visitor-needs">visitor</a> and <a href="https://w3c.github.io/sustyweb/#research-non-visitor-s-needs">non-visitor</a> needs; then define appropriate <a href="https://w3c.github.io/sustyweb/#create-a-stakeholder-focused-testing-prototyping-policy">test policies</a>.</li>
<li>Consider the use of <a href="https://w3c.github.io/sustyweb/#consider-sustainability-in-early-ideation">low-carbon tools during ideation</a>.</li>
</ul>
<p>In relation to <strong>journey design</strong>, make sure you:</p>
<ul>
<li>Create a <a href="https://w3c.github.io/sustyweb/#create-a-frictionless-lightweight-experience-by-default">frictionless, lightweight experience</a>, using <a href="https://w3c.github.io/sustyweb/#use-recognized-design-patterns">recognized design patterns</a> that ensure navigation and way-finding <a href="https://w3c.github.io/sustyweb/#ensure-navigation-and-way-finding-are-well-structured">are well-structured</a>, the visitor's <a href="https://w3c.github.io/sustyweb/#respect-the-visitor-s-attention">attention is respected</a> and <a href="https://w3c.github.io/sustyweb/#avoid-manipulative-patterns">visitors aren't manipulated</a>.</li>
<li>Implement forms that are <a href="https://w3c.github.io/sustyweb/#provide-accessible-usable-minimal-web-forms">usable, accessible, and minimal</a> and <a href="https://w3c.github.io/sustyweb/#validate-form-errors-and-external-input">assist visitors with errors</a>.</li>
<li>Only implement <a href="https://w3c.github.io/sustyweb/#provide-useful-notifications-to-improve-the-visitor-s-journey">useful notifications</a> that improve the visitor's experience.</li>
</ul>
<p>In relation to <strong>content and assets</strong>, make sure you:</p>
<ul>
<li>Avoid <a href="https://w3c.github.io/sustyweb/#avoid-unnecessary-or-an-overabundance-of-assets">unnecessary assets</a>, but when they are needed, take a sustainable approach to <a href="https://w3c.github.io/sustyweb/#take-a-more-sustainable-approach-to-image-assets">images</a>, <a href="https://w3c.github.io/sustyweb/#take-a-more-sustainable-approach-to-media-assets">media</a>, <a href="https://w3c.github.io/sustyweb/#take-a-more-sustainable-approach-to-animation">animations</a>, <a href="https://w3c.github.io/sustyweb/#take-a-more-sustainable-approach-to-typefaces">typefaces</a>, and <a href="https://w3c.github.io/sustyweb/#reduce-the-impact-of-downloadable-or-physical-documents">documents</a>.</li>
<li>Provide <a href="https://w3c.github.io/sustyweb/#provide-suitable-alternatives-to-web-assets">alternatives to visual and audio content</a>, as well as facilitate <a href="https://w3c.github.io/sustyweb/#support-non-graphic-ways-to-interact-with-content">speech-based browsing</a> of your content.</li>
<li><a href="https://w3c.github.io/sustyweb/#write-with-purpose-in-an-accessible-easy-to-understand-format">Write with purpose, in an accessible, easy-to-understand format</a>.</li>
</ul>
<p>In relation to <strong>quality assurance</strong>, make sure you:</p>
<ul>
<li>Have <a href="https://w3c.github.io/sustyweb/#document-and-share-project-outputs">open working and documentation processes</a> such as <a href="https://w3c.github.io/sustyweb/#use-a-design-system-to-prioritize-interface-consistency">design systems</a>.</li>
<li>Conduct <a href="https://w3c.github.io/sustyweb/#conduct-regular-audits-regression-and-non-regression-tests">regular audits and testing</a>, including <a href="https://w3c.github.io/sustyweb/#incorporate-value-testing-into-each-major-release-cycle">value</a>, <a href="https://w3c.github.io/sustyweb/#incorporate-usability-testing-into-each-minor-release-cycle">usability</a>, and <a href="https://w3c.github.io/sustyweb/#incorporate-compatibility-testing-into-each-release-cycle">compatibility</a> testing into releases, as well as using inputs from visitor <a href="https://w3c.github.io/sustyweb/#incorporate-performance-testing-into-each-major-release-cycle">journey tracking</a> to identify issues / opportunities.</li>
</ul>
</details>
</section>
<section id="web-development"><div class="header-wrapper"><h3 id="x2-2-web-development"><bdi class="secno">2.2 </bdi>Web Development</h3><a class="self-link" href="#web-development" aria-label="Permalink for Section 2.2"></a></div>
<p>Covering development approach, code minimization, code coherence, and code security.</p>
<details>
<summary>Show / Hide available guidance.</summary>
<p>In relation to the <strong>development approach</strong>, make sure you:</p>
<ul>
<li>Identify indicators and metrics that will encourage sustainable development approaches, and use sustainability as a success criterion of your technical requirements.</li>
</ul>
<p>In relation to <strong>code minimization</strong>, make sure you:</p>
<ul>
<li>Focus on removing bottlenecks and reducing compute load on a visitor's device by <a href="https://w3c.github.io/sustyweb/#resolve-render-blocking-content">removing rendering blockages</a>, using <a href="https://w3c.github.io/sustyweb/#use-code-splitting-within-projects">code splitting</a>, <a href="https://w3c.github.io/sustyweb/#manage-dependencies-appropriately">managing dependencies</a>, taking advantage of <a href="https://w3c.github.io/sustyweb/#take-advantage-of-native-features">native features</a>, rigorously assessing <a href="https://w3c.github.io/sustyweb/#rigorously-assess-third-party-services">third-party code</a> / services, and <a href="https://w3c.github.io/sustyweb/#minify-your-html-css-and-javascript">minifying everything</a>.</li>
<li>Hunt out valueless code by <a href="https://w3c.github.io/sustyweb/#apply-tree-shaking-to-code">tree shaking your code</a>, <a href="https://w3c.github.io/sustyweb/#avoid-code-duplication">avoiding duplication</a>, <a href="https://w3c.github.io/sustyweb/#run-fewer-simpler-queries-as-possible">fewer and simpler queries</a>, and (sparingly) <a href="https://w3c.github.io/sustyweb/#use-beneficial-javascript-and-its-api-s">using the latest JavaScript and APIs</a>.</li>
</ul>
<p>In relation to <strong>code coherence</strong>, make sure you:</p>
<ul>
<li>Enable other tools to interpret your code by using <a href="https://w3c.github.io/sustyweb/#use-html-elements-correctly">HTML</a> and <a href="https://w3c.github.io/sustyweb/#use-metadata-correctly">metadata</a> correctly, adhering to <a href="https://w3c.github.io/sustyweb/#ensure-your-solutions-are-accessible">accessibility standards</a>, enabling <a href="https://w3c.github.io/sustyweb/#provide-code-based-way-finding-mechanisms">code-based way-finding</a>, avoiding <a href="https://w3c.github.io/sustyweb/#avoid-using-deprecated-or-proprietary-code">deprecated or proprietary code</a>, <a href="https://w3c.github.io/sustyweb/#include-files-that-are-automatically-expected">providing expected files</a>, and using the latest standards in relation to website assets.</li>
<li>Facilitate your visitor's low-carbon choices by using a <a href="https://w3c.github.io/sustyweb/#develop-a-mobile-first-layout">mobile-first layout</a> and <a href="https://w3c.github.io/sustyweb/#adapt-to-user-preferences">adapting to user preferences</a>.</li>
</ul>
<p>In relation to <strong>code security</strong>, make sure you:</p>
<ul>
<li>Use the <a href="https://w3c.github.io/sustyweb/#use-the-latest-stable-language-version">latest stable version</a> of your chosen code language and regularly ensure your <a href="https://w3c.github.io/sustyweb/#ensure-your-scripts-are-secure">scripts are secure</a>.</li>
</ul>
</details>
</section>
<section id="hosting-infrastructure-and-systems"><div class="header-wrapper"><h3 id="x2-3-hosting-infrastructure-and-systems"><bdi class="secno">2.3 </bdi>Hosting, Infrastructure and Systems</h3><a class="self-link" href="#hosting-infrastructure-and-systems" aria-label="Permalink for Section 2.3"></a></div>
<p>Covering environment commissioning, minimizing environment and data, and minimizing human disruption.</p>
<details>
<summary>Show / Hide available guidance.</summary>
<p>Make sure you:</p>
<ul>
<li>Commission environments by selecting a <a href="https://w3c.github.io/sustyweb/#choose-a-sustainable-hosting-provider">sustainable hosting provider</a>, ensuring support of <a href="https://w3c.github.io/sustyweb/#enable-asynchronous-processing-and-communication">asynchronous processing</a>, using the <a href="https://w3c.github.io/sustyweb/#use-the-lowest-infrastructure-tier-meeting-business-requirements">lowest appropriate infrastructure tier</a>, and minimizing the use of <a href="https://w3c.github.io/sustyweb/#limit-usage-of-additional-environments">additional environments</a>.</li>
<li>Minimize environments and reduce data transfer by <a href="https://w3c.github.io/sustyweb/#compress-your-files">compressing files</a>, <a href="https://w3c.github.io/sustyweb/#be-mindful-of-duplicate-data">managing duplicate data</a>, <a href="https://w3c.github.io/sustyweb/#store-data-according-to-visitor-needs">storing data</a> according to visitor needs, <a href="https://w3c.github.io/sustyweb/#optimize-browser-caching">optimizing caching</a>, <a href="https://w3c.github.io/sustyweb/#maintain-a-relevant-refresh-frequency">refreshing data</a> only when the visitor needs it, and using <a href="https://w3c.github.io/sustyweb/#consider-cdn-s-and-edge-caching">CDNs and edge caching</a>.</li>
<li>Reduce human disruption by <a href="https://w3c.github.io/sustyweb/#automate-to-fit-the-needs">automating where appropriate</a> and dealing with <a href="https://w3c.github.io/sustyweb/#use-error-pages-and-redirects-carefully">errors and redirects</a>.</li>
</ul>
</details>
</section>
<section id="business-strategy-and-product-management"><div class="header-wrapper"><h3 id="x2-4-business-strategy-and-product-management"><bdi class="secno">2.4 </bdi>Business Strategy and Product Management</h3><a class="self-link" href="#business-strategy-and-product-management" aria-label="Permalink for Section 2.4"></a></div>
<p>Covering reporting, disclosure, strategy, and policies from both an organizational and website / product level.</p>
<details>
<summary>Show / Hide available guidance.</summary>
<p>In relation to <strong>organizational level reporting and disclosure</strong>, make sure you:</p>
<ul>
<li>Assign <a href="https://w3c.github.io/sustyweb/#assign-a-sustainability-representative">responsibility for sustainability</a> as a core part of people's roles.</li>
<li>Define clear sustainability <a href="https://w3c.github.io/sustyweb/#define-clear-organizational-sustainability-goals-and-metrics">goals and metrics</a>, which are <a href="https://w3c.github.io/sustyweb/#verify-your-efforts-using-established-third-party-business-certifications">verified</a> and upon which you <a href="https://w3c.github.io/sustyweb/#support-mandatory-disclosures-and-reporting">report regularly</a> so that others can <a href="https://w3c.github.io/sustyweb/#raise-awareness-and-inform">follow in your footsteps</a>.</li>
</ul>
<p>In relation to <strong>organizational level strategy and policies</strong>, make sure you:</p>
<ul>
<li>Have <a href="https://w3c.github.io/sustyweb/#create-one-or-more-impact-business-models">business models</a> based on positive impact, which <a href="https://w3c.github.io/sustyweb/#share-decision-making-power-with-appropriate-stakeholders">actively listen to all stakeholders</a>, and ensure <a href="https://w3c.github.io/sustyweb/#share-economic-benefits">economic benefits are shared</a> with employees, suppliers, and wider society.</li>
<li>Define and implement policies for <a href="https://w3c.github.io/sustyweb/#use-justice-equity-diversity-inclusion-jedi-practices">Justice, Equity, Diversity and Inclusion</a>, ethical and responsible <a href="https://w3c.github.io/sustyweb/#include-responsible-financial-policies">finance / investments</a>, <a href="https://w3c.github.io/sustyweb/#include-organizational-philanthropy-policies">philanthropy</a>, working with suppliers who <a href="https://w3c.github.io/sustyweb/#create-a-supplier-standards-of-practice">align with your values</a>, <a href="https://w3c.github.io/sustyweb/#include-e-waste-right-to-repair-and-recycling-policies">reduction of e-waste</a>, <a href="https://w3c.github.io/sustyweb/#promote-responsible-data-practices">data privacy</a>, appropriate <a href="https://w3c.github.io/sustyweb/#implement-appropriate-data-management-procedures">data management</a>, and considered use of <a href="https://w3c.github.io/sustyweb/#promote-responsible-emerging-technology-practices">emerging technologies</a>.</li>
<li>Fully <a href="https://w3c.github.io/sustyweb/#implement-sustainability-onboarding-guidelines">induct your employees</a> on all of the above.</li>
</ul>
<p>In relation to <strong>product or website-level strategy policies</strong>, make sure you:</p>
<ul>
<li>Establish <a href="https://w3c.github.io/sustyweb/#establish-if-a-digital-product-or-service-is-necessary">if the product or website is needed</a>; if it is, then <a href="https://w3c.github.io/sustyweb/#determine-the-functional-unit">define its requirements</a>, design an ethical and sustainable <a href="https://w3c.github.io/sustyweb/#have-an-ethical-and-sustainability-product-strategy">product strategy</a> to guide it, <a href="https://w3c.github.io/sustyweb/#estimate-a-product-or-service-s-environmental-impact">estimate its emissions</a>, put <a href="https://w3c.github.io/sustyweb/#define-performance-and-environmental-budgets">budgets around those emissions</a>, and <a href="https://w3c.github.io/sustyweb/#communicate-the-ecological-impact-of-user-choices">communicate to visitors</a> the impact their decisions will have.</li>
<li>Once live, follow a <a href="https://w3c.github.io/sustyweb/#follow-a-product-management-and-maintenance-strategy">product management and maintenance strategy</a> to keep efficient, <a href="https://w3c.github.io/sustyweb/#implement-continuous-improvement-procedures">continuously improve it</a>, openly and honestly <a href="https://w3c.github.io/sustyweb/#document-future-updates-and-evolutions">communicate the changes you've made</a>, and <a href="https://w3c.github.io/sustyweb/#plan-for-a-digital-product-or-service-s-care-and-end-of-life">plan for its end of life</a>.</li>
<li>Use <a href="https://w3c.github.io/sustyweb/#use-open-source-tools">open source software</a>.</li>
</ul>
</details>
</section>
</section>
<section class="appendix" id="acknowledgments"><div class="header-wrapper"><h2 id="a-acknowledgments"><bdi class="secno">A. </bdi>Acknowledgments</h2><a class="self-link" href="#acknowledgments" aria-label="Permalink for Appendix A."></a></div>
<p>Additional information about participation in the Sustainable Web Design Community Group (SWD-CG) can be found <a href="https://www.w3.org/community/sustyweb/wiki/Main_Page">within the wiki</a> of the community group.</p>
<section id="participants-of-the-swd-cg-active-in-the-development-of-this-document"><div class="header-wrapper"><h3 id="a-1-participants-of-the-swd-cg-active-in-the-development-of-this-document"><bdi class="secno">A.1 </bdi>Participants of the SWD-CG Active in the Development of This Document</h3><a class="self-link" href="#participants-of-the-swd-cg-active-in-the-development-of-this-document" aria-label="Permalink for Appendix A.1"></a></div>
<p>Alexander Dawson, Andy Blum, Chris Wilson, Michelle Barker, Neil Clark, Tim Frick</p>
</section>
</section>
<section id="references" class="appendix"><div class="header-wrapper"><h2 id="b-references"><bdi class="secno">B. </bdi>References</h2><a class="self-link" href="#references" aria-label="Permalink for Appendix B."></a></div><section id="informative-references"><div class="header-wrapper"><h3 id="b-1-informative-references"><bdi class="secno">B.1 </bdi>Informative references</h3><a class="self-link" href="#informative-references" aria-label="Permalink for Appendix B.1"></a></div>
<dl class="bibliography"><dt id="bib-8bt">[8BT]</dt><dd>
<a href="https://8billiontrees.com/carbon-offsets-credits/carbon-footprint-of-the-internet/"><cite>Carbon Footprint of the Internet Over Time Since 1990</cite></a>. Georgette Kilgore. 18 March 2024. Informational. URL: <a href="https://8billiontrees.com/carbon-offsets-credits/carbon-footprint-of-the-internet/">https://8billiontrees.com/carbon-offsets-credits/carbon-footprint-of-the-internet/</a>
</dd><dt id="bib-country">[COUNTRY]</dt><dd>
<a href="https://www.greenpeace.org/usa/internet-growing-to-suprass-television-should-be-powered-with-clean-energy/"><cite>Internet - growing to surpass television - should be powered with clean energy</cite></a>. David Pomerantz. 05 August 2013. Informational. URL: <a href="https://www.greenpeace.org/usa/internet-growing-to-suprass-television-should-be-powered-with-clean-energy/">https://www.greenpeace.org/usa/internet-growing-to-suprass-television-should-be-powered-with-clean-energy/</a>
</dd><dt id="bib-data">[DATA]</dt><dd>
<a href="https://www.iea.org/energy-system/buildings/data-centres-and-data-transmission-networks"><cite>Data Centres and Data Transmission Networks</cite></a>. IEA. 11 July 2023. Informational. URL: <a href="https://www.iea.org/energy-system/buildings/data-centres-and-data-transmission-networks">https://www.iea.org/energy-system/buildings/data-centres-and-data-transmission-networks</a>
</dd><dt id="bib-euc">[EUC]</dt><dd>
<a href="https://ec.europa.eu/commission/presscorner/detail/en/qanda_22_6229"><cite>Questions and Answers: EU action plan on digitalising the energy system</cite></a>. EU Commission. 18 October 2022. Informational. URL: <a href="https://ec.europa.eu/commission/presscorner/detail/en/qanda_22_6229">https://ec.europa.eu/commission/presscorner/detail/en/qanda_22_6229</a>
</dd><dt id="bib-humane">[HUMANE]</dt><dd>
<a href="https://humanewebmanifesto.com/"><cite>Manifesto for a Humane Web</cite></a>. Michelle Barker. 13 May 2024. Informational. URL: <a href="https://humanewebmanifesto.com/">https://humanewebmanifesto.com/</a>
</dd><dt id="bib-ict-impact">[ICT-IMPACT]</dt><dd>
<a href="https://www.cell.com/patterns/pdfExtended/S2666-3899(21)00188-4"><cite>The real climate and transformative impact of ICT: A critique of estimates, trends, and regulations</cite></a>. Charlotte Freitag, Mike Berners-Lee, Kelly Widdicks, Bran Knowles, Gordon S. Blair, and Adrian Friday. 10 September 2021. Informational. URL: <a href="https://www.cell.com/patterns/pdfExtended/S2666-3899(21)00188-4">https://www.cell.com/patterns/pdfExtended/S2666-3899(21)00188-4</a>
</dd><dt id="bib-manifesto">[MANIFESTO]</dt><dd>
<a href="https://www.sustainablewebmanifesto.com/"><cite>Sustainable Web Manifesto</cite></a>. Tom Greenwood, Tim Frick, Mike Gifford, Andrew Boardman, Jack Amend, Matt Hocking, Jack Lenox, René Post, Chris Adams, James Christie, Jerome Toole, Chris Butterworth, Josh Stopper, Alex Hughes, Pete Markiewicz. 01 May 2019. Informational. URL: <a href="https://www.sustainablewebmanifesto.com/">https://www.sustainablewebmanifesto.com/</a>
</dd><dt id="bib-page-weight">[PAGE-WEIGHT]</dt><dd>
<a href="https://httparchive.org/reports/page-weight?start=2015_12_01&end=latest&view=list"><cite>Page Weight</cite></a>. HTTP Archive. 29 August 2023. Informational. URL: <a href="https://httparchive.org/reports/page-weight?start=2015_12_01&end=latest&view=list">https://httparchive.org/reports/page-weight?start=2015_12_01&end=latest&view=list</a>
</dd></dl>
</section></section><p role="navigation" id="back-to-top">
<a href="#title"><abbr title="Back to Top">↑</abbr></a>
</p><script id="respec-dfn-panel">(() => {
// @ts-check
if (document.respec) {
document.respec.ready.then(setupPanel);
} else {
setupPanel();
}
function setupPanel() {
const listener = panelListener();
document.body.addEventListener("keydown", listener);
document.body.addEventListener("click", listener);
}
function panelListener() {
/** @type {HTMLElement} */
let panel = null;
return event => {
const { target, type } = event;
if (!(target instanceof HTMLElement)) return;
// For keys, we only care about Enter key to activate the panel
// otherwise it's activated via a click.
if (type === "keydown" && event.key !== "Enter") return;
const action = deriveAction(event);
switch (action) {
case "show": {
hidePanel(panel);
/** @type {HTMLElement} */
const dfn = target.closest("dfn, .index-term");
panel = document.getElementById(`dfn-panel-for-${dfn.id}`);
const coords = deriveCoordinates(event);
displayPanel(dfn, panel, coords);
break;
}
case "dock": {
panel.style.left = null;
panel.style.top = null;
panel.classList.add("docked");
break;
}
case "hide": {
hidePanel(panel);
panel = null;
break;
}
}
};
}
/**
* @param {MouseEvent|KeyboardEvent} event
*/
function deriveCoordinates(event) {
const target = /** @type HTMLElement */ (event.target);
// We prevent synthetic AT clicks from putting
// the dialog in a weird place. The AT events sometimes
// lack coordinates, so they have clientX/Y = 0
const rect = target.getBoundingClientRect();
if (
event instanceof MouseEvent &&
event.clientX >= rect.left &&
event.clientY >= rect.top
) {
// The event probably happened inside the bounding rect...
return { x: event.clientX, y: event.clientY };
}
// Offset to the middle of the element
const x = rect.x + rect.width / 2;
// Placed at the bottom of the element
const y = rect.y + rect.height;
return { x, y };
}
/**
* @param {Event} event
*/
function deriveAction(event) {
const target = /** @type {HTMLElement} */ (event.target);
const hitALink = !!target.closest("a");
if (target.closest("dfn:not([data-cite]), .index-term")) {
return hitALink ? "none" : "show";
}
if (target.closest(".dfn-panel")) {
if (hitALink) {
return target.classList.contains("self-link") ? "hide" : "dock";
}
const panel = target.closest(".dfn-panel");
return panel.classList.contains("docked") ? "hide" : "none";
}
if (document.querySelector(".dfn-panel:not([hidden])")) {
return "hide";
}
return "none";
}
/**
* @param {HTMLElement} dfn
* @param {HTMLElement} panel
* @param {{ x: number, y: number }} clickPosition
*/
function displayPanel(dfn, panel, { x, y }) {
panel.hidden = false;
// distance (px) between edge of panel and the pointing triangle (caret)
const MARGIN = 20;
const dfnRects = dfn.getClientRects();
// Find the `top` offset when the `dfn` can be spread across multiple lines
let closestTop = 0;
let minDiff = Infinity;
for (const rect of dfnRects) {
const { top, bottom } = rect;
const diffFromClickY = Math.abs((top + bottom) / 2 - y);
if (diffFromClickY < minDiff) {
minDiff = diffFromClickY;
closestTop = top;
}
}
const top = window.scrollY + closestTop + dfnRects[0].height;
const left = x - MARGIN;
panel.style.left = `${left}px`;
panel.style.top = `${top}px`;
// Find if the panel is flowing out of the window
const panelRect = panel.getBoundingClientRect();
const SCREEN_WIDTH = Math.min(window.innerWidth, window.screen.width);
if (panelRect.right > SCREEN_WIDTH) {
const newLeft = Math.max(MARGIN, x + MARGIN - panelRect.width);
const newCaretOffset = left - newLeft;
panel.style.left = `${newLeft}px`;
/** @type {HTMLElement} */
const caret = panel.querySelector(".caret");
caret.style.left = `${newCaretOffset}px`;
}
// As it's a dialog, we trap focus.
// TODO: when <dialog> becomes a implemented, we should really
// use that.
trapFocus(panel, dfn);
}
/**
* @param {HTMLElement} panel
* @param {HTMLElement} dfn
* @returns
*/
function trapFocus(panel, dfn) {
/** @type NodeListOf<HTMLAnchorElement> elements */
const anchors = panel.querySelectorAll("a[href]");
// No need to trap focus
if (!anchors.length) return;
// Move focus to first anchor element
const first = anchors.item(0);
first.focus();
const trapListener = createTrapListener(anchors, panel, dfn);
panel.addEventListener("keydown", trapListener);
// Hiding the panel releases the trap
const mo = new MutationObserver(records => {
const [record] = records;
const target = /** @type HTMLElement */ (record.target);
if (target.hidden) {
panel.removeEventListener("keydown", trapListener);
mo.disconnect();
}
});
mo.observe(panel, { attributes: true, attributeFilter: ["hidden"] });
}
/**
*
* @param {NodeListOf<HTMLAnchorElement>} anchors
* @param {HTMLElement} panel
* @param {HTMLElement} dfn
* @returns
*/
function createTrapListener(anchors, panel, dfn) {
const lastIndex = anchors.length - 1;
let currentIndex = 0;
return event => {
switch (event.key) {
// Hitting "Tab" traps us in a nice loop around elements.
case "Tab": {
event.preventDefault();
currentIndex += event.shiftKey ? -1 : +1;
if (currentIndex < 0) {
currentIndex = lastIndex;
} else if (currentIndex > lastIndex) {
currentIndex = 0;
}
anchors.item(currentIndex).focus();
break;
}
// Hitting "Enter" on an anchor releases the trap.
case "Enter":
hidePanel(panel);
break;
// Hitting "Escape" returns focus to dfn.
case "Escape":
hidePanel(panel);
dfn.focus();
return;
}
};
}
/** @param {HTMLElement} panel */
function hidePanel(panel) {
if (!panel) return;
panel.hidden = true;
panel.classList.remove("docked");
}
})()</script><script src="https://www.w3.org/scripts/TR/2021/fixup.js"></script></body></html>