-
Notifications
You must be signed in to change notification settings - Fork 780
Expand file tree
/
Copy pathOverview.bs
More file actions
2287 lines (1993 loc) · 92 KB
/
Overview.bs
File metadata and controls
2287 lines (1993 loc) · 92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
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
<pre class='metadata'>
Title: CSS Shapes Module Level 1
Status: ED
Prepare for TR: no
Work Status: Testing
Shortname: css-shapes
Level: 1
Group: csswg
TR: https://www.w3.org/TR/css-shapes/
ED: https://drafts.csswg.org/css-shapes/
Previous Version: https://www.w3.org/TR/2025/CRD-css-shapes-1-20250612/
Editor: Rossen Atanassov, Microsoft Corporation, [email protected], w3cid 49885
Editor: Alan Stearns, Adobe, [email protected], w3cid 46659
Editor: Noam Rosenthal, Google, w3cid 121539
Former Editor: Vincent Hardy
Implementation Report: https://wpt.fyi/results/css/css-shapes
Abstract: CSS Shapes describe geometric shapes for use in CSS. For Level 1, CSS Shapes can be applied to floats. A circle shape on a float will cause inline content to <a>wrap</a> around the circle shape instead of the float's bounding box.
Repository: w3c/csswg-drafts
WPT Path Prefix: css/css-shapes/
WPT Display: open
</pre>
<pre class='link-defaults'>
spec:css2; type:property; text:margin
spec:css-backgrounds-3; type:property; text:border-radius
spec:css-inline; type:dfn; text:initial letter box
spec:css-masking-1; type: value
text: nonzero
text: evenodd
spec:css-shapes; type: value
text: closest-side
text: farthest-side
spec:svg2; type:property;
text:fill-rule
spec:css-values-5; type:value;
text:top;
text:right;
text:bottom;
text:left;
text:center;
text:x-start;
text:y-start;
text:x-end;
text:y-end;
</pre>
<style>
.singleImgExample {
display: block;
margin: auto;
}
</style>
<h2 id="intro">
Introduction</h2>
<em>This section is not normative.</em>
Shapes define arbitrary geometries
that can be used as CSS values.
This specification defines properties
to control the geometry
of an element's <a>float area</a>.
The 'shape-outside' property uses shape values
to define the <a>float area</a> for a float.
Note: Future levels of CSS Shapes will allow use of shapes
on elements other than floats.
Other CSS modules can make use of shapes as well,
such as CSS Masking [[CSS-MASKING]]
and CSS Exclusions [[CSS3-EXCLUSIONS]].
Note: If a user agent implements both CSS Shapes
and CSS Exclusions,
the 'shape-outside' property defines
the exclusion area for an exclusion.
Note: A future level of CSS Shapes will define a shape-inside property,
which will define a shape to <a>wrap</a> content within the element.
<h3 id="module-interactions">
Module Interactions</h3>
This module extends the float features defined in [[!CSS2]] chapter 9.
<h3 id="values">Values</h3>
This specification follows the <a href="https://www.w3.org/TR/CSS2/about.html#property-defs">CSS property definition conventions</a> from [[!CSS2]]
using the <a href="https://www.w3.org/TR/css-values-3/#value-defs">value definition syntax</a> from [[!CSS-VALUES-3]].
Value types not defined in this specification are defined in CSS Values & Units [[!CSS-VALUES-3]].
Combination with other CSS modules may expand the definitions of these value types.
In addition to the property-specific values listed in their definitions,
all properties defined in this specification
also accept the <a>CSS-wide keywords</a> as their property value.
For readability they have not been repeated explicitly.
<h3 id="terminology">
Terminology</h3>
<dfn data-lt="wrap|wrapping">Wrap</dfn>
This specification uses the term <a>wrap</a>
to refer to flowing content
around the sides of a <a>float area</a>,
defined in [[!CSS2]] chapter 9.
Content <a>wraps</a> around the right side
of a left-floated box,
and content <a>wraps</a> around the left side
of a right-floated box.
One result of this <a>wrapping</a>
is that line boxes next to a float
are shortened as necessary
to avoid intersections with the <a>float area</a>.
<dfn>Float area</dfn>
The area used
for <a>wrapping</a> content
around a float element.
The rules for float behavior
use the sides of the <a>float area</a>
to determine where content flows.
By default,
the <a>float area</a> is the float element's
<a>margin box</a>
(note this can be different than
the <a>float area</a> produced
by the ''margin-box'' value,
which includes border-radius curvature).
This specification's 'shape-outside'
and 'shape-margin' properties
can be used to define an arbitrary,
non-rectangular <a>float area</a>.
<dfn>direction-agnostic size</dfn>
The [=direction-agnostic size=] of a box is equal to the length of the diagonal of the box,
divided by sqrt(2).
Note: This is a method of averaging the width and height of a box
used by SVG in some cases,
when a percentage of a box's size is desired
but the context doesn't specifically favor the width or the height.
For square boxes, this is the same as the width/height.
<h2 id="relation-to-box-model-and-float-behavior">
Relation to the box model and float behavior</h2>
While the boundaries used
for <a>wrapping</a> inline flow content
outside a float
can be defined using shapes,
the actual box model does not change.
If the element has specified
margins, borders or padding
they will be computed and rendered
according to the [[!CSS3BOX]] module.
Also, float positioning and stacking are not affected
by defining a <a>float area</a> with a shape.
When a shape is used to define
a <a>float area</a>,
the shape is clipped
to the float's margin box.
In other words,
a shape can only ever reduce
a <a>float area</a>,
not increase it.
A reduced <a>float area</a> may have no effect
on some line boxes
that would normally be affected by the float.
If a shape does not enclose any area,
the shape’s edges are still used
to define the <a>float area</a>.
A <a>float area</a> defined by a shape
may reduce the normal <a>float area</a> on all sides,
but this does not allow content to <a>wrap</a>
on both sides of a float.
Left floats with a 'shape-outside' still
only allow content <a>wrapping</a> on the right side,
and right floats only allow <a>wrapping</a> on the left.
<div class="example">
In the following example
the left and right floating
<code class="html">img</code> elements
specify a triangular shape
using the 'shape-outside' property.
<pre><code>
<img class="left" src="hand.svg"/>
<img class="right" src="hand.svg"/>
<p>
Sometimes a web page's text content appears to be
funneling your attention towards a spot on the page
to drive you to follow a particular link. Sometimes
you don't notice.
</p>
<style type="text/css">
.left {
shape-outside: polygon(0 0, 100% 100%, 0 100%);
float: left;
width: 40%;
height: 12ex;
transform: scaleX(-1);
}
.right {
shape-outside: polygon(100% 0, 100% 100%, 0 100%);
float: right;
width: 40%;
height: 12ex;
}
p {
text-align: center;
}
</style>
</code>
</pre>
<img class="singleImgExample" src="images/hand-funnel.png" alt="Using the shape-outside property with floats">
</div>
<div class="example">
Since shapes are clipped to the float's margin box,
adding this shape to the left float above
would result in the same rendering.
<pre><code>
shape-outside: polygon(0 0, 500% 500%, 0 500%);
</code>
</pre>
</div>
<div class="example">
A shape that does not enclose any area
still has edges that contribute to the <a>float area</a>.
This inset shape is a vertical line positioned
at the midpoint of the reference box.
This midpoint edge is used as the edge
of the float area for wrapping content.
<pre><code>
shape-outside: inset(0% 50% 0% 50%);
</code></pre>
If inset values add up to more than the width,
[[css-backgrounds-3#corner-overlap]] rules are used to determine
the edges of the rectangle.
This shape results in a vertical edge
25% from the left side of the reference box.
<pre><code>
shape-outside: inset(0% 150% 50% 0%);
</code></pre>
If the shape is only a horizontal line,
then it is an empty float area and has no effect on wrapping.
Note that in this example shape-margin must be 0px
(otherwise the line would expand to enclose an area).
<pre><code>
shape-outside: inset(50% 0% 0% 50%);
shape-margin: 0px;
</code></pre>
</div>
<div class="example">
A 'shape-outside' can create open areas
on both the left and right
of a <a>float area</a>.
Content still <a>wraps</a> only on one side
of a float in this case.
In the picture,
the shape is rendered in blue,
and the content area outside the shape in mauve.
<pre><code>
shape-outside: polygon(50px 0px, 100px 100px, 0px 100px);
</code>
</pre>
<img class="singleImgExample" src="images/float-side-example.png" alt="wrapping around right side of a left-float float area">
</div>
<div class="example">
The following styling creates
a shape much smaller than
the float's content area,
and adds a margin-top to the float.
In the picture,
the shape is rendered in blue,
the content area outside the shape in mauve,
and the margin area of the float box in yellow.
The inline content only <a>wraps</a> around the shape,
and otherwise overlays the rest
of the float margin box.
<pre><code>
.float-left {
shape-outside: polygon(0% 50%, 50% 100%, 0 100%);
float: left;
width: 100px;
height: 100px;
margin-top: 20px;
}
</code></pre>
<img class="singleImgExample" src="images/float-margin-example.png" alt="Adding margin-top to a float with a small shape-outside">
The next picture shows a possible result
if two of these floats
were stacked next to each other.
Note that the floats are positioned
using their margin boxes,
not the <a>float area</a>.
<img class="singleImgExample" src="images/stacked-float-example.png" alt="Stacking two floats with a small shape-outside">
</div>
<h2 id="basic-shape-functions">
Basic Shapes</h2>
The <dfn><basic-shape></dfn> type
can be specified using basic shape functions.
When using this syntax
to define shapes,
the <dfn for="<basic-shape>" export>reference box</dfn> is defined
by each property that uses
<<basic-shape>> values.
The coordinate system for the shape
has its origin on the top-left corner of the
<a>reference box</a> with the x-axis
running to the right
and the y-axis running downwards.
All the lengths expressed in percentages
are resolved from the used dimensions
of the <a>reference box</a>.
<h3 id="supported-basic-shapes">
Supported Shapes</h3>
The <<basic-shape>> functions are:
<pre class=prod>
<<inset()>> = inset(
<<length-percentage>>{1,4}
[ round <<'border-radius'>> ]?
)
<<xywh()>> = xywh(
<<length-percentage>>{2} <<length-percentage [0, ∞]>>{2}
[ round <<'border-radius'>> ]?
)
<<rect()>> = rect(
[ <<length-percentage>> | auto ]{4}
[ round <<'border-radius'>> ]?
)
<dfn><basic-shape-rect></dfn> = <<inset()>> | <<rect()>> | <<xywh()>>
<<circle()>> = circle(
<<radial-size>>?
[ at <<position>> ]?
)
<<ellipse()>> = ellipse(
<<radial-size>>?
[ at <<position>> ]?
)
<<polygon()>> = polygon(
<<'fill-rule'>>?
[ round <<length>> ]? ,
[<<length-percentage>> <<length-percentage>>]#
)
<<path()>> = path(
<<'fill-rule'>>? ,
<<string>>
)
<<shape()>> = shape(
<<'fill-rule'>>?
from <<position>> ,
<<shape-command>>#
)
</pre>
<dl dfn-for="<basic-shape>">
<dt><dfn>inset()</dfn>
<dd>
Defines an inset rectangle
via insets from each edge of the [=reference box=].
If less than four <<length-percentage>> values are provided,
the omitted values default in the same way as the 'margin' shorthand:
an omitted second or third value defaults to the first,
and an omitted fourth value defaults to the second.
The four <<length-percentage>>s
define the position of the top, right, bottom, and left edges of a rectangle,
respectively,
as insets from the corresponding edges of the [=reference box=].
A pair of insets in either dimension
that add up to more than the used dimension
(such as left and right insets of 75% apiece)
use the [[css-backgrounds-3#corner-overlap]] rules
to proportionally reduce the inset effect to 100%.
<div class=example>
For example, specifying ''inset(75% 0 50% 0)''
has the top+bottom edges summing to 125%
of the [=reference box's=] height.
They're proportionally reduced to sum to 100%,
identical to specifying ''inset(60% 0 40% 0)''.
</div>
The optional <<'border-radius'>> argument(s)
define rounded corners for the rectangle
using the 'border-radius' shorthand syntax.
<wpt>
shape-functions/inset-function-computed.html
shape-functions/inset-function-invalid.html
shape-functions/inset-function-valid.html
</wpt>
<dt><dfn>xywh()</dfn>
<dd>
Defines a rectangle
via offsets from the top and left edge of the [=reference box=],
and a specified width and height.
The four <<length-percentage>>s define,
respectively,
the inset from the left edge of the [=reference box=],
the inset from the top edge of the [=reference box=],
the width of the rectangle,
and the height of the rectangle.
Note: This syntax is inspired by the <{svg/viewBox}> attribute from SVG.
The optional <<'border-radius'>> argument(s)
define rounded corners for the inset rectangle
using the 'border-radius' shorthand syntax.
<wpt>
shape-functions/xywh-function-computed.html
shape-functions/xywh-function-invalid.html
shape-functions/xywh-function-valid.html
</wpt>
<dt><dfn>rect()</dfn> =
<dd>
Defines a rectangle
via insets from the top and left edges of the [=reference box=].
The four <<length-percentage>>s
define the position of the top, right, bottom, and left edges of a rectangle,
respectively,
as insets from the top edge of the [=reference box=]
(for the first and third values)
or the left edge of the [=reference box=]
(for the second and fourth values).
An <css>auto</css> value makes the edge of the box
coincide with the corresponding edge of the [=reference box=]:
it's equivalent to ''0%''
as the first (top) or fourth (left) value,
and equivalent to ''100%''
as the second (right) or third (bottom) value.
The second (right) and third (bottom) values are floored
by the fourth (left) and second (top) values, respectively.
<div class='example'>
For example, specifying ''rect(10px 0 0 20px)''
would place the bottom edge higher than the top edge,
and the right edge further left than the left edge,
so both are corrected to not cross over the other edge,
identical to specifying ''rect(10px 20px 10px 20px)''.
</div>
Note: This syntax is similar,
but not quite identical,
to the legacy ''rect()'' function
used solely by the 'clip' property.
The optional <<'border-radius'>> argument(s)
define rounded corners for the rectangle
using the 'border-radius' shorthand syntax.)
<wpt>
shape-functions/rect-function-computed.html
shape-functions/rect-function-invalid.html
shape-functions/rect-function-valid.html
</wpt>
<dt><dfn>circle()</dfn>
<dd>
* The <<radial-size>> argument defines
the circle's radius.
Rather than referring to the [=gradient box=],
values are resolved against the [=reference box=].
Two <<length-percentage>> values are invalid.
If omitted it defaults to ''<radial-size>/closest-side''.
* The <<position>> argument defines
the center of the circle.
Unless otherwise specified,
this defaults to <css>center</css> if omitted.
<wpt>
shape-functions/circle-function-computed.html
shape-functions/circle-function-invalid.html
shape-functions/circle-function-valid.html
</wpt>
<dt><dfn>ellipse()</dfn>
<dd>
* The <<radial-size>> argument defines
the horizontal and vertical radiuses of the ellipse.
Rather than referring to the [=gradient box=],
values are resolved against the [=reference box=].
If omitted it defaults to ''<radial-size>/closest-side''.
* The <<position>> argument defines
the center of the ellipse.
Unless otherwise specified,
this defaults to <css>center</css> if omitted.
<wpt>
shape-functions/ellipse-function-computed.html
shape-functions/ellipse-function-invalid.html
shape-functions/ellipse-function-valid.html
</wpt>
<dt><dfn>polygon()</dfn>
<dd>
* The <<'fill-rule'>> specifies the filling rule used
to determine the interior.
Defaults to ''nonzero'' if omitted.
* An optional <<length>> after a <css>round</css> keyword
defines rounding for each vertex of the polygon.
The length is the radius of a circle
whose center lies on the bisector
of the smaller angle of the vertex,
and that is tangential
to both sides of the vertex.
<div class="example">
<figure>
<img src="images/vertex-rounding.png" alt="rounding concave and convex polygon vertices">
<figcaption>
Rounding polygon vertices that are both convex and concave.
</figcaption>
</figure>
</div>
To avoid rounding more
than half of any line segment,
the rounding of each vertex
must be clamped separately
such that the radius is never more than
the smaller of <code>tan(angle/2) segment / 2</code>
evaluated against both vertex line segments.
<div class="example">
<figure>
<img src="images/clamp-explanation.png" alt="visualization of clamp formula">
<figcaption>
This diagram shows the intent of the clamping formula.
</figcaption>
</figure>
</div>
* Each <<length-percentage>> pair
specifies a vertex of the polygon,
as a horizontal and vertical offset
from the left and top edges of the [=reference box=].
The UA must close a polygon
by connecting the last vertex
with the first vertex of the list.
<wpt>
shape-functions/polygon-function-computed.html
shape-functions/polygon-function-invalid.html
shape-functions/polygon-function-valid.html
</wpt>
<dt><dfn>path()</dfn>
<dd dfn-type=value dfn-for="path()">
* The <<'fill-rule'>> specifies the filling rule used
to determine the interior.
Defaults to ''nonzero'' if omitted,
unless the function is being used
in a context such as SVG shapes
where the 'fill-rule' property is relevant.
In that case an omitted value will use
the computed value of the 'fill-rule' property.
* The <<string>> represents an
<a href="https://www.w3.org/TR/SVG11/paths.html#PathData">SVG Path data string</a>.
A path data string that does not conform to the
to the grammar and parsing rules of SVG 1.1,
or that does conform but defines an empty path,
is [=invalid=] and causes the entire ''path()'' to be [=invalid=].
The initial position is defined
by the first “move to” argument
in the path string.
For the initial direction follow SVG 1.1.
The UA must close a path
with an implicit
closepath command ("z" or "Z")
if it is not present in the string
for properties that require a closed loop
(such as 'shape-outside' and 'clip-path').
<wpt>
shape-functions/path-function-computed.html
shape-functions/path-function-invalid.html
shape-functions/path-function-valid.html
</wpt>
<dt><dfn>shape()</dfn>
<dd dfn-type=value dfn-for="shape()">
See <a href="#shape-function">The shape() function</a>.
<wpt>
shape-functions/shape-function-computed.html
shape-functions/shape-function-invalid.html
shape-functions/shape-function-valid.html
</wpt>
</dl>
<h4 id='shape-function'>
The ''shape()'' Function</h4>
While the ''path()'' function allows reuse of the SVG path syntax
to define more arbitrary shapes than allowed by more specialized shape functions,
it requires writing a path as a single string
(which is not compatible with, for example, building a path piecemeal with ''var()''),
and inherits a number of limitations from SVG,
such as implicitly only allowing the ''px'' unit.
The ''shape()'' function uses a set of commands roughly equivalent to the ones used by ''path()'',
but does so with more standard CSS syntax,
and allows the full range of CSS functionality,
such as additional units and math functions.
The commands used by ''shape()'' are dynamically turned into path segments when it is used for rendering,
e.g., when computing the rendered 'clip-path'.
In that sense, ''shape()'' is a superset of ''path()''. A ''path()'' can be easily converted to a ''shape()'',
but to convert a ''shape()'' back to a ''path()'' or to SVG requires information about the CSS environment (e.g.
current values of CSS custom properties, current font size for ''em'' units, etc).
The <<'fill-rule'>> is interpreted identically to the same argument in ''path()''.
The rest of the arguments define a list of path data commands,
identical to that of an <a href="https://www.w3.org/TR/SVG11/paths.html#PathData">SVG Path</a>,
which the function represents.
The <css>from <<coordinate-pair>></css> represents the starting point for the first shape-command.
It adds an initial <a href="https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands">absolute moveto</a>
to the list of path data commands.
The sequence of <dfn><<shape-command>></dfn>s represent
further <a href="https://www.w3.org/TR/SVG11/paths.html#PathData">path data commands</a>.
Each command's starting point is the previous command's ending point.
<pre class=prod>
<<shape-command>> = <<move-command>> | <<line-command>> | close |
<<horizontal-line-command>> | <<vertical-line-command>> |
<<curve-command>> | <<smooth-command>> | <<arc-command>>
<<move-command>> = move <<command-end-point>>
<<line-command>> = line <<command-end-point>>
<<horizontal-line-command>> = hline
[ to [ <<length-percentage>> | left | center | right | x-start | x-end ]
| by <<length-percentage>> ]
<<vertical-line-command>> = vline
[ to [ <<length-percentage>> | top | center | bottom | y-start | y-end ]
| by <<length-percentage>> ]
<<curve-command>> = curve
[ [ to <<position>> with <<control-point>> [ / <<control-point>> ]? ]
| [ by <<coordinate-pair>> with <<relative-control-point>> [ / <<relative-control-point>> ]? ] ]
<<smooth-command>> = smooth
[ [ to <<position>> [ with <<control-point>> ]? ]
| [ by <<coordinate-pair>> [ with <<relative-control-point>> ]? ] ]
<<arc-command>> = arc <<command-end-point>>
[ [ of <<length-percentage>>{1,2} ]
&& <<arc-sweep>>? && <<arc-size>>? && [rotate <<angle>>]? ]
<<command-end-point>> = [ to <<position>> | by <<coordinate-pair>> ]
<<control-point>> = [ <<position>> | <<relative-control-point>> ]
<<relative-control-point>> = <<coordinate-pair>> [ from [ start | end | origin ] ]?
<<coordinate-pair>> = <<length-percentage>>{2}
<<arc-sweep>> = cw | ccw
<<arc-size>> = large | small
</pre>
<dl dfn-for="shape()">
<dt><dfn><<coordinate-pair>></dfn> = <<length-percentage>>{2}
<dd>Defines a pair of coordinates,
representing a rightward and downward offset, respectively,
from a specified reference point.
Percentages are resolved against the width or height, respectively,
of the [=reference box=].
<dt><dfn><<command-end-point>></dfn> = [ <dfn value for="shape(), <command-end-point>">to</dfn> <<position>> | <dfn value for="shape(), <command-end-point>">by</dfn> <<coordinate-pair>> ]
<dd>
Every command can be specified in "absolute" or "relative" coordinates,
determined by their ''shape()/by'' or ''shape()/to'' component.
''shape()/to'' indicates that any <<coordinate-pair>>s in the command
are relative to the top-left corner of the [=reference box=],
while ''shape()/by'' indicates that the <<coordinate-pair>>s
are relative to the command's starting point.
<<relative-control-point>> defines how ''shape()/by'' and ''shape()/to'' are interpreted for curve control points,
while <<horizontal-line-command>> and <<vertical-line-command>> define how ''shape()/by'' and ''shape()/to'' are
interpreted for horizontal and vertical lines, respectively.
When ''shape()/to'' is used, the coordinates can be specified as <<position>>s instead of <<coordinate-pair>>s.
Note: In either case, <<percentage>> values in <<coordinate-pair>>s
are always computed relative to the [=reference box's=] size.
<dt><dfn><<move-command>></dfn> = <dfn value>move</dfn> <<command-end-point>>
<dd>
Adds a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataMovetoCommands">moveto</a> command
to the list of path data commands,
with an ending point specified by the <<coordinate-pair>>.
This draws nothing,
and merely "moves the pen" for the next command.
Note: This starts a new subpath,
for the purpose of the ''close'' command.
<dt><dfn><<line-command>></dfn> = <dfn value>line</dfn> <<command-end-point>>
<dd>
Adds a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands">lineto</a> command
to the list of path data commands,
with an ending point specified by the <<coordinate-pair>>.
This draws a straight line from the command's starting point to its ending point.
<dt><dfn><<horizontal-line-command>></dfn> = hline [ to [ <<length-percentage>> | left | center | right | x-start | x-end ]
| by <<length-percentage>> ]
<dd>
Adds a horizontal
<a href="https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands">lineto</a> command
to the list of path data commands.
This is equivalent to a ''line'' command
with the <<length-percentage>> given as the horizontal component of the <<coordinate-pair>>.
Specifying the horizontal component of <<position>> instead of a <<length-percentage>> (''left'', ''center'', ''right'', ''x-start'', or ''x-end''),
would draw a line to that <<position>>, with the <<position>>'s vertical component remaining the same as the starting point.
<dt><dfn><<vertical-line-command>></dfn> = vline [ to [ <<length-percentage>> | top | center | bottom | y-start | y-end ] | by <<length-percentage>> ]
<dd>
Adds a vertical
<a href="https://www.w3.org/TR/SVG/paths.html#PathDataLinetoCommands">lineto</a> command
to the list of path data commands.
This is equivalent to a ''line'' command
with the <<length-percentage>> given as the vertical component of the <<coordinate-pair>>.
Specifying the horizontal component of <<position>>
(''top'', ''center'', ''bottom'', ''y-start'', or ''y-end'')
instead of a <<length-percentage>>,
would draw a line to that <<position>>, with the <<position>>'s horizontal component remaining the same as the starting point.
<dt><dfn><<curve-command>></dfn> = <dfn value>curve</dfn> [ [ to <<position>> with <<control-point>> [ / <<control-point>> ]? ]
| [ by <<coordinate-pair>> with <<relative-control-point>> [ / <<relative-control-point>> ]? ] ]
<dd>
Adds a Bézier curve command to the list of path data commands,
ending at the point specified by the <<position>> following the ''shape()/to'' keyword,
or the <<coordinate-pair>> following the ''shape()/by'' keyword, as specified by <<command-end-point>>.
The <css>with</css> component specifies control points for the curve:
if a single <<control-point>> or <<relative-control-point>> is provided,
the command specifies a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands">quadratic curve</a>;
if two <<control-point>>s or <<relative-control-point>>s are provided,
it specifies a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands">cubic curve</a>.
<dt><dfn><<smooth-command>></dfn> = <dfn value>smooth</dfn> [ [ to <<position>> [with <<control-point>> ]? ]
| [ by <<coordinate-pair>> [ with <<relative-control-point>> ]? ] ]
<dd>
Adds a smooth Bézier curve command to the list of path data commands,
ending at the point specified by the <<position>> following the ''shape()/to'' keyword, or the <<coordinate-pair>> following the ''shape()/by'' keyword, as specified by <<command-end-point>>.
The <css>with</css> component specifies control points for the curve:
if it's omitted,
the command specifies a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataQuadraticBezierCommands">smooth quadratic curve</a>;
if it's provided,
if specifies a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataCubicBezierCommands">smooth cubic curve</a>.
Note: A ''smooth'' command is equivalent to a ''curve'' command
with the first control point automatically specified
as the reflection of the previous curve's second control point
around the starting point,
or as the starting point if the previous path data command wasn't a curve.
This ensures G1 continuity with the previous command,
so the curve appears to smoothly continue from the previous command,
rather than possibly making a sudden direction change.
<dt><dfn><<control-point>></dfn> = [ <<position>> | <<relative-control-point>> ]
<dd>
Provides a control point to a quadratic or cubic Bézier curve.
<dt><dfn><<relative-control-point>></dfn> = <<coordinate-pair>> [ from [ start | end | origin ] ]?
<dd>
Provides a control point to a quadratic or cubic Bézier curve.
When a <css>from</css> keyword is specified followed by <css>start</css>, <css>end</css>, or <css>origin</css>,
the given <<coordinate-pair>> is relative to
the command's starting point, the command's end point, or the [=reference box=], respectively.
If such component is not provided, the <<coordinate-pair>> is relative to the segment's start.
<dt><dfn><<arc-command>></dfn> = <dfn value>arc</dfn> <<command-end-point>> [of <<length-percentage>>{1,2}] && <<arc-sweep>>? && <<arc-size>>? && rotate <<angle>>? ]
<dd>
Add an <a href="https://www.w3.org/TR/SVG/paths.html#PathDataEllipticalArcCommands">elliptical arc</a> command
to the list of path data commands,
ending at the <<command-end-point>>.
The <css>of</css> component specifies the size of the ellipse that the arc is taken from.
The first <<length-percentage>> provides the horizontal radius of the ellipse
and the second provides the vertical radius.
Like for <<coordinate-pair>>s,
<<percentage>> values are resolved against the width or height of the [=reference box=],
as appropriate.
If only one <<length-percentage>> is provided,
both radiuses use the provided value.
In that case, <<percentage>> values are resolved against the [=direction-agnostic size=] of the [=reference box=]
(similar to the ''circle()'' function).
<div class=note>
Note that SVG has [[svg2#ArcOutOfRangeParameters|some specific error-handling for the ellipse radiuses]]:
* if the endpoint is the same as the starting point, the command does nothing
* if either radius is zero, the command is equivalent to a <<line-command>> to the ending point
* if either radius is negative, its absolute value is used instead
* if the radiuses don't describe an ellipse large enough
to intersect both the starting point and ending point
(after rotation by the specified <<angle>>),
they are scaled up uniformly until the ellipse is just large enough to reach.
</div>
The ellipse described by the specified radiuses defaults to being axis-aligned,
but can be rotated by specifying an <<angle>>.
Similar to the ''rotate()'' transform function,
positive angles specify a clockwise rotation,
and negative angles specify a counterclockwise rotation.
If omitted, this defaults to ''0deg''.
The ending point, radiuses, and angle,
taken together,
usually define two possible ellipses
that intersect the starting point and ending point,
and each ellipse can be traced in either direction,
for a total of four possible arcs.
The <<arc-sweep>> and <<arc-size>> components specify which of these arcs is desired:
* <dfn><<arc-sweep>></dfn> can be <dfn value for="shape(), arc">cw</dfn> or <dfn value for="shape(), arc">ccw</dfn>,
indicating that the arc that is traced around the ellipse clockwise or counter-clockwise from the center, respectively,
must be chosen.
If omitted, this defaults to ''ccw''.
Note: In the SVG arc command, ''cw'' corresponds to the value 1 for the sweep flag, and ''ccw'' to the value 0.
* <dfn><<arc-size>></dfn> can be <dfn value for="shape(), arc">large</dfn> or <dfn value for="shape(), arc">small</dfn>,
indicating that the larger or smaller, respectively, of the two possible arcs
must be chosen.
If omitted, this defaults to ''small''.
Note: In the SVG arc command, ''large'' corresponds to the value 1 for the large flag, and ''small'' to the 0.
Note: If the starting and ending points are on exactly opposite sides of the ellipse,
both possible arcs are the same size,
but also there is only one possible ellipse.
In this case, the <<arc-sweep>> distinguishes which of the two possible arcs will be chosen,
and <<arc-size>> has no effect.
<figure>
<img src="images/four-arcs.svg" alt="a depiction of four possible arcs given a start and end point">
<figcaption>
A depiction of the two possible ellipses,
and four possible arcs,
that can be chosen between.
</figcaption>
</figure>
<dt><dfn value>close</dfn>
<dd>
Adds a <a href="https://www.w3.org/TR/SVG/paths.html#PathDataClosePathCommand">closepath</a> command
to the list of path data commands.
Note: This is similar to a ''line'' command
with its ending point set to the starting point of the subpath.
When specifying a raw shape, they're identical,
but if the path is stroked,
the ending point of the ''close'' command is smoothly joined
with the start of the subpath,
which affects how line-joins and line-caps are rendered.
</dl>
<h5 id=shape-examples>Using ''shape()'' to create responsive, parametric speech bubble</h5>
<div class=example>
The ''shape()'' function enables shapes that are responsive, rather than scalable.
While the ''polygon()'' shape is also responsive, it only support simple rounded corners and not complex curves.
To demonstrate, let's start with a speech bubble, such as the following:
<img src="images/bubble.svg" width=300 style="background: unset" alt="A speech bubble shape">
Using this shape with a ''clip-path'' can be done by using the ''path()'' function:
<pre highlight="css">
.bubble { clip-path: path("m 5 0 H 95 Q 100 0 100 5 V 92 Q 100 97 95 97 H 70 l -2 3 l -2 -3 H 5 Q 0 97 0 92 V 5 Q 0 0 5 0") };
</pre>
Altohugh this path can easily scale, the scaled results are not always desirable. e.g. when scaled to a small balloon, the arrow and corners are scaled to become almost invisible:
<img src="images/bubble.svg" width=100 style="background: unset" alt="scled-down speech bubble shape">
To construct this shape using the ''shape()'' function, let's start by turning all the pixel values from the ''path'' function to percentages.
Note that the ''shape()'' function begins with <css>from</css>:
<pre highlight="css">
.bubble { clip-path: shape( from 5% 0%,
hline to 95%,
curve to 100% 5% with 100% 0%,
vline to 92%,
curve to 95% 97% with 100% 97%,
hline to 70%,
line by -2% 3%,
line by -2% -3%,
hline to 5%,
curve to 0% 92% with 0% 97%,
vline to 5%,
curve to 5% 0% with 0% 0%); }
</pre>
To make this path responsive, as in, respond well to size changes, we will convert some of its units to ''px'' values,
specifically the ones the control the curves and arrows:
<pre highlight="css">
.bubble { clip-path: shape( from 5px 0%,
hline to calc(100% - 5px),
curve to 100% 5px with 100% 0%,
vline to calc(100% - 8px),
curve to calc(100% - 5px) calc(100% - 3px) with 100% calc(100% - 3px),
hline to 70%,
line by -2px 3px,
line by -2px -3px,
hline to 5px,
curve to 0% calc(100% - 8px) with 0% calc(100% - 3px),
vline to 5px,
curve to 5px 0% with 0% 0%); }
</pre>
When applied as ''clip-path'', it would looks like the following:
<p>
<img src="images/bubble-50.svg" width=150 style="background: unset" alt="A speech bubble shape, using clip-path">
</p>
The whole speech bubble is scaled to the reference box, while the curves and arrows stay more constant.
Since ''shape()'' uses CSS units, we can replace some of the edges with ''position'' values:
<pre highlight="css">
.bubble { clip-path: shape(from 5px 0,
hline to calc(100% - 5px),
curve to right 5px with right top,
vline to calc(100% - 8px),
curve to calc(100% - 5px) calc(100% - 3px) with right calc(100% - 3px),
hline to 70%,
line by -2px 3px,
line by -2px -3px,
hline to 5px,
curve to left calc(100% - 8px) with left calc(100% - 3px),
vline to 5px,
curve to 5px top with left top); }
</pre>
Another useful feature of ''shape()'' is that it can be used alongside CSS properties. In this case,