-
Notifications
You must be signed in to change notification settings - Fork 137
/
Copy pathstruct.html
3290 lines (2860 loc) · 144 KB
/
struct.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
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
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional+edit//EN" "xhtml1-transitional+edit.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:edit="http://xmlns.grorg.org/SVGT12NG/">
<head>
<title>Document Structure</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"/>
<!-- Style sheets for local dev. Will be standardized in processing.
Add attribute data-keep="" to any extra stylesheet link you do not want removed
(or use <style>), and include it before here. -->
<link rel="stylesheet" href="style/svg.css" type="text/css" />
<link rel="stylesheet" href="style/W3C-ED.css" type="text/css" />
</head>
<body>
<h1>Document Structure</h1>
<h2 id="NewDocument">Defining an SVG document fragment: the <span class='element-name'>'svg'</span> element</h2>
<edit:with element='svg'>
<h3 id="NewDocumentOverview">Overview</h3>
<p>An <a>SVG document fragment</a> consists of any number of SVG elements
contained within an <a>'svg'</a> element.</p>
<p>An SVG document fragment can range from an empty fragment (i.e.,
no content inside of the <a>'svg'</a> element), to a very simple SVG
document fragment containing a single SVG <a>graphics element</a>
such as a <a>'rect'</a>, to a complex, deeply nested collection of
<a>container elements</a> and <a>graphics elements</a>.</p>
<p>An SVG document fragment can stand by itself as a self-contained
file or resource, in which case the SVG document fragment is an <a>SVG
document</a>, or it can be embedded inline as a fragment within a parent
HTML or XML document.</p>
<p id="EmbeddedSVGExample">The following example shows simple SVG
content embedded inline as a fragment within a parent XML document.
Note the use of XML namespaces to indicate that the <a>'svg'</a> and
<a>'ellipse'</a> elements belong to the <a>SVG namespace</a>:</p>
<pre class='xml'><![CDATA[
<?xml version="1.0" standalone="yes"?>
<parent xmlns="http://example.org"
xmlns:svg="http://www.w3.org/2000/svg">
<!-- parent contents here -->
<svg:svg width="4cm" height="8cm">
<svg:ellipse cx="2cm" cy="4cm" rx="2cm" ry="1cm" />
</svg:svg>
<!-- ... -->
</parent>
]]></pre>
<p>This example shows a slightly more complex (i.e., it contains
multiple rectangles) stand-alone, self-contained SVG document:</p>
<edit:example href='images/struct/StandAlone01.svg' image='no'/>
<p><a>'svg'</a> elements can appear in the middle of SVG content. This
is the mechanism by which SVG document fragments can be embedded within
other SVG document fragments.</p>
<p>Another use for <a>'svg'</a> elements within the middle
of SVG content is to establish a new SVG viewport. (See
<a href="coords.html#EstablishingANewSVGViewport">Establishing a new
SVG viewport</a>.)</p>
<h3 id="Namespace">Namespace</h3>
<p>When SVG is parsed as a XML, for compliance with the
<a href="https://www.w3.org/TR/2006/REC-xml-names-20060816/"><cite>Namespaces in XML</cite></a> Recommendation
[<a href="refs.html#ref-xml-names">xml-names</a>], an SVG namespace
declaration must be provided so that all SVG elements are identified
as belonging to the SVG namespace.</p>
<p>When using the HTML syntax, the namespace is provided automatically by the HTML parser.</p>
<pre class='html'><![CDATA[
<html>
<svg viewBox="0 0 100 100">
<circle cx="50" cy="50" r="50" fill="green">
</svg>
</html>
]]></pre>
<p>As the example shows there's no need to have an <span class='attr-name'>'xmlns'</span>
attribute declaring that the element is in the SVG namespace when using the HTML parser.
The HTML parser will automatically create the SVG elements in the proper namespace.
</p>
<p class="issue" data-issue="1">This section should talk about how a document's behavior
is defined in terms of the DOM, and also explain how the HTML parser can
create SVG fragments.</p>
<p>The SVG 2 namespace is <code>http://www.w3.org/2000/svg</code>,
which is the same as for earlier versions of SVG.</p>
<p>The following are possible ways to
provide a namespace declaration when SVG is parsed as XML. An <span class='attr-name'>'xmlns'</span>
attribute without a namespace prefix could be specified on an
<a>'svg'</a> element, which means that SVG is the default namespace
for all elements within the scope of the element with the <span class='attr-name'>'xmlns'</span> attribute:</p>
<pre class='xml'><![CDATA[
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<rect x="10" y="10" width="80" height="80" fill="green" />
</svg>
]]></pre>
<p>If a namespace prefix is specified on the <span class='attr-name'>'xmlns'</span>
attribute (e.g., <code class='xml'>xmlns:svg="http://www.w3.org/2000/svg"</code>),
then the corresponding namespace is not the default namespace, so an
explicit namespace prefix must be assigned to the elements:</p>
<pre class='xml'><![CDATA[
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" viewBox="0 0 100 100">
<svg:rect x="10" y="10" width="80" height="80" fill="green" />
</svg:svg>
]]></pre>
<p>Namespace prefixes can be specified on ancestor elements (illustrated
in the <a href="#EmbeddedSVGExample">above example</a>). For more
information, refer to the <a href="https://www.w3.org/TR/2006/REC-xml-names-20060816/"><cite>Namespaces in XML</cite></a> Recommendation
[<a href="refs.html#ref-xml-names">xml-names</a>].</p>
<h3 id="Definitions">Definitions</h3>
<dl class="definitions">
<dt><dfn id="TermStructuralElement" data-dfn-type="dfn" data-export="">structural element</dfn></dt>
<dd>The structural elements are those which define the primary
structure of an SVG document. Specifically, the following
elements are structural elements:
<edit:elementcategory name='structural'/>.</dd>
<dt><dfn id="TermStructurallyExternalElement" data-dfn-type="dfn" data-export="">structurally external element</dfn></dt>
<dd>Elements that define its structure by reference to an external resource.
Specifically, the following elements are structurally external elements when
they have an <span class="attr-name">'href'</span> attribute:
<edit:elementcategory name='structurally external'/>.</dd>
<dt><dfn id="TermCurrentSVGDocumentFragment" data-dfn-type="dfn" data-export="">current SVG document fragment</dfn></dt>
<dd>The document sub-tree which starts with the outermost
ancestor <a>'svg'</a> element of a given SVG
element, with the requirement that all container elements
between the outermost <a>'svg'</a> and the given element are
all elements in the SVG namespace.</dd>
<dt><dfn id="TermOutermostSVGElement" data-dfn-type="dfn" data-export="">outermost svg element</dfn></dt>
<dd>The furthest <a>'svg'</a> ancestor element that remains in the
<a>current SVG document fragment</a>.</dd>
<dt><dfn id="TermSVGDocumentFragment" data-dfn-type="dfn" data-export="">SVG document fragment</dfn></dt>
<dd>A document sub-tree which starts with an <a>'svg'</a>
element which is either the root element of the document or whose parent
element is not in the SVG namespace.
An SVG document fragment can consist of a stand-alone SVG document,
or a fragment of a parent document enclosed by an <a>'svg'</a>
element.
However, an <a>'svg'</a> element that is a direct child of another SVG-namespaced element
is not the root of an SVG document fragment.
</dd>
<dt><dfn id="TermSVGElements" data-dfn-type="dfn" data-export="">SVG elements</dfn></dt>
<dd>Any element in the <a>SVG namespace</a>.</dd>
<dt id="TermGraphicsElement"><dfn id="graphics-element" data-dfn-type="dfn" data-export="">graphics element</dfn></dt>
<dd>One of the element types that can cause graphics to be
drawn onto the target canvas. Specifically:
<edit:elementcategory name='graphics'/>.</dd>
<dt id="TermGraphicsReferencingElement"><dfn id="graphics-referencing-element" data-dfn-type="dfn" data-export="">graphics referencing element</dfn></dt>
<dd>A graphics element which uses a reference to a different
document or element as the source of its graphical content.
Specifically: <edit:elementcategory name='graphics referencing'/>.</dd>
</dl>
<h3 id="SVGElement">The <span class='element-name'>'svg'</span> element</h3>
<div class="annotation svg2-requirement">
<table>
<tr>
<th>SVG 2 Requirement:</th>
<td>Support transforming <a>'svg'</a> elements.</td>
</tr>
<tr>
<th>Resolution:</th>
<td><a href="http://www.w3.org/2011/10/28-svg-irc#T00-23-44">We will allow <span class='attr-name'>'transform'</span> on <span class='element-name'>'svg'</span> in SVG 2.</a></td>
</tr>
<tr>
<th>Purpose:</th>
<td>To allow transforms on nested <a>'svg'</a> elements, in line with author expectations.</td>
</tr>
<tr>
<th>Owner:</th>
<td>Dirk (no action)</td>
</tr>
<tr>
<th>Status:</th>
<td>Done</td>
</tr>
</table>
</div>
<edit:elementsummary name='svg'/>
<p>
The <a>'x'</a> and <a>'y'</a> attributes specify the
top-left corner of the rectangular region into which an
embedded <a>'svg'</a> element is placed. On an <a>outermost svg element</a>,
these attributes have no effect.
</p>
<p>
For <a>outermost svg elements</a>,
the <a>'width property'</a> and <a>'height property'</a> attributes specify
the intrinsic size of the SVG document fragment.
For embedded <a>'svg'</a> elements, they specify the size
of the rectangular region into which the <a>'svg'</a> element
is placed.
In either case, a computed style of <span class="prop-value">auto</span>
is treated equivalent to <span class="prop-value">100%</span>.
</p>
<p>If an SVG document is likely to be referenced as a component
of another document, the author will often want to include a
<a>'viewBox'</a> attribute on the <a>outermost svg element</a> of the
referenced document. This attribute provides a convenient way to design
SVG documents to scale-to-fit into an arbitrary SVG viewport.</p>
<p id="SVGElementEventHandlerAttributes">The <a>'svg'</a> element exposes as <a>event handler content attributes</a> a number of the <a>event handlers</a> of the <a>Window</a> object. It also mirrors their <a>event handler IDL attributes</a>.</p>
<p>The <a href="interact.html">onblur</a>, <a>'onerror'</a>, <a href="interact.html">onfocus</a>, <a>'onload'</a>, and <a>'onscroll'</a> <a>event handlers</a> of the <a>Window</a> object, exposed on the <a>'svg'</a> element,
replace the generic <a>event handlers</a> with the same names normally supported by <a>SVG elements</a>.</p>
</edit:with>
<h2 id="Groups">Grouping: the <span class='element-name'>'g'</span> element</h2>
<h3 id="GroupsOverview">Overview</h3>
<dl class="definitions">
<dt id="TermContainerElement"><dfn id="container-element" data-dfn-type="dfn" data-export="">container element</dfn></dt>
<dd>An element which can have <a>graphics elements</a> and other
container elements as child elements. Specifically:
<edit:elementcategory name='container'/>.</dd>
</dl>
<p>The <a>'g'</a> element is a <a>container element</a> for grouping together
related <a>graphics elements</a>.</p>
<p>A group of elements, as well as individual objects, can be given
a name using the <a>'id'</a> attribute. Named groups are needed for
several purposes such as animation and re-usable objects.</p>
<p>An example:</p>
<edit:example href='images/struct/grouping01.svg' image='no' link='yes'/>
<p>A <a>'g'</a> element can contain other <a>'g'</a> elements nested
within it, to an arbitrary depth.</p>
<h3 id="GElement">The <span class='element-name'>'g'</span> element</h3>
<edit:elementsummary name='g'/>
<h2 id="Head">Defining content for reuse, and the <span class='element-name'>'defs'</span> element</h2>
<h3 id="Overview">Overview</h3>
<p>SVG allows a graphical object to be defined for later reuse.
To do this, SVG makes extensive use of the <a>URL reference</a>
construct [<a href="refs.html#ref-rfc3987">rfc3987</a>].
For example, to fill a rectangle with a linear gradient, a
<a>'linearGradient'</a> element may be defined with an
<a>'id'</a> property that may be referenced in the value for
the rectangle's <a>'fill'</a> property, as in the following:</p>
<pre class='xml'><![CDATA[
<linearGradient id="MyGradient">...</linearGradient>
<rect style="fill:url(#MyGradient)"/>
]]></pre>
<p>Some types of element, such as gradients, will not by themselves produce a graphical result. They can therefore be placed anywhere convenient. However, sometimes it is desired to define a graphical object and prevent it from being directly rendered. it is only there to be referenced elsewhere. To do this, and to allow convenient grouping defined content, SVG provides the <span class='element-name'>'defs'</span> element.</p>
<p>It is recommended that, where possible, referenced elements be defined
prior to the elements that use them, in document order.
Collecting all referenced elements
inside of a single <a>'defs'</a> element
near the top of the file
can make the markup easier to read and understand.
</p>
<h3 id="DefsElement">The <span class='element-name'>'defs'</span> element</h3>
<edit:elementsummary name='defs'/>
<p>The <a>'defs'</a> element is a container element for
<a href="struct.html#Head">referenced elements</a>. For understandability and
<a href="access.html">accessibility</a> reasons, it is recommended
that, whenever possible, referenced elements be defined inside
of a <a>'defs'</a>.</p>
<p>The content model for <a>'defs'</a> is the same as for the
<a>'g'</a> element; thus, any element that can be a child of a
<a>'g'</a> can also be a child of a <a>'defs'</a>, and vice versa.</p>
<p>Elements that are descendants of a <a>'defs'</a> are not rendered directly;
the <a>'display'</a> value for the <a>'defs'</a> element
must always be set to <span class="prop-value">none</span>
by the <a>user agent style sheet</a>,
and this declaration must have importance over any other CSS rule or presentation attribute.
Note, however, that the descendants of a <a>'defs'</a> are
always present in the source tree and thus can always be
referenced by other elements; thus, the value of the <a>'display'</a>
property on the <a>'defs'</a> element does not
prevent those elements from being referenced by other elements.</p>
<div class="ready-for-wider-review">
<h2 id="SymbolElement">The <span class='element-name'>'symbol'</span> element</h2>
<p>The <a>'symbol'</a> element is used to define graphical templates
which can be instantiated by a <a>'use'</a> element but which are not rendered
directly.</p>
<p>A <a>'symbol'</a> establishes a nested coordinate system
for the graphics it contains.
When a symbol is instantiated
as the <a>referenced element</a> of a <a>'use'</a> element,
it is therefore rendered very similarly to a nested <a>'svg'</a> element.</p>
<edit:elementsummary name='symbol'/>
<p>The <a>'x'</a>, <a>'y'</a>, <a>'width'</a>, and <a>'height'</a> geometry properties
have the same effect as on an <a>'svg'</a> element,
when the <a>'symbol'</a> is instantiated by a <a>'use'</a> element.
In particular, if <a>'width'</a> and <a>'height'</a>
compute to <span class="prop-value">auto</span>
(and are not over-ridden by values on the instantiating <a>'use'</a> element),
then they will be treated as a value of <span class="prop-value">100%</span>.
</p>
<p class="note">
New in SVG 2.
Allowing geometry properties to be specified on a symbol
provides a more consistent rendering model,
and allows authors to set a default size for each symbol
(which may still be over-ridden by attributes on the <a>'use'</a> element).
</p>
<edit:with element='symbol'>
<h3 id="SymbolAttributes">Attributes</h3>
<dl class="attrdef-list">
<dt>
<table class="attrdef def">
<tr>
<th>Name</th>
<th>Value</th>
<th>Initial value</th>
<th>Animatable</th>
</tr>
<tr>
<td><dfn data-dfn-type="element-attr" data-dfn-for="symbol" id="SymbolElementRefXAttribute">refX</dfn></td>
<td><a><length></a> | left | center | right</td>
<td>(none)</td>
<td>yes</td>
</tr>
<tr>
<td><dfn data-dfn-type="element-attr" data-dfn-for="symbol" id="SymbolElementRefYAttribute">refY</dfn></td>
<td><a><length></a> | top | center | bottom</td>
<td>(none)</td>
<td>yes</td>
</tr>
</table>
</dt>
<dd>
<p class="note">
New in SVG 2. Added to make it easier to align symbols to a
particular point, as is often done in maps. Similar to the
matching attributes on <a>'marker element'</a>.
</p>
<p class="annotation">
Add refX/refY to symbol element. Resolved at
<a href="http://www.w3.org/2014/04/08-svg-minutes.html#item12">Leipzig F2F</a>.
Status: Done.
</p>
<p class="annotation">
We will add top/center/bottom, left/center/right keywords to
refX/refY on marker/symbol. Resolved at
<a href="http://www.w3.org/2014/08/26-svg-minutes.html#item07">London
F2F</a>. Values inspired by
<a href="https://www.w3.org/TR/css3-background/#the-background-position">'background-position'</a>.
Status: Done.
</p>
<p>
The <a>'refX'</a> and <a>'refY'</a> attributes define the
reference point of the symbol which is to be placed exactly at
the symbol's <span class="prop-value">x,y</span> positioning coordinate,
as defined by the cumulative effect of the <a>'x'</a> and <a>'y'</a>
properties and any transformations on the <a>'symbol'</a>
and its <a>host</a> <a>'use'</a> element.
</p>
<p>
Keyword values have the same meaning as for the
<a>'marker/refX'</a> and <a>'marker/refY'</a> attributes on the <a>'marker element'</a> element,
resolving to 0%, 50%, or 100% in the applicable direction.
</p>
<p>
Unlike other positioning attributes,
<a>'refX'</a> and <a>'refY'</a>
are interpreted as being in the coordinate system of the
symbol contents, after application of the <a>'viewBox'</a>
and <a>'preserveAspectRatio'</a> attributes.
If one or both of the attributes is not specified,
no adjustment is made in the corresponding dimension,
and the top or left side of the symbol's rectangular viewport region
(regardless of the <a>'viewBox'</a> coordinates)
is positioned at the <span class="prop-value">x,y</span> point.
</p>
<p class="note">
For backwards compatibility,
the behavior when <a>'refX'</a> and <a>'refY'</a>
are not specified on a <a>'symbol'</a>
is different from when they are specified with a value of <span class="attr-value">0</span>,
and therefore different from the behavior
when equivalent attributes are not specified on a <a>'marker element'</a>.
</p>
</dd>
</dl>
<h3 id="SymbolNotes">Notes on symbols</h3>
<p>The use of <a>'symbol'</a> elements for graphics that are used multiple
times in the same document adds structure and semantics.
Closely related to the <a>'symbol'</a> element are the
<a>'marker element'</a> and <a>'pattern'</a> elements;
all three define a container of graphical content
that can be rendered repeatedly at various positions and scales in the SVG.
However, while <a>re-used graphics</a> in a pattern and marker
provide a graphical effect on another element,
the content in a <a>'symbol'</a> will be embedded
as fully interactive content, within a <a>use-element shadow tree</a>.
</p>
<p>The <a href="styling.html#UAStyleSheet">user agent style sheet</a> sets
the <a>'overflow'</a> property for <a>'symbol element'</a> elements to
<span class="prop-value">hidden</span>, which causes a rectangular clipping
path to be created at the bounds of symbol's SVG viewport. Unless the
<a>'overflow'</a> property is overridden, any graphics within the symbol which
goes outside of the symbol's SVG viewport will be clipped.</p>
<p><a>'symbol'</a> elements must never be rendered directly;
their only usage is as something that can be referenced
using the <a>'use'</a> element.
<!--
The <a>'display'</a> property does not apply
to the <a>'symbol'</a> element; thus, <a>'symbol'</a> elements are
not directly rendered even if the <a>'display'</a> property is set to a
value other than <span class="prop-value">none</span>, and <a>'symbol'</a>
elements are available for referencing even when the
<a>'display'</a> property on the <a>'symbol'</a> element or any of its
ancestors is set to <span class="prop-value">none</span>.
-->
The user agent must set the
<a>'display'</a> property on the <a>'symbol'</a> element
to <span class="prop-value">none</span>,
as part of the <a>user agent style sheet</a>,
and this declaration must have importance over any other CSS rule or presentation attribute.
</p>
<p>The generated <a>instance</a> of a <a>'symbol'</a>
that is the direct <a>referenced element</a> of a <a>'use'</a> element
must always have a computed value of <span class="prop-value">inline</span>
for the <a>'display'</a> property.
In other words, it must be rendered whenever the host <a>'use'</a> element is rendered.
The <a>user agent style sheet</a> again defines this
declaration to have importance over any other CSS rule or presentation attribute.
Any other <a>'symbol'</a> that is cloned
to create an <a>element instance</a>
within the <a>use-element shadow tree</a>
behaves as a symbol definition, and must not be rendered.
</p>
</edit:with>
<h2 id="UseElement">The <span class='element-name'>'use'</span> element</h2>
<div class="annotation svg2-requirement">
<table>
<tr>
<th>SVG 2 Requirement:</th>
<td>Allow <a>'use'</a> to reference an external document's root element by omitting the fragment.</td>
</tr>
<tr>
<th>Resolution:</th>
<td><a href="http://www.w3.org/2011/10/28-svg-irc#T00-33-43">We will relax referencing requirements to particular elements to allow dropping fragments to mean referencing root element, where it makes sense, such as with use, in SVG 2.</a></td>
</tr>
<tr>
<th>Purpose:</th>
<td>To avoid requiring authors to modify the referenced document to add an ID to the root element.</td>
</tr>
<tr>
<th>Owner:</th>
<td>Cameron (<a href="http://www.w3.org/Graphics/SVG/WG/track/actions/3417">ACTION-3417</a>)</td>
</tr>
<tr>
<th>Status:</th>
<td>Done</td>
</tr>
</table>
</div>
<edit:with element='use'>
<edit:elementsummary name='use'/>
<p>The <a>'use'</a> element
references another element, a copy of which
is rendered in place of the <a>'use'</a> in the document.
The <a>referenced element</a> may be a <a>container element</a>,
in which case a copy of
the complete SVG document subtree rooted at that element is used.
</p>
<p>
The cloned content inherits styles from the <a>'use'</a> element
and can be the target of user events.
However, these cloned <a>element instances</a> remain linked to the referenced source
and reflect DOM mutations in the original.
In addition, all style rules that apply in the scope of the referenced element
also apply in the scope of the cloned <a>shadow tree</a>.
</p>
<p>The <a>'x'</a>, <a>'y'</a>, <a>'width'</a> and <a>'height'</a>
geometric properties specify the positioning of the referenced element.
The <a>'width'</a> and <a>'height'</a> attributes
only have an effect if the <a>referenced element</a>
defines a viewport (i.e., if it is a <a>'svg'</a> or <a>'symbol'</a>);
if so, a value other than <span class="prop-value">auto</span>
for the <a>'use'</a> element overrides the value
of the corresponding geometric property on that element.
</p>
<p>A negative value for <a>'width'</a> or <a>'height'</a>
is <a>invalid</a> and must be <a>ignored</a>.
If <a>'width'</a> or <a>'height'</a> is zero,
and the properties have an effect on the <a>referenced element</a>,
then rendering of that element will be disabled.</p>
<p class="note">
The <a>'x'</a> and <a>'y'</a> properties
affect the user coordinate system for the element.
See the <a href="#UseLayout">Layout</a> section for implementation details.
</p>
<dl class="attrdef-list">
<dt>
<table class="attrdef def">
<tr>
<th>Name</th>
<th>Value</th>
<th>Initial value</th>
<th>Animatable</th>
</tr>
<tr>
<td><dfn id="UseElementHrefAttribute">href</dfn></td>
<td>URL <a href="types.html#attribute-url" class="syntax">[URL]</a></td>
<td>(none)</td>
<td>yes</td>
</tr>
</table>
</dt>
<dd>
<p>An <a href="linking.html#URLReference">URL reference</a> to the
element/fragment within an SVG document to be cloned for
rendering.</p>
<p>The <a>'use'</a> element can reference an entire SVG document
by specifying an <a>'href'</a> value without a fragment.
Such references are taken to be referring to the root element
of the referenced document.</p>
Refer to the common handling defined for <a
href="linking.html#linkRefAttrs">URL reference attributes</a> and
<a href="linking.html#XLinkRefAttrs">deprecated XLink attributes</a>.
</dd>
</dl>
<p class="note">New in SVG 2.
An <a>'href'</a> without a fragment allows an entire SVG document to be referenced
without having to ensure that it has an ID on its root element.</p>
<p>
User agents may restrict external resource documents for security
reasons. In particular, this specification does not allow cross-origin and <a href="linking.html#TermDataURL">data URL</a> resource requests in <a>'use'</a>.
</p>
<p>When the <a>'href'</a> attribute is set
(or, in the absence of an <a>'href'</a> attribute, an <a>'xlink:href'</a> attribute),
the user agent must <a href="linking.html#processingURL">process the URL</a>.
The target element that results from URL processing is the <a>referenced element</a> of the <a>'use'</a>.
</p>
<p>If the <a>referenced element</a> that results from resolving the URL
is not an SVG element,
then the reference is <a>invalid</a> and the <a>'use'</a> element is in error.
</p>
<p>
If the referenced element is a (shadow-including) ancestor
of the <a>'use'</a> element,
then this is an <a>invalid circular reference</a>
and the <a>'use'</a> element is in error.
</p>
<p>
Otherwise, the user agent must generate a <a>shadow tree</a>
of <a>re-used graphics</a> to render as the contents of the <a>'use'</a> element,
as described in the next section, <a href="#UseShadowTree">The use-element shadow tree</a>.
</p>
<p>A <a>'use'</a> that has an <a>unresolved</a> or <a>invalid</a> URL reference
is not rendered.
For the purpose of bounding box calculations,
it is equivalent to an empty container element.</p>
<h3 id="UseShadowTree">The use-element shadow tree</h3>
<p>The <a>re-used graphics</a> generated by a <a>'use'</a> element
are defined in terms of a <a>shadow tree</a>.
In terms of interactivity and style inheritance,
they are therefore quite different from other types of <a>re-used graphics</a> in SVG,
such as <a>'pattern'</a> and <a>'marker element'</a> content.
</p>
<p>
Elements in the shadow tree are rendered as if
the <a>'use'</a> element was a container and they were its children.
However, the SVG Document Object Model (DOM) only contains
the <a>'use'</a> element and its attributes.
The SVG DOM does not include the
element instances as children of the <a>'use'</a> element.
</p>
<p>User agents that support scripting and the document object model
must implement the <a>use-element shadow tree</a> as described in this section
and in conformance with the <a href="refs.html#ref-dom">dom</a> specification <a href="refs.html#ref-dom">[dom]</a>,
or its future replacement.
In contrast, user agents that do <em>not</em> support
the dynamic interactive processing mode
may not need to implement all the details of the shadow DOM.
However, all user agents must ensure that the <a href="#UseLayout">layout</a>
and <a href="#UseStyleInheritance">style inheritance</a> for the re-used graphics
and <a href="#UseAnimations">declarative animations</a> if applicable,
are rendered in the same way as if the shadow DOM was implemented.
</p>
<p>The following definitions apply when discussing <a>'use'</a> elements
and their shadow trees:</p>
<dl>
<dt><dfn id="TermReferencedElement">referenced element</dfn></dt>
<dd>The element specified by the <a>'href'</a> (or <a>'xlink:href'</a>) attribute on the <a>'use'</a> element, or the root element of a document referenced by that attribute if the URL provided does not include a target fragment that links to a specific element <a>'id'</a>.</dd>
<dt><dfn id="TermReferencedDocumentSubtree">referenced document subtree</dfn></dt>
<dt>referenced graphics</dt>
<dd>The referenced element, and all of its descendent nodes.</dd>
<dt><dfn id="TermShadowRoot">shadow root</dfn></dt>
<dd>A <a>ShadowRoot</a> object,
a type of <a>DocumentFragment</a> node which is associated with a host <a>Element</a>,
and which contains the content that will be used to render that host.
A shadow root should be implemented in conformance with the <a href="refs.html#ref-dom">dom</a> specification <a href="refs.html#ref-dom">[dom]</a>,
or its future replacement.
</dd>
<dt><dfn id="TermShadowHost">shadow host</dfn></dt>
<dt>host</dt>
<dd>An element that has an associated shadow root;
usage is consistent the definition of <a href="https://dom.spec.whatwg.org/#concept-documentfragment-host">host</a> in the DOM standard.
</dd>
<dt><dfn id="TermShadowTree">shadow tree</dfn></dt>
<dd>A node tree whose root is a shadow root;
usage is consistent the definition of <a href="https://dom.spec.whatwg.org/#shadow-trees">shadow tree</a> in the DOM standard.
</dd>
<dt><dfn id="TermUseElementShadowTree">use-element shadow tree</dfn></dt>
<dd>A shadow tree whose host is a <a>'use'</a> element,
which contains element instances generated by cloning the referenced graphics.
</dd>
<dt><dfn id="TermElementInstance">element instance</dfn></dt>
<dt>instance</dt>
<dd>An element in the <a>use-element shadow tree</a>,
which is generated by cloning a corresponding element in the referenced document subtree.
</dd>
<dt><dfn id="TermInstanceRoot">instance root</dfn></dt>
<dd>The <a>element instance</a> for the referenced element;
it is always a direct child of the <a>'use'</a> element's shadow root.
</dd>
<dt><dfn id="TermCorrespondingElement">corresponding element</dfn></dt>
<dd>For each element instance,
the element in the referenced document subtree from which it is cloned.</dd>
<dt><dfn id="TermCorrespondingUseElement">corresponding use element</dfn></dt>
<dd>For each element instance,
the <a>'use'</a> element which causes it to be rendered in the document.
This is the instance's shadow root's host <a>'use'</a> element
<em>if</em> that element is not itself an element instance within a <a>'use'</a> element shadow tree,
or is that element's corresponding use element otherwise,
recursively exiting shadow trees as many times as necessary
to reach a <a>'use'</a> element that was not itself generated
as part of the shadow tree of another <a>'use'</a> element.
</dd>
</dl>
<p>When the user agent successfully resolves a <a>'use'</a> element
to identify a <a>referenced element</a>,
the user agent must create a
<a>use-element shadow tree</a> whose host is the <a>'use'</a> element itself.
The shadow tree must be created even if
the <a>'use'</a> element is not rendered
because it is a descendent of a <a>never-rendered element</a>,
because of conditional processing,
or because of the <a>'display'</a> property being set to <span class="prop-value">none</span>
on it or an ancestor element.
</p>
<p>
Each node in the shadow tree is an <a>instance</a> of a corresponding node
from the <a>referenced document subtree</a>.
The shadow nodes all descend from the <a>instance root</a>,
which is the instance of the <a>referenced element</a>,
and which itself is a direct child of the <a>shadow root</a> node.
</p>
<p>
The shadow tree is open (inspectable by script), but read-only.
Any attempt to directly modify the elements, attributes, and other nodes in the shadow tree
must throw a <code>NoModificationAllowedError</code>.
</p>
<p>
Within a <a>use-element shadow tree</a>,
<a>'script'</a> elements are inert (do not execute).
</p>
<p class="note">
Previous versions of SVG restricted the contents
of the shadow tree to SVG graphics elements.
This specification allows any valid SVG document subtree
to be cloned.
Cloning non-graphical content, however,
will not usually have any visible effect.
</p>
<p>
If the <a>referenced element</a> is in an external file,
then all <a>URL references</a> in attributes and style properties
must be made absolute as described in <a href="linking.html#processingURL-absolute">Generating the absolute URL</a>,
before copying the value to the <a>element instances</a>.
The shadow tree itself uses the same document base URL
as the document that includes it.
</p>
<p>
The user agent must ensure that
all mutations to the <a>referenced document subtree</a> are reflected in the shadow tree.
This includes changes to elements, attributes, and text and other nodes.
In addition, changes to the stylesheets in effect for the referenced graphics
must be reflected in changes to the stylesheets in the shadow tree's scope,
as described further in the section on <a href="#UseStyleInheritance">style inheritance</a>.
</p>
<p>
If either the <a>'use'</a> element or the <a>referenced element</a> is altered
in a way that causes the <a>'use'</a> element's URL reference to become <a>unresolved</a> again,
then the entire shadow tree for that use element is discarded.
</p>
<p>When a <a>'use'</a> references
another element which is another <a>'use'</a> or whose content contains a
<a>'use'</a> element, then the shadow DOM
cloning approach described above is recursive. However, a set
of references that directly or indirectly reference a element
to create a circular dependency is an <a>invalid circular reference</a>.
The <a>'use'</a> element or element instance
whose shadow tree would create the circular reference
is in error and must not be rendered by the user agent.</p>
<h3 id="UseLayout">Layout of re-used graphics</h3>
<p>The value of the <a>'x'</a>, <a>'y'</a>, <a>'width'</a> and <a>'height'</a> properties
on a <a>'use'</a> element
are used to position the re-used graphics
and to set the viewport size
if the <a>referenced element</a> defines a nested viewport.
The effect of these properties on a <a>'use'</a> element
is notably different from their effect on a <a>graphics element</a>,
or from their effect in CSS box layout.
</p>
<p>
The <a>'x'</a> and <a>'y'</a> properties define
an additional transformation
(<span class="attr-value">translate(x,y)</span>,
where <span class="attr-value">x</span>
and <span class="attr-value">y</span> represent the computed value of the corresponding property)
to be applied to the <a>'use'</a> element,
after any transformations specified with other properties
(i.e., appended to the right-side of the transformation list).
</p>
<div class="note">
<p>
For historical reasons,
the supplemental transformation is applied to the <a>'use'</a> element itself,
rather than solely to the re-used content in the shadow tree.
This affects the coordinate system used for
any masks, clipping paths, or filters
applied to the <a>'use'</a> element
and calculated in <span class="attr-value">userSpaceOnUse</span> units.
</p>
<p>
To apply <span class="attr-value">userSpaceOnUse</span> graphical effects in an un-transformed coordinate space,
while also using the <a>'x'</a> and <a>'y'</a> to position the graphics,
authors can nest the <a>'use'</a> element inside a <a>'g'</a>,
and apply the graphical effects to the <a>'g'</a> element.
</p>
</div>
<p>
The <a>'width'</a> and <a>'height'</a> properties
on the <a>'use'</a> element
override the values for the corresponding properties
on a referenced <a>'svg'</a> or <a>'symbol'</a> element
when determining the used value for that property on the <a>instance root</a> element.
However, if the computed value for the property on the <a>'use'</a> element is <span class="prop-value">auto</span>,
then the property is computed as normal for the element instance.
</p>
<p>
These properties can therefore be used to scale a graphic
that defines its own coordinate system,
each time it is re-used.
Because <span class="prop-value">auto</span> is the initial value,
if dimensions are not explicitly set on the <a>'use'</a> element,
the values set on the <a>'svg'</a> or <a>'symbol'</a> will be used as defaults.
</p>
<p>
The <a>'width'</a> and <a>'height'</a> properties
on the <a>'use'</a> element have no effect
if the <a>referenced element</a> does not
<a href="coords.html#EstablishingANewSVGViewport">establish a new viewport</a>.
In particular, the <a>'use'</a> element does not itself establish a new viewport,
and therefore does not affect the interpretation of percentages in the re-used graphics.
</p>
<p>
In all other ways,
rendering and layout of elements within the
<a>use-element shadow tree</a>
occurs as if the <a>'use'</a> element was a container for its shadow content.
In particular, unless elements within the shadow tree establish a new viewport,
they must be drawn in the coordinate system in which the <a>'use'</a> element is defined
(including any cumulative transformations).
This affects the interpretation of percentage lengths,
and also graphical effects with <span class="prop-value">userSpaceOnUse</span> units.
</p>
<h3 id="UseStyleInheritance">Style Scoping and Inheritance</h3>
<p>The <a>use-element shadow tree</a>, like other shadow trees,
exhibits style encapsulation,
as defined in the <a href="https://www.w3.org/TR/css-scoping-1/">CSS Scoping</a> module <a href="refs.html#ref-css-scoping-1">[css-scoping-1]</a>.
This means that elements in the shadow tree inherit styles
from its <a>host</a> <a>'use'</a> element,
but that style rules defined in the outer document
do not match the elements in the shadow tree.
Instead, the shadow tree maintains its own list of stylesheets,
whose CSS rules are matched against elements in the shadow tree.
</p>
<p class="note">
Presentation attributes and the <a>'style attribute'</a> attribute
are cloned from the elements in the <a>referenced graphics</a>
into the <a>element instances</a>
in the same manner as other attributes.
</p>
<p>
When the <a>referenced element</a>
is from the same document as the <a>'use'</a> element,
the same document stylesheets will apply in
both the original document and the shadow tree document fragment.
Any changes to the stylesheets in the main document
also affect the shadow tree;
the <code>StyleSheetList</code> object accessed through the
document and shadow root document fragment's
<code>styleSheets</code> properties must be identical.
If a <a>'style element'</a> element is duplicated
as part of the <a>referenced document subtree</a>,
then the <code>styleSheet</code> property on the <a>element instance</a>
points to the same object as for the <a>corresponding element</a>.
</p>
<p>
When the <a>referenced element</a>
is from an external document,
the stylesheet objects generated when processing that document
apply to the shadow tree, and are read-only.
All <a>URL references</a> in the stylesheet,
including fragment-only references,
must be made absolute, relative to the URL of the document
that contains the <a>referenced element</a>.
User agents may re-use the same stylesheet objects for any shadow trees
that reference that same external document.
</p>
<p>
Style rules that are scoped to the shadow tree
cannot normally affect any elements in the main document.
Similarly, style rules in the main document can only
affect the shadow tree elements by changing inherited values.
However, <a href="https://www.w3.org/TR/css-scoping-1/">CSS Scoping</a>
defines special selectors for styling the <a>host</a> element from within the shadow tree,
or for adjusting styles within the shadow tree
in response to changes in the host's context
<a href="refs.html#ref-css-scoping-1">[css-scoping-1]</a>.
</p>
<p>
CSS media queries within a shadow tree's scope
are evaluated using the same device features and dimensions
as the corresponding "light" document
(that is, the document that contains the <a>corresponding use element</a>
for the shadow tree, after recursively exiting all nested shadow trees).
</p>
<div class="note">
<p>
In most cases,
the <a>element instance</a> in the shadow tree will match the same style rules
as its <a>corresponding element</a> in the original document.
However, if a CSS rule uses a <a href="https://drafts.csswg.org/selectors/#complex">complex selector</a>
to match an element based on its ancestors or siblings,
and those ancestors or siblings are not cloned as part of the shadow tree,
then that rule would no longer match the <a>element instance</a>.
Similarly, child-indexed pseudo-classes
such as <code>nth-of-type</code> and <code>nth-child</code>
may apply to one element but not the other.
This represents a change
from how style cloning was defined in previous versions of SVG.
</p>
<p>
The following example demonstrates both the consistent and changed style-matching rules.
The circle on the left is re-used to draw the circle on the right.
The original circle has styles set in various ways:
</p>
<ul>
<li><a>'stroke-width'</a> (20) is set in a presentation attribute on the circle itself.</li>
<li><a>'stroke-opacity'</a> (0.7) is set via a CSS rule with a simple selector matching the circle tag name.</li>
<li><a>'stroke'</a> color (green) is set using a complex CSS selector, matching the circle as a descendent of an element with class <code>special</code>.</li>
<li><a>'fill'</a> color is not set directly on the circle, so is inherited from the style set on the containing <a>'g'</a> element (blue).</li>
</ul>
<p>
In the SVG 1.1 style-cloning model,
the <a href="https://www.w3.org/TR/css-cascade-3/#specified">specified style values</a>
would be cloned from the original element to the element instance.
The re-used circle would have the same styles as the original,
except that the <a>'fill'</a> value would be inherited from the <a>'use'</a> (orange)
instead of from the <a>'g'</a> (blue).
</p>
<p>
In the shadow DOM model required by SVG 2,
the styles for the re-used circle are calculated as follows:
</p>
<ul>
<li>the <a>'stroke-width'</a> (20) presentation attribute is cloned to the element instance.</li>
<li>the CSS rule setting <a>'stroke-opacity'</a> (0.7) is part of the CSS stylesheet cloned into the shadow tree; it matches the circle tag name of the <a>element instance</a>, so is applied.</li>
<li>the CSS rule with the complex selector is also part of the cloned stylesheet, but it does not match the <a>element instance</a> of the circle, which is not a descendent of an element with class <code>special</code>; instead, <a>'stroke'</a> color on the circle is inherited from the host <a>'use'</a> element (purple).</li>
<li><a>'fill'</a> color is still not set directly, so is once again inherited from the host <a>'use'</a> element.</li>
</ul>
<p>
The re-used circle therefore differs from the original in both fill color (because it inherits from a different element) and stroke color (because the complex selector no longer matches).
</p>
<edit:example href='images/struct/Use-changed-styles.svg' name='Use-changed-styles' description="A 'use' element copying a 'circle', with various style matching rules demonstrated" link='yes' image='yes'/>
<p>
Previous versions of SVG
were not clear about how dynamic pseudo-classes