SVG in HTML5
Shapes in SVG
In this chapter, we will delve into the basic shapes available in SVG, which are the foundation for building graphics and drawings. SVG offers a variety of geometric shapes that we can combine, transform, and style to create complex graphics.
Basic Shapes in SVG
SVG includes several geometric shapes that we can define using specific tags, each with its attributes to determine position, size, and style. The most common shapes include rectangles, circles, ellipses, lines, and polygons.
Rectangle (<rect>
)
The <rect>
element creates a rectangle in SVG. We can control its size and position using the x
, y
, width
, and height
attributes.
html
Circle (<circle>
)
The <circle>
element allows us to create a circle using the cx
and cy
attributes for the center position and r
for the radius.
html
Ellipse (<ellipse>
)
The <ellipse>
element allows us to define an ellipse, similar to the circle, but it allows for different radii on the X and Y axes, which is useful for creating oval shapes.
html
Line (<line>
)
The <line>
element draws a line between two points defined by the x1
, y1
, x2
, and y2
attributes.
html
Polygon (<polygon>
)
The <polygon>
element allows us to create shapes with multiple sides by specifying a series of points through the points
attribute.
html
Polyline (<polyline>
)
The <polyline>
element is similar to <polygon>
, but the lines do not connect to the starting point, which is useful for creating open paths or broken lines.
html
Combining Shapes to Create Complex Graphics
The shapes in SVG can be combined and overlaid to create complex graphics. For example, we can combine several circles, rectangles, and lines to form custom illustrations or diagrams. With the positioning and transformation tools that we will explore in other chapters, you can arrange these shapes in an organized manner and with great precision.
Conclusion
Shapes in SVG are fundamental building blocks for creating vector graphics. By mastering the use of these basic shapes, you can begin to experiment with designs and compositions.
See you in the next chapter!