ADVERTISEMENT
Google AdSense Slot (headerLeaderboard)

Set your Publisher ID in src/config/ads.ts to display live ads.

SVG & HTML5 Canvas Tutorial• 6 min read

SVG Primitives: rect, circle, ellipse & line

Coordinate systems, stroke, fill, and presentation attributes

SVG coordinate space starts at (0, 0) in the top-left corner, expanding rightward along the X axis and downward along the Y axis.

Core SVG Shape Elements

<rect x="10" y="10" width="100" height="50" rx="5" />: Rectangle with optional rounded corners (rx).

<circle cx="50" cy="50" r="40" />: Circle defined by center coordinates (cx, cy) and radius (r).

<ellipse cx="60" cy="40" rx="50" ry="25" />: Ellipse with separate horizontal and vertical radii.

<line x1="0" y1="0" x2="200" y2="100" />: Straight line between two coordinates.

Presentation attributes: fill (background color), stroke (border line color), stroke-width (line thickness).

Drawing Clean SVG Geometric Badges
<svg width="240" height="120" viewBox="0 0 240 120" xmlns="http://www.w3.org/2000/svg">
  <!-- Rounded Card Background -->
  <rect x="10" y="10" width="220" height="100" rx="12" fill="#1e293b" stroke="#38bdf8" stroke-width="2"/>
  
  <!-- Glowing Target Circle -->
  <circle cx="60" cy="60" r="28" fill="#04AA6D" stroke="#ffffff" stroke-width="3"/>
  
  <!-- Text Label -->
  <text x="105" y="68" fill="#ffffff" font-family="Arial" font-size="18" font-weight="bold">CODEXIA</text>
</svg>
viewBox ensures fluid responsiveness across responsive screens.
ADVERTISEMENT
Google AdSense Slot (inContentBanner)

Set your Publisher ID in src/config/ads.ts to display live ads.

Test Yourself With Exercise

+15 XP

Which SVG element requires `cx`, `cy`, and `r` attributes to position and size itself?