SVG Path<path>
In SVG, the<path>element is used to create paths, and it is one of the most powerful and flexible basic shapes in SVG.
Using<path>the element can draw various complex shapes such as lines, curves, arcs, etc., and the shape and style of the path can be controlled by setting path commands.
Basic Syntax
<path d="path-data" <!-- 定义路径的路径数据 --> fill="fill-color" <!-- 路径的填充颜色 --> stroke="stroke-color" <!-- 路径的描边颜色 --> stroke-width="width" <!-- 路径的描边宽度 --> />
Attribute explanation:
dThe attribute defines the path data, i.e., the sequence of path commands. Path data consists of a series of path commands, each command starts with a letter followed by a set of numeric parameters. Common path commands include: M (move to), L (line to), H (horizontal line to), V (vertical line to), C (cubic Bezier curve), S (smooth curve), Q (quadratic Bezier curve), T (smooth quadratic Bezier curve), A (arc), Z (close path), etc.fillThe attribute defines the fill color of the path.strokeThe attribute defines the stroke color of the path.stroke-widthThe attribute defines the stroke width of the path.
The following code draws a path with orange fill, black stroke, and a width of 2 pixels. Its path data is: move to (50, 50), then connect to (150, 50) and (100, 150) in order, and finally close the path.
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg"> <path d="M 50 50 L 150 50 L 100 150 Z" fill="orange" stroke="black" stroke-width="2" /> </svg>
Example 1
The following example defines a path that starts at position 150 0, reaches position 75 200, then from there goes to 225 200, and finally closes the path at 150 0.
Below is the SVG code:
Example
Try it yourself »
Click to view:View SVG file。
Example 2
The following example creates a quadratic Bezier curve, where A and C are the start point and end point respectively, and B is the control point:
Below is the SVG code:
Example
Try it yourself »
Click to view:View SVG file。
Notes
<path>The path data of the element is the most complex part of SVG, and requires a certain amount of learning and practice to master the use of various path commands.Path data can contain multiple path commands, and each path command can have different parameters to control the shape and direction of the path.
By using<path>the element, you can draw various complex shapes and paths in SVG, and control the appearance and style of the path by setting attributes.