This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
/
semantics-document-metadata.include
1736 lines (1455 loc) · 89.9 KB
/
semantics-document-metadata.include
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
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<section>
<h3 id="document-metadata">Document metadata</h3>
<h4 id="the-head-element">The <dfn element><code>head</code></dfn> element</h4>
<dl class="element">
<dt><a>Categories</a>:</dt>
<dd>None.</dd>
<dt><a>Contexts in which this element can be used</a>:</dt>
<dd>As the first element in an <{html}> element.</dd>
<dt><a>Content model</a>:</dt>
<dd>
If the document is <a lt="iframe srcdoc document">an <code>iframe</code> <code>srcdoc</code> document</a> or if title
information is available from a higher-level protocol: Zero or more elements of
<a>metadata content</a>, of which no more than one is a <{title}> element and no more
than one is a <{base}> element.
</dd>
<dd>
Otherwise: One or more elements of <a>metadata content</a>, of which exactly one is a
<{title}> element and no more than one is a <{base}> element.
</dd>
<dt><a>Tag omission in text/html</a>:</dt>
<dd>
A <{head}> element's <a>start tag</a> may be omitted if the element is empty, or if
the first thing inside the <{head}> element is an element.
</dd>
<dd>
A <{head}> element's <a>end tag</a> may be omitted if the <{head}> element
is not immediately followed by a <a>space character</a> or a <a>comment</a>.
</dd>
<dt><a>Content attributes</a>:</dt>
<dd><a>Global attributes</a></dd>
<dt>Allowed <a href="#aria-role-attribute">ARIA role attribute</a> values:</dt>
<dd>None</dd>
<dt>Allowed <a href="#state-and-property-attributes">ARIA state and property attributes</a>:</dt>
<dd><a>Global aria-* attributes</a></dd>
<dt><a>DOM interface</a>:</dt>
<dd>
<pre class="idl" data-highlight="webidl">
interface HTMLHeadElement : HTMLElement {};
</pre>
</dd>
</dl>
The <{head}> element <a>represents</a> a collection of metadata for the {{Document}}.
<div class="example">
The collection of metadata in a <{head}> element can be large or small. Here is an
example of a very short one:
<pre highlight="html">
<!doctype html>
<html lang="en">
<head>
<title>A document with a short head</title>
</head>
<body>
...
</pre>
Here is an example of a longer one:
<pre highlight="html">
<!DOCTYPE HTML>
<HTML lang="en">
<HEAD>
<META CHARSET="UTF-8">
<BASE HREF="https://www.example.com/">
<TITLE>An application with a long head</TITLE>
<LINK REL="STYLESHEET" HREF="default.css">
<LINK REL="STYLESHEET ALTERNATE" HREF="big.css" TITLE="Big Text">
<SCRIPT SRC="support.js"></SCRIPT>
<META NAME="APPLICATION-NAME" CONTENT="Long headed application">
</HEAD>
<BODY>
...
</pre>
</div>
<p class="note">
The <{title}> element is a required child in most situations, but when a higher-level
protocol provides title information, e.g., in the Subject line of an e-mail when HTML is used as
an e-mail authoring format, the <{title}> element can be omitted.
</p>
<!-- W3C START - DO NOT OVERWRITE-->
<p class="note">
It is recommended to keep the usage of attributes and their values defined on the <{head}>
element to a minimum to allow for proper detection of the <a>character encoding declaration</a>
within the first 1024 bytes.
</p>
<!-- W3C END -->
<h4 id="the-title-element">The <dfn element><code>title</code></dfn> element</h4>
<dl class="element">
<dt><a>Categories</a>:</dt>
<dd><a>Metadata content</a>.</dd>
<dt><a>Contexts in which this element can be used</a>:</dt>
<dd>In a <{head}> element containing no other <{title}> elements.</dd>
<dt><a>Content model</a>:</dt>
<dd><a>Text</a> that is not <a>inter-element whitespace</a>.</dd>
<dt><a>Tag omission in text/html</a>:</dt>
<dd>Neither tag is omissible.</dd>
<dt><a>Content attributes</a>:</dt>
<dd><a>Global attributes</a></dd>
<dt>Allowed <a href="#aria-role-attribute">ARIA role attribute</a> values:</dt>
<dd>None</dd>
<dt>Allowed <a href="#state-and-property-attributes">ARIA state and property attributes</a>:</dt>
<dd><a>Global aria-* attributes</a></dd>
<dt><a>DOM interface</a>:</dt>
<dd>
<pre class="idl" data-highlight="webidl">
interface HTMLTitleElement : HTMLElement {
attribute DOMString text;
};
</pre>
</dd>
</dl>
The <{title}> element <a>represents</a> the document's title or name. Authors should use
titles that identify their documents even when they are used out of context, for example in a
user's history or bookmarks, or in search results. The document's title is often different from
its first heading, since the first heading does not have to stand alone when taken out of context.
There must be no more than one <{title}> element per document.
<p class="note">
If it's reasonable for the {{Document}} to have no title, then the <code>title</code>
element is probably not required. See the <{head}> element's content model for a
description of when the element is required.
</p>
<dl class="domintro">
<dt><var>title</var> . <code>text</code> [ = <var>value</var> ]</dt>
<dd>
Returns the <a>child text content</a> of the element.
Can be set, to replace the element's children with the given value.
</dd>
</dl>
<div class="impl">
The IDL attribute <dfn attribute for="HTMLTitleElement"><code>text</code></dfn> must return the
<a>child text content</a> of the <{title}> element. On
setting, it must act the same way as the {{Node/textContent}} IDL attribute.
</div>
<div class="example">
Here are some examples of appropriate titles, contrasted with the top-level headings that
might be used on those same pages.
<pre highlight="html">
<title>Introduction to The Mating Rituals of Bees</title>
...
<h1>Introduction</h1>
<p>This companion guide to the highly successful
<cite>Introduction to Medieval Bee-Keeping</cite> book is...
</pre>
The next page might be a part of the same site. Note how the title describes the subject matter
unambiguously, while the first heading assumes the reader knows what the context is and
therefore won't wonder if the dances are Salsa or Waltz:
<pre highlight="html">
<title>Dances used during bee mating rituals</title>
...
<h2>The Dances</h2>
</pre>
</div>
The string to use as the document's title is given by the <code>document.title</code> IDL
attribute.
<div class="impl">
User agents should use the document's title when referring to the document in their user
interface. When the contents of a <{title}> element are used in this way,
<a>the directionality</a> of that <{title}> element should be used to set the
directionality of the document's title in the user interface.
</div>
<h4 id="the-base-element">The <dfn element><code>base</code></dfn> element</h4>
<dl class="element">
<dt><a>Categories</a>:</dt>
<dd><a>Metadata content</a>.</dd>
<dt><a>Contexts in which this element can be used</a>:</dt>
<dd>In a <{head}> element containing no other <{base}> elements.</dd>
<dt><a>Content model</a>:</dt>
<dd><a>Nothing</a>.</dd>
<dt><a>Tag omission in text/html</a>:</dt>
<dd>No end tag.</dd>
<dt><a>Content attributes</a>:</dt>
<dd><a>Global attributes</a></dd>
<dd><code>href</code> — <a>Document base URL</a></dd>
<dd>
<code>target</code> — Default <a>browsing context</a> for <a>hyperlink</a> <a>navigation</a>
and [[#forms-form-submission]]
</dd>
<dt>Allowed <a href="#aria-role-attribute">ARIA role attribute</a> values:</dt>
<dd>None</dd>
<dt>Allowed <a href="#state-and-property-attributes">ARIA state and property attributes</a>:</dt>
<dd><a>Global aria-* attributes</a>.</dd>
<dt><a>DOM interface</a>:</dt>
<dd>
<pre class="idl" data-highlight="webidl">
interface HTMLBaseElement : HTMLElement {
attribute DOMString href;
attribute DOMString target;
};
</pre>
</dd>
</dl>
The <{base}> element allows authors to specify the <a>document base URL</a> for the
purposes of [[#parsing-urls]], and the name of the default <a>browsing context</a>
for the purposes of <a>following hyperlinks</a>. The element does not <a>represent</a> any content
beyond this information.
There must be no more than one <{base}> element per document.
A <{base}> element must have either an <{base/href}> attribute, a <code>target</code>
attribute, or both.
The <dfn element-attr for="base"><code>href</code></dfn> content attribute, if specified, must
contain a <a>valid URL potentially surrounded by spaces</a>.
A <{base}> element, if it has an <{base/href}> attribute, must come before any other elements in
the tree that have attributes defined as taking <a for="url">URLs</a>.
<div class="impl">
<p class="note">
If there are multiple <{base}> elements with <{base/href}> attributes, all but
the first are ignored.
</p>
</div>
The <dfn element-attr for="base"><code>target</code></dfn> attribute, if specified, must contain a <a>valid browsing
context name or keyword</a>, which specifies which <a>browsing context</a> is to be used as the
default when <a>hyperlinks</a> and <a>forms</a> in the {{Document}} cause
<a>navigation</a>.
A <{base}> element, if it has a <code>target</code> attribute, must come before any
elements in the tree that represent <a>hyperlinks</a>.
<div class="impl">
<p class="note">
If there are multiple <{base}> elements with <code>target</code> attributes, all but
the first are ignored.
</p>
A <{base}> element that is the first <{base}> element with an
<{base/href}> content attribute <a>in a document tree</a> has a
<dfn>frozen base URL</dfn>. The <a>frozen base URL</a> must be <a>immediately</a>
<a lt="set the frozen base URL">set</a> for an element whenever any of the following situations
occur:
* The <{base}> element becomes the first <{base}> element in <a>tree order</a>
with an <{base/href}> content attribute in its {{Document}}.
* The <{base}> element is the first <{base}> element in <a>tree order</a> with
an <{base/href}> content attribute in its {{Document}}, and its
<{base/href}> content attribute is changed.
To <dfn>set the frozen base URL</dfn>, for an element <var>element</var>:
1. Let <var>document</var> be <var>element</var>'s <a>node document</a>.
2. Let <var>urlRecord</var> be the result of <a>parsing</a> the value of
<var>element</var>'s <{base/href}> content attribute with <var>document</var>'s
<a>fallback base URL</a>, and <var>document</var>'s <a>character encoding</a>. (Thus the
<{base}> element isn't affected by itself.)
3. Set <var>elements</var>'s <a>frozen base URL</a> to <var>document</var>'s
<a>fallback base URL</a>, if <var>urlRecord</var> is failure or running
<a>Is base allowed for Document?</a> on the <a>resulting URL record</a> and
<var>document</var> returns "<code>Blocked</code>", and to <var>urlRecord</var> otherwise.
The <dfn attribute for="HTMLBaseElement"><code>href</code></dfn> IDL attribute, on getting, must
return the result of running the following algorithm:
1. Let <var>document</var> be <var>element</var>'s <a>node document</a>.
2. Let <var>url</var> be the value of the <{base/href}> attribute of the <{base}> element, if it
has one, and the empty string otherwise.
3. Let <var>urlRecord</var> be the result of <a>parsing</a> <var>url</var> with
<var>document</var>'s <a>fallback base url</a>, and <var>document</var>'s
<a>character encoding</a>. (Thus, the <{base}> element isn't affected by other <{base}>
elements or itself).
4. If <var>urlRecord</var> is failure, return <var>url</var>.
5. Return the <a>serialization</a> of <var>urlRecord</var>.
The {{HTMLBaseElement/href}} IDL attribute, on setting, must set the <{base/href}> content
attribute to the given new value.
The <dfn attribute for="HTMLBaseElement"><code>target</code></dfn> IDL attribute must
<a>reflect</a> the content attribute of the same name.
</div>
<div class="example">
In this example, a <{base}> element is used to set the <a>document base URL</a>:
<pre highlight="html">
<!DOCTYPE html>
<html lang="en">
<head>
<title>This is an example for the &lt;base&gt; element</title>
<base href="https://www.example.com/news/index.html">
</head>
<body>
<p>Visit the <a href="archives.html">archives</a>.</p>
</body>
</html>
</pre>
The link in the above example would be a link to
"<code>https://www.example.com/news/archives.html</code>".
</div>
<h4 id="the-link-element">The <dfn element><code>link</code></dfn> element</h4>
<dl class="element">
<dt><a>Categories</a>:</dt>
<dd><a>Metadata content</a>.</dd>
<dd>If the element is <a>allowed in the body</a>: <a>flow content</a>.</dd>
<dd>If the element is <a>allowed in the body</a>: <a>phrasing content</a>.</dd>
<dt><a>Contexts in which this element can be used</a>:</dt>
<dd>Where <a>metadata content</a> is expected.</dd>
<dd>In a <{noscript}> element that is a child of a <{head}> element.</dd>
<dd>If the element is <a>allowed in the body</a>: where <a>phrasing content</a> is expected.</dd>
<dt><a>Content model</a>:</dt>
<dd><a>Nothing</a>.</dd>
<dt><a>Tag omission in text/html</a>:</dt>
<dd>No <a>end tag</a>.</dd>
<dt><a>Content attributes</a>:</dt>
<dd><a>Global attributes</a></dd>
<dd><code>href</code> — Address of the <a>hyperlink</a></dd>
<dd><code>crossorigin</code> — How the element handles crossorigin requests</dd>
<dd><{link/rel}> — Relationship of this document (or subsection/topic) to the destination resource</dd>
<dd><{link/rev}> — <a>Reverse link</a> relationship of the destination resource to this document (or subsection/topic)</dd>
<dd><code>media</code> — Applicable media</dd>
<dd><code>nonce</code> — Cryptographic nonce used in Content Security Policy checks [[CSP3]]</dd>
<dd><code>hreflang</code> — Language of the linked resource</dd>
<dd><code>type</code> — Hint for the type of the referenced resource</dd>
<dd><code>sizes</code> — Sizes of the icons (for <{link/rel}>="<code>icon</code>")</dd>
<dd>
Also, the <{link/title}> attribute has special semantics on this element: Title of the
link; alternative style sheet set name.
</dd>
<dt>Allowed <a href="#aria-role-attribute">ARIA role attribute</a> values:</dt>
<dd><a><code>link</code></a> (default - <a><em>do not set</em></a>).</dd>
<dt>Allowed <a href="#state-and-property-attributes">ARIA state and property attributes</a>:</dt>
<dd><a>Global aria-* attributes</a></dd>
<dd>Any <code>aria-*</code> attributes <a href="#allowed-aria-roles-states-and-properties">applicable to the default or allowed roles</a>.</dd>
<dd>For <code>role</code> value </dd>
<dt><a>DOM interface</a>:</dt>
<dd>
<pre class="idl" data-highlight="webidl">
interface HTMLLinkElement : HTMLElement {
attribute DOMString href;
attribute DOMString? crossOrigin;
attribute DOMString rel;
attribute DOMString rev;
[SameObject, PutForwards=value]readonly attribute DOMTokenList relList;
attribute DOMString media;
attribute DOMString hreflang;
attribute DOMString type;
[SameObject, PutForwards=value] readonly attribute DOMTokenList sizes;
};
HTMLLinkElement implements LinkStyle;
</pre>
</dd>
</dl>
The <{link}> element allows authors to link their document to other resources.
The destination of the link(s) is given by the <dfn element-attr for="link"><code>href</code></dfn> attribute, which must
be present and must contain a <a>valid non-empty URL potentially surrounded by spaces</a>.
<span class="impl">If the <{link/href}> attribute is absent, then the element does not define
a link.</span>
A <{link}> element must have a <{link/rel}> attribute.
<p class="note">
If the <{link/rel}> attribute is used, the element is restricted to the <code>head</code>
element.
</p>
The types of link indicated (the relationships) are given by the value of the
<dfn element-attr for="link"><code>rel</code></dfn> attribute, which, if present, must have a
value that is a <a>set of space-separated tokens</a>. The <a>allowed keywords and their
meanings</a> are defined in a later section. If the <{link/rel}> attribute is absent, has no
keywords, or if none of the keywords used are allowed according to the definitions in this
specification, then the element does not create any links.
If a <code>link</code> element has a <code>rel</code> attribute that contains only keywords that are
<a>body-ok</a>, then the element is said to be <dfn>allowed in the body</dfn>. This means
that the element can be used where <a>phrasing content</a> is expected.</p>
Two categories of links can be created using the <{link}> element:
<a>Links to external resources</a> and <a>hyperlinks</a>. The [[#sec-link-types]] section defines
whether a particular link type is an external resource or a hyperlink. One <code>link</code>
element can create multiple links (of which some might be external resource links and some might
be hyperlinks); exactly which and how many links are created depends on the keywords given in the
<{link/rel}> attribute. User agents must process the links on a per-link
basis, not a per-element basis.
<p class="note">
Each link created for a <{link}> element is handled separately. For instance, if there
are two <{link}> elements with <code>rel="stylesheet"</code>, they each count as a
separate external resource, and each is affected by its own attributes independently. Similarly,
if a single <{link}> element has a <{link/rel}> attribute with the value
<code>next stylesheet</code>, it creates both a <a>hyperlink</a> (for the <code>next</code>
keyword) and an <a>external resource link</a> (for the <code>stylesheet</code> keyword), and
they are affected by other attributes (such as <code>media</code> or <code>title</code>)
differently.
</p>
<div class="example">
For example, the following <{link}> element creates two hyperlinks (to the same page):
<pre highlight="html"><link rel="author license" href="/about"></pre>
The two links created by this element are one whose semantic is that the target page has
information about the current page's author, and one whose semantic is that the target page has
information regarding the license under which the current page is provided.
</div>
<{link}> and <{a}> elements may also have a
<dfn element-attr for="a,link,links"><code>rev</code></dfn> attribute, which is used to describe
a <a>reverse link</a> relationship from the resource specified by the <{links/href}> to the
current document. If present, the value of this attribute must be a <a>set of space-separated
tokens</a>. Like the <{links/rel}> attribute, [[#sec-link-types]] describes the <a>allowed
keywords and their meanings</a> for the <{links/rev}> attribute. Both the <{links/rel}> and
<{links/rev}> attributes may be present on the same element.
<dfn lt="reverse link|Reverse links">Reverse links</dfn> are a way to express the reverse
directional relationship of a link. In contrast to the <{links/rel}> attribute, whose value
conveys a forward directional relationship ("how is the link related to me"), the <{links/rev}>
attribute allows for similiar relationships to be expressed in the reverse direction ("how am I
related to this link"). These values can enable user agents to build a more comprehensive map of
linked documents.
<div class="example">Given two documents, each containing a chapter of a book, the links between
them could be described with the <{link/rel}> and <{links/rev}> attributes as follows:
Document with URL "chapter1.html"
<pre highlight="html"><link href="chapter2.html" rel="next" rev="prev"></pre>
Document with URL "chapter2.html"
<pre highlight="html">
<link href="chapter1.html" rel="prev" rev="next">
<link href="chapter3.html" rel="next" rev="prev"></pre>
From chapter1.html, the link to chapter2.html is the "<code>next</code>" chapter in the series in
the forward direction, and the "<code>previous</code>" chapter in the reverse diretion (from
chapter2.html to chapter1.html).
</div>
<div class="example">The links in a table of contents document might be described using
<{links/rel}> and <{links/rev}> as follows:
<pre highlight="html">
<ol>
<li><a href="chapter1.html" rev="toc" rel="next">chapter 1</a></li>
<li><a href="chapter2.html" rev="toc"></a>chapter 2</li>
<li><a href="chapter3.html" rev="toc"></a>chapter 3</li>
</ol>
</pre>
From the table of contents, the "<code>next</code>" logical path is to the first chapter,
expressed using <{links/rel}>. Each chapter link has a "<code>toc</code>" <{links/rev}> value
which indicates that the current document is the table of contents document for every chapter.
</div>
<p>The <dfn element-attr for="link"><code>nonce</code></dfn> attribute represents a
cryptographic nonce ("number used once") which can be used by <cite>Content Security Policy</cite>
to determine whether or not an external resource specified by the link will be loaded and applied
to the document. The value is text. [[CSP3]]</p>
The <dfn element-attr for="link"><code>crossorigin</code></dfn> attribute is a
<a>CORS settings attribute</a>. It is intended for use with external resource links.
The exact behavior for links to external resources depends on the exact relationship, as defined
for the relevant link type. Some of the attributes control whether or not the external resource is
to be applied (as defined below).
For external resources that are represented in the DOM (for example, style sheets), the DOM
representation must be made available (modulo cross-origin restrictions) even if the resource is
not applied. To <dfn lt="obtain|obtain the resource">obtain the resource</dfn>, the user agent
must run the following steps:
1. If the <{link/href}> attribute's value is the empty string, then abort these steps.
2. <a>Parse</a> the <a for="url">URL</a> given by the <{link/href}> attribute, relative to the
element's <a>node document</a>. If that fails, then abort these steps. Otherwise, let
<var>url</var> be the <a>resulting URL record</a>.
3. Let <var>corsAttributeState</var> be the current state of the element's <{link/crossorigin}>
content attribute.
4. Let <var>request</var> be the result of <a>creating a potential-CORS request</a> given
<var>url</var> and <var>corsAttributeState</var>.
5. Set <var>request</var>'s <a>client</a> to the <{link}> element's <a>node document</a>'s
{{Window}} object's <a>environment settings object</a>.
6. Set <var>request</var>'s <a>cryptographic nonce metadata</a> to the current state of the
<{link}> element's <{link/nonce}> content attribute.
7. <a>Fetch</a> <var>request</var>.
User agents may opt to only try to obtain such resources when they are needed, instead of
pro-actively fetching all the external resources that are not applied.
The semantics of the protocol used (e.g., HTTP) must be followed when fetching external
resources. (For example, redirects will be followed and 404 responses will cause the external
resource to not be applied.)
Once the attempts to obtain the resource and its <a>critical subresources</a> are complete, the
user agent must, if the loads were successful, <a>queue a task</a> to <a>fire a simple event</a>
named <code>load</code> at the <{link}> element, or, if the resource or one of its
<a>critical subresources</a> failed to completely load for any reason (e.g., DNS error, HTTP 404
response, a connection being prematurely closed, unsupported Content-Type), <a>queue a task</a>
to <a>fire a simple event</a> named <code>error</code> at the <{link}> element.
Non-network errors in processing the resource or its subresources (e.g., CSS parse errors, PNG
decoding errors) are not failures for the purposes of this paragraph.
The <a>task source</a> for these <a>tasks</a> is the <a>DOM manipulation task source</a>.
The element must <a>delay the load event</a> of the element's <a>node document</a> until all the
attempts to obtain the resource and its <a>critical subresources</a> are complete. (Resources
that the user agent has not yet attempted to obtain, e.g., because it is waiting for the resource
to be needed, do not <a>delay the load event</a>.)
<hr />
Interactive user agents may provide users with a means to <a>follow the hyperlinks</a> created
using the <{link}> element, somewhere within their user interface. The exact interface
is not defined by this specification, but it could include the following information (obtained
from the element's attributes, again as defined below), in some form or another (possibly
simplified), for each hyperlink created with each <{link}> element in the document:
* The relationship between this document and the resource (given by the <{link/rel}>
attribute)
* The title of the resource (given by the <{link/title}> attribute).
* The address of the resource (given by the <{link/href}> attribute).
* The language of the resource (given by the <{link/hreflang}> attribute).
* The optimum media for the resource (given by the <{link/media}> attribute).
User agents could also include other information, such as the type of the resource (as given by
the <code>type</code> attribute).
<p class="note">
Hyperlinks created with the <{link}> element and its <{link/rel}> attribute apply
to the whole page. This contrasts with the <{links/rel}> attribute of <{a}> and
<{area}> elements, which indicates the type of a link whose context is given by the
link's location within the document.
</p>
The <dfn element-attr for="link"><code>media</code></dfn> attribute says which media the resource
applies to. The value must be a <a>valid media query list</a>.
<div class="impl">
If the link is a <a>hyperlink</a> then the <{link/media}> attribute is purely advisory, and
describes for which media the document in question was designed.
However, if the link is an <a>external resource link</a>, then the <code>media</code> attribute
is prescriptive. The user agent must apply the external resource when the <code>media</code>
attribute's value <a>matches the environment</a> and the other relevant conditions apply, and
must not apply it otherwise.
<p class="note">
The external resource might have further restrictions defined within that limit its
applicability. For example, a CSS style sheet might have some <code>@media</code> blocks. This
specification does not override such further restrictions or requirements.
</p>
</div>
The default, if the <code>media</code> attribute is omitted, is "<code>all</code>", meaning that
by default links apply to all media.
The <dfn element-attr for="link"><code>hreflang</code></dfn> attribute on the <{link}> element has
the same semantics as the {{HTMLLinkElement/hreflang}} attribute on the <{a}> element.
The <dfn element-attr for="link"><code>type</code></dfn> attribute gives the <a>MIME type</a> of
the linked resource. It is purely advisory. The value must be a <a>valid mime type</a>.
For <a>external resource links</a>, the <{link/type}> attribute is used as a hint to user agents
so that they can avoid fetching resources they do not support. If the attribute is present, then
the user agent must assume that the resource is of the given type (even if that is not a
<a>valid mime type</a>, e.g., the empty string). If the attribute is omitted, but the external
resource link type has a default type defined, then the user agent must assume that the resource
is of that type. If the user agent does not support the given <a>MIME type</a> for the given link
relationship, then the user agent should not <a>obtain</a> the resource; if the user agent does
support the given <a>MIME type</a> for the given link relationship, then the user agent should
<a>obtain</a> the resource at the appropriate time as specified for the
<a>external resource link</a>'s particular type. If the attribute is omitted, and the external
resource link type does not have a default type defined, but the user agent would <a>obtain</a>
the resource if the type was known and supported, then the user agent should <a>obtain</a> the
resource under the assumption that it will be supported.
<div class="impl">
User agents must not consider the <code>type</code> attribute authoritative — upon
fetching the resource, user agents must not use the <code>type</code> attribute to determine its
actual type. Only the actual type (as defined in the next paragraph) is used to determine
whether to <em>apply</em> the resource, not the aforementioned assumed type.
<dfn lt="determining the type of the resource"></dfn>If the external resource link type defines
rules for processing the resource's <a>Content-Type metadata</a>, then those rules apply.
Otherwise, if the resource is expected to be an image, user agents may apply the
<a>image sniffing rules</a>, with the <var>official type</var> being the type determined from
the resource's <a>Content-Type metadata</a>, and use the resulting
<a>computed type of the resource</a> as if it was the actual type. Otherwise, if neither of
these conditions apply or if the user agent opts not to apply the image sniffing rules, then the
user agent must use the resource's <a>Content-Type metadata</a> to determine the type of the
resource. If there is no type metadata, but the external resource link type has a default type
defined, then the user agent must assume that the resource is of that type.
<p class="note">
The <code>stylesheet</code> link type defines rules for processing the resource's
<a>Content-Type metadata</a>.
</p>
Once the user agent has established the type of the resource, the user agent must apply the
resource if it is of a supported type and the other relevant conditions apply, and must ignore
the resource otherwise.
<div class="example">
If a document contains style sheet links labeled as follows:
<pre highlight="html">
<link rel="stylesheet" href="A" type="text/plain">
<link rel="stylesheet" href="B" type="text/css">
<link rel="stylesheet" href="C">
</pre>
...then a compliant user agent that supported only CSS style sheets would fetch the B and C
files, and skip the A file (since <code>text/plain</code> is not the <a>MIME type</a> for CSS
style sheets).
For files B and C, it would then check the actual types returned by the server. For those that
are sent as <code>text/css</code>, it would apply the styles, but for those labeled as
<code>text/plain</code>, or any other type, it would not.
If one of the two files was returned without a <a>Content-Type</a> metadata, or with a
syntactically incorrect type like <code>Content-Type: "null"</code>, then the default type
for <code>stylesheet</code> links would kick in. Since that default type is
<code>text/css</code>, the style sheet <em>would</em> nonetheless be applied.
</div>
</div>
The <dfn element-attr for="link"><code>title</code></dfn> attribute gives the title of the link.
With one exception, it is purely advisory. The value is text. The exception is for style sheet
links, where the <{link/title}> attribute defines <a>alternative style sheet sets</a>.
<p class="note">
The <{link/title}> attribute on <{link}> elements differs from the global <{global/title}>
attribute of most other elements in that a link without a title does not inherit the title of
the parent element: it merely has no title.
</p>
The <code>sizes</code> attribute is used with the <code>icon</code> link type. The attribute must
not be specified on <{link}> elements that do not have a <{link/rel}> attribute that
specifies the <code>icon</code> keyword.
<div class="impl">
The <a>activation behavior</a> of <code>link</code> elements that create <a>hyperlinks</a> is to
run the following steps:
1. If the <{link}> element's <a>node document</a> is not <a>fully active</a>, then
abort these steps.
2. <a>Follow the hyperlink</a> created by the<code>link</code> element.
HTTP <code>Link:</code> headers, if supported, must be assumed to come before any links in the
document, in the order that they were given in the HTTP message. These headers are to be
processed according to the rules given in the relevant specifications. [[!HTTP]] [[!RFC5988]]
<p class="note">
Registration of relation types in HTTP Link: headers is distinct from <a>HTML link types</a>,
and thus their semantics can be different from same-named HTML types.
</p>
The IDL attributes <dfn attribute for="HTMLLinkElement"><code>href</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>rel</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>rev</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>media</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>nonce</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>hreflang</code></dfn>,
<dfn attribute for="HTMLLinkElement"><code>type</code></dfn>, and
<dfn attribute for="HTMLLinkElement"><code>sizes</code></dfn> each must <a>reflect</a> the
respective content attributes of the same name.
The <dfn attribute for="HTMLLinkElement"><code>crossOrigin</code></dfn> IDL attribute must
<a>reflect</a> the <{link/crossorigin}> content attribute.
The IDL attribute <dfn attribute for="HTMLLinkElement"><code>relList</code></dfn> must
<a>reflect</a> the <{link/rel}> content attribute.
<code>relList</code>'s {{DOMTokenList}}'s <a>supported tokens</a> are the keywords
defined in <a>HTML link types</a> which are allowed on <{link}> elements and supported
by the user agent.
<{link/rel}>'s <a>supported tokens</a> are the keywords defined in <a>HTML link types</a> which
are allowed on <{link}> elements, impact the processing model, and are supported by the user
agent. The possible supported tokens are <code>alternate</code>,
<a><code>dns-prefetch</code></a>, <code>icon</code>, <a><code>preconnect</code></a>,
<a><code>prefetch</code></a>, <a><code>prerender</code></a>, <code>search</code>,
<code>stylesheet</code> and <code>next</code>. <{link/rel}>'s <a>supported tokens</a> must only
include the tokens from this list that the user agent implements the processing model for.
Other specifications may add <a>HTML link types</a> as defined in <a>Other link types</a>, with
the following additional requirements:
* Such specifications may require that their link types be included in <{link/rel}>'s supported
tokens.
* Such specifications may specify that their link types are <a>body-ok</a>.
</div>
The {{LinkStyle}} interface is also implemented by this element. [[!CSSOM]]
<div class="example">
Here, a set of <{link}> elements provide some style sheets:
<pre highlight="html">
<!-- a persistent style sheet -->
<link rel="stylesheet" href="default.css">
<!-- the preferred alternate style sheet -->
<link rel="stylesheet" href="green.css" title="Green styles">
<!-- some alternate style sheets -->
<link rel="alternate stylesheet" href="contrast.css" title="High contrast">
<link rel="alternate stylesheet" href="big.css" title="Big fonts">
<link rel="alternate stylesheet" href="wide.css" title="Wide screen">
</pre>
</div>
<div class="example">
The following example shows how you can specify versions of the page that use alternative
formats, are aimed at other languages, and that are intended for other media:
<pre highlight="html">
<link rel=alternate href="/en/html" hreflang=en type=text/html title="English HTML">
<link rel=alternate href="/fr/html" hreflang=fr type=text/html title="French HTML">
<link rel=alternate href="/en/html/print" hreflang=en type=text/html media=print title="English HTML (for printing)">
<link rel=alternate href="/fr/html/print" hreflang=fr type=text/html media=print title="French HTML (for printing)">
<link rel=alternate href="/en/pdf" hreflang=en type=application/pdf title="English PDF">
<link rel=alternate href="/fr/pdf" hreflang=fr type=application/pdf title="French PDF">
</pre>
</div>
<h4 id="the-meta-element">The <dfn element><code>meta</code></dfn> element</h4>
<dl class="element">
<dt><a>Categories</a>:</dt>
<dd><a>Metadata content</a>.</dd>
<dt><a>Contexts in which this element can be used</a>:</dt>
<dd>
If the <code>charset</code> attribute is present, or if the element's <code>http-equiv</code>
attribute is in the <a state for="http-equiv">encoding declaration state</a>: in a <{head}> element.
</dd>
<dd>
If the <code>http-equiv</code> attribute is present but not in the
<a state for="http-equiv">encoding declaration state</a>: in a <{head}> element.
</dd>
<dd>
If the <code>http-equiv</code> attribute is present but not in the
<a state for="http-equiv">encoding declaration state</a>: in a <{noscript}> element that is a child of a
<{head}> element.
</dd>
<dd>
If the <code>name</code> attribute is present: where <a>metadata content</a> is expected.
</dd>
<dt><a>Content model</a>:</dt>
<dd><a>Nothing</a>.</dd>
<dt><a>Tag omission in text/html</a>:</dt>
<dd>No <a>end tag</a>.</dd>
<dt><a>Content attributes</a>:</dt>
<dd><a>Global attributes</a></dd>
<dd><code>name</code> — Metadata name</dd>
<dd><code>http-equiv</code> — Pragma directive</dd>
<dd><code>content</code> — Value of the element</dd>
<dd><code>charset</code> — <a>Character encoding declaration</a></dd>
<dt>Allowed <a href="#aria-role-attribute">ARIA role attribute</a> values:</dt>
<dd>None</dd>
<dt>Allowed <a href="#state-and-property-attributes">ARIA state and property attributes</a>:</dt>
<dd><a>Global aria-* attributes</a></dd>
<dt><a>DOM interface</a>:</dt>
<dd>
<pre class="idl" data-highlight="webidl">
interface HTMLMetaElement : HTMLElement {
attribute DOMString name;
attribute DOMString httpEquiv;
attribute DOMString content;
};
</pre>
</dd>
</dl>
The <{meta}> element <a>represents</a> various kinds of metadata that cannot be
expressed using the <{title}>, <{base}>, <{link}>, <{style}>,
and <{script}> elements.
The <{meta}> element can represent document-level metadata with the <code>name</code>
attribute, pragma directives with the <dfn element-attr for="meta"><code>http-equiv</code></dfn> attribute, and the file's
<a>character encoding declaration</a> when an HTML document is serialized to string form (e.g., for
transmission over the network or for disk storage) with the <code>charset</code> attribute.
Exactly one of the <code>name</code>, <code>http-equiv</code>, and <code>charset</code>
attributes must be specified.
If either <code>name</code> or <code>http-equiv</code> is
specified, then the <code>content</code> attribute must also be
specified. Otherwise, it must be omitted.
The <dfn element-attr for="meta"><code>charset</code></dfn> attribute specifies the character
encoding used by the document. This is a <a>character encoding declaration</a>. If the
attribute is present in an <a>XML document</a>, its value must be an
<a>ASCII case-insensitive</a> match for the string "<code>utf-8</code>" (and the
document is therefore forced to use <a>UTF-8</a> as its encoding).
<p class="note">The <code>charset</code> attribute on the
<{meta}> element has no effect in XML documents, and is only allowed in order to
facilitate migration to and from XHTML.</p>
There must not be more than one <{meta}> element with a <code>charset</code> attribute
per document.
The <dfn element-attr for="meta"><code>content</code></dfn> attribute gives the value of the
document metadata or pragma directive when the element is used for those purposes. The allowed
values depend on the exact context, as described in subsequent sections of this specification.
<div class="warning">
<p><a href="https://www.w3.org/TR/css-device-adapt-1/#viewport-meta"><code><meta name="viewport" content="..."></code></a>
allows authors to define specific viewport characteristics (such as the layout viewport's width and zoom factor)
for their documents. Among these is the ability to prevent or restrict users from being able to zoom, using
<code>content</code> values such as <code>user-scalable=no</code> or <code>maximum-scale=1.0</code>. Authors should not suppress
or limit the ability of users to resize a document, as this causes accessibility and usability issues.</p>
<div class="example">
The following examples illustrate code that should be avoided:
<pre highlight="html">
<!-- DO NOT DO THIS -->
<meta name="viewport" content="<mark>user-scalable=no</mark>">
<meta name="viewport" content="width=device-width, initial-scale=1.0, <mark>maximum-scale=1.0</mark>">
</pre>
</div>
<p>There may be specific use cases where preventing users from zooming may be appropriate, such as map applications –
where custom zoom functionality is handled via scripting.
However, in general this practice should be avoided, and HTML conformance checking tools should display a warning if
they encounter these values.</p>
<p>Note that most user agents now allow users to always zoom, regardless of any
<code><meta name="viewport" content="..."></code> restrictions – either by default, or as a setting/option (which may however not be immediately apparent to users).</p>
</div>
If a <{meta}> element has a <dfn element-attr for="meta"><code>name</code></dfn>
attribute, it sets document metadata. Document metadata is expressed in terms of name-value pairs,
the <code>name</code> attribute on the <{meta}> element giving the
name, and the <code>content</code> attribute on the same element giving
the value. The name specifies what aspect of metadata is being set; valid names and the meaning of
their values are described in the following sections. If a <{meta}> element has no
<code>content</code> attribute, then the value part of the metadata name-value pair is the empty
string.
The <dfn attribute for="HTMLMetaElement"><code>name</code></dfn> and <dfn attribute for="HTMLMetaElement"><code>content</code></dfn> IDL attributes must
<a>reflect</a> the respective content attributes of the same name. The IDL attribute
<dfn attribute for="HTMLMetaElement"><code>httpEquiv</code></dfn> must <a>reflect</a> the content attribute
<{meta/http-equiv}>.
<h5 id="standard-metadata-names">Standard metadata names</h5>
This specification defines a few names for the <code>name</code> attribute of the
<{meta}> element.
Names are case-insensitive<span class="impl">, and must be compared in an
<a>ASCII case-insensitive</a> manner</span>.
: <dfn><code>application-name</code></dfn>
:: The value must be a short free-form string giving the name of the Web application that the page
represents. If the page is not a Web application, the <code>application-name</code> metadata
name must not be used. Translations of the Web application's name may be given, using the
<{global/lang}> attribute to specify the language of each name.
There must not be more than one <{meta}> element with a given <a>language</a> and
with its <code>name</code> attribute set to the value <code>application-name</code> per
document.
<div class="impl">
User agents may use the application name in UI in preference to the page's
<{title}>, since the title might include status messages and the like relevant to
the status of the page at a particular moment in time instead of just being the name of the
application.
To find the application name to use given an ordered list of languages (e.g., British
English, American English, and English), user agents must run the following steps:
1. Let <var>languages</var> be the list of languages.
2. Let <var>default language</var> be the <a>language</a> of the {{Document}}'s
<a>document element</a>, if any, and if that language is not unknown.
3. If there is a <var>default language</var>, and if it is not the same language as any of
the languages in <var>languages</var>, append it to <var>languages</var>.
4. Let <var>winning language</var> be the first language in <var>languages</var> for which
there is a <{meta}> element in the {{Document}} that has its
<code>name</code> attribute set to the value <code>application-name</code> and whose
<a>language</a> is the language in question.
If none of the languages have such a <{meta}> element, then abort these steps;
there's no given application name.
5. Return the value of the <code>content</code> attribute of the first <code>meta</code>
element in the {{Document}} in <a>tree order</a> that has its <code>name</code>
attribute set to the value <code>application-name</code> and whose <a>language</a> is
<var>winning language</var>.
<p class="note">
This algorithm would be used by a browser when it needs a name for the page, for instance,
to label a bookmark. The languages it would provide to the algorithm would be the user's
preferred languages.
</p>
</div>
: <dfn><code>author</code></dfn>
:: The value must be a free-form string giving the name of one of the page's authors.
: <dfn><code>description</code></dfn>
:: The value must be a free-form string that describes the page. The value must be appropriate for
use in a directory of pages, e.g., in a search engine. There must not be more than one
<{meta}> element with its <code>name</code> attribute set to the value
<code>description</code> per document.
: <dfn><code>generator</code></dfn>
:: The value must be a free-form string that identifies one of the software packages used to
generate the document. This value must not be used on pages whose markup is not generated by
software, e.g., pages whose markup was written by a user in a text editor.
<div class="example">
Here is what a tool called "Frontweaver" could include in its output, in the page's
<{head}> element, to identify itself as the tool used to generate the page:
<pre highlight="html"><meta name=generator content="Frontweaver 8.2"></pre>
</div>
: <dfn><code>keywords</code></dfn>
:: The value must be a <a>set of comma-separated tokens</a>, each of which is a keyword relevant
to the page.
<div class="example">
This page about typefaces on British motorways uses a <{meta}> element to specify
some keywords that users might use to look for the page:
<pre highlight="html">
<!DOCTYPE HTML>
<html lang="en-GB">
<head>
<title>Typefaces on UK motorways</title>
<meta name="keywords" content="british,type face,font,fonts,highway,highways">
</head>
<body>
...
</pre>
</div>
<p class="note">
Many search engines do not consider such keywords, because this feature has historically
been used unreliably and even misleadingly as a way to spam search engine results in a way
that is not helpful for users.
</p>
<div class="impl">
To obtain the list of keywords that the author has specified as applicable to the page, the
user agent must run the following steps:
1. Let <var>keywords</var> be an empty list.
2. For each <{meta}> element with a <code>name</code> attribute and a
<code>content</code> attribute and whose <code>name</code> attribute's value is
<code>keywords</code>, run the following substeps:
1. <a lt="split a string on commas">Split the value of the element's <code>content</code> attribute on commas</a>.
2. Add the resulting tokens, if any, to <var>keywords</var>.
3. Remove any duplicates from <var>keywords</var>.
4. Return <var>keywords</var>. This is the list of keywords that the author has specified as
applicable to the page.
User agents should not use this information when there is insufficient confidence in the
reliability of the value.
<p class="example">
For instance, it would be reasonable for a content management system to use the keyword
information of pages within the system to populate the index of a site-specific search
engine, but a large-scale content aggregator that used this information would likely find
that certain users would try to game its ranking mechanism through the use of
inappropriate keywords.
</p>
</div>
<h5 id="other-metadata-names">Other metadata names</h5>
<dfn lt="register the names|register the name|metadata names">Extensions to the predefined set of metadata names</dfn> may be registered in the
<a href="https://wiki.whatwg.org/wiki/MetaExtensions">WHATWG Wiki MetaExtensions page</a>. [[!WHATWGWIKI]]
Anyone is free to edit the WHATWG Wiki MetaExtensions page at any time to add a type. These new
names must be specified with the following information: