First you need to define the dimensions of the SVG area you want. As the figure is represented by a square, suppose you want a star with 100x100
pixels. Then set the width
and the height
in 100px
:
CSS:
svg{
width: 100px;
height: 100px;
}
Now you need to set the coordinates within that area (for the star, they are 5 coordinates), separated by comma being x,y (x is the horizontal axis and y the vertical axis) at the points indicated below:
As SVG has 100x100
pixels of dimension, the values of the figure above are the approximate percentages to build a perfect star, ie:
1º vértice: x = 50%, y = 0%
2º vértice: x = 19,49%, y = 100%
3º vértice: x = 100%, y = 37,93%
4º vértice: x = 0%, y = 37,93%
5º vértice: x = 80,51%, y = 100%
Example:
svg{
width: 100px;
height: 100px;
}
<svg xmlns="http://www.w3.org/2000/svg">
<polygon points="50,0 19.49,100 100,37.93 0,37.93 80.51,100" fill="black" style="fill:yellow"/>
</svg>
Depending on the size of the star you want, just apply the
percentages proportionally in the coordinates according to the square dimensions.