-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
186 lines (144 loc) · 4.61 KB
/
index.md
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
---
title: stroke-linecap
slug: Web/SVG/Attribute/stroke-linecap
page-type: svg-attribute
browser-compat: svg.global_attributes.stroke-linecap
---
{{SVGRef}}
The **`stroke-linecap`** attribute is a presentation attribute defining the shape to be used at the end of open subpaths when they are stroked.
> [!NOTE]
> As a presentation attribute `stroke-linecap` can be used as a CSS property.
You can use this attribute with the following SVG elements:
- {{SVGElement('path')}}
- {{SVGElement('polyline')}}
- {{SVGElement('line')}}
- {{SVGElement('text')}}
- {{SVGElement('textPath')}}
- {{SVGElement('tref')}}
- {{SVGElement('tspan')}}
## Example
```css hidden
html,
body,
svg {
height: 100%;
}
```
```html
<svg viewBox="0 0 6 6" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the (default) "butt" value -->
<line x1="1" y1="1" x2="5" y2="1" stroke="black" stroke-linecap="butt" />
<!-- Effect of the "round" value -->
<line x1="1" y1="3" x2="5" y2="3" stroke="black" stroke-linecap="round" />
<!-- Effect of the "square" value -->
<line x1="1" y1="5" x2="5" y2="5" stroke="black" stroke-linecap="square" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4 M1,3 h4 M1,5 h4" stroke="pink" stroke-width="0.025" />
</svg>
```
{{EmbedLiveSample("Example", '100%', 200)}}
## Usage notes
<table class="properties">
<tbody>
<tr>
<th scope="row">Value</th>
<td><code>butt</code> | <code>round</code> | <code>square</code></td>
</tr>
<tr>
<th scope="row">Default value</th>
<td><code>butt</code></td>
</tr>
<tr>
<th scope="row">Animatable</th>
<td>discrete</td>
</tr>
</tbody>
</table>
### butt
The `butt` value indicates that the stroke for each subpath does not extend beyond its two endpoints. On a zero length subpath, the path will not be rendered at all.
#### Example
```css hidden
html,
body,
svg {
height: 100%;
}
```
```html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "butt" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="butt" />
<!-- Effect of the "butt" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="butt" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
```
{{EmbedLiveSample('butt', '100%', 200)}}
### round
The `round` value indicates that at the end of each subpath the stroke will be extended by a half circle with a diameter equal to the stroke width. On a zero length subpath, the stroke consists of a full circle centered at the subpath's point.
#### Example
```css hidden
html,
body,
svg {
height: 100%;
}
```
```html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "round" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="round" />
<!-- Effect of the "round" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="round" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
```
{{EmbedLiveSample('round', '100%', 200)}}
### square
The `square` value indicates that at the end of each subpath the stroke will be extended by a rectangle with a width equal to half the width of the stroke and a height equal to the width of the stroke. On a zero length subpath, the stroke consists of a square with its width equal to the stroke width, centered at the subpath's point.
#### Example
```css hidden
html,
body,
svg {
height: 100%;
}
```
```html
<svg viewBox="0 0 6 4" xmlns="http://www.w3.org/2000/svg">
<!-- Effect of the "square" value -->
<path d="M1,1 h4" stroke="black" stroke-linecap="square" />
<!-- Effect of the "square" value on a zero length path -->
<path d="M3,3 h0" stroke="black" stroke-linecap="square" />
<!--
the following pink lines highlight the
position of the path for each stroke
-->
<path d="M1,1 h4" stroke="pink" stroke-width="0.025" />
<circle cx="1" cy="1" r="0.05" fill="pink" />
<circle cx="5" cy="1" r="0.05" fill="pink" />
<circle cx="3" cy="3" r="0.05" fill="pink" />
</svg>
```
{{EmbedLiveSample('square', '100%', 200)}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}