Master the fundamental building blocks of vector graphics
SVG provides several basic shape elements that serve as the foundation for creating vector graphics. These predefined shapes are perfect for beginners and can be combined to create complex designs. Understanding these basic shapes is essential for anyone working with SVG.
Each shape element has specific attributes that control its appearance, position, and size. By mastering these basic shapes, you'll have the tools to create everything from simple icons to complex illustrations.
The rect
element creates rectangles and squares. It's one of the most commonly used SVG shapes.
x, y
- Position coordinateswidth, height
- Dimensionsrx, ry
- Corner radius for rounded rectangles<rect x="10" y="10" width="80" height="60" />
The circle
element creates perfect circles. It's defined by its center point and radius.
cx, cy
- Center coordinatesr
- Radius<circle cx="100" cy="100" r="50" />
The ellipse
element creates oval shapes. Unlike circles, ellipses can have different horizontal and vertical radii.
cx, cy
- Center coordinatesrx
- Horizontal radiusry
- Vertical radius<ellipse cx="100" cy="100" rx="80" ry="40" />
The line
element creates straight lines between two points. It's perfect for creating simple geometric patterns.
x1, y1
- Starting point coordinatesx2, y2
- Ending point coordinatesstroke
- Line color (required for visibility)<line x1="0" y1="0" x2="100" y2="100" stroke="black" />
The polyline
element creates connected line segments through a series of points. It's useful for creating open shapes.
points
- Space-separated list of x,y coordinatesfill
- Fill color (optional)stroke
- Line color<polyline points="20,20 60,60 100,20 140,60 180,20" />
The polygon
element creates closed shapes by connecting a series of points. It automatically closes the shape.
points
- Space-separated list of x,y coordinatesfill
- Fill colorstroke
- Border color<polygon points="100,20 180,80 100,140 20,80" />
The text
element adds text to SVG graphics. Text in SVG is scalable and can be styled with CSS.
x, y
- Text position coordinatesfont-family
- Font typefont-size
- Text sizetext-anchor
- Text alignment<text x="100" y="100" text-anchor="middle">Hello SVG!</text>
The real power of SVG comes from combining multiple basic shapes to create complex designs. Here's an example of a simple house made from basic shapes:
<svg width="200" height="200">
<rect x="40" y="80" width="120" height="80" fill="beige" />
<polygon points="30,80 100,30 170,80" fill="darkred" />
<rect x="80" y="120" width="30" height="40" fill="brown" />
<!-- More shapes... -->
</svg>
Basic SVG shapes provide a solid foundation for creating vector graphics. By mastering these fundamental elements, you can build complex designs through simple combinations and transformations.
Remember that while these shapes are basic, they're incredibly powerful when combined with CSS styling, JavaScript interactivity, and advanced SVG features like gradients, patterns, and filters.
Start with these basic shapes, experiment with their attributes, and gradually build more complex designs. The more you practice, the more you'll discover the creative possibilities within SVG.
Explore our SVG collection and tools to start creating your own vector graphics.