HTML Graphics

SVG Attribute Complete Reference

Beyond presentation styling, SVG elements carry geometry and core attributes that define their position, size and shape data. This reference collects the attributes you reach for most often: coordinate and size attributes for the basic shapes, the powerful d and points path data attributes, and the viewport attributes viewBox and preserveAspectRatio that control how a drawing is scaled and aligned.


Position & Size Attributes

AttributeDescription
xThe x-coordinate of the left edge for <rect>, <image>, <text> and similar elements.
yThe y-coordinate of the top edge for <rect>, <image>, <text> and similar elements.
widthThe horizontal size of a <rect>, <image>, <svg> or <pattern>.
heightThe vertical size of a <rect>, <image>, <svg> or <pattern>.
cxThe x-coordinate of the centre for <circle>, <ellipse> and radial gradients.
cyThe y-coordinate of the centre for <circle>, <ellipse> and radial gradients.
rThe radius of a <circle> or the radius of a <radialGradient>.
rxThe horizontal radius of an <ellipse>, or the horizontal corner radius of a <rect>.
ryThe vertical radius of an <ellipse>, or the vertical corner radius of a <rect>.

Line & Point Attributes

AttributeDescription
x1The x-coordinate of the start point of a <line> or the start of a linear gradient.
y1The y-coordinate of the start point of a <line> or the start of a linear gradient.
x2The x-coordinate of the end point of a <line> or the end of a linear gradient.
y2The y-coordinate of the end point of a <line> or the end of a linear gradient.
pointsA space/comma separated list of x,y pairs defining a <polyline> or <polygon>.
dThe path data string for <path>: commands like M (move), L (line), C/Q (Bezier), A (arc), Z (close).

Viewport & Reference Attributes

AttributeDescription
viewBox'min-x min-y width height' defining the internal coordinate system that is scaled to the element's size.
preserveAspectRatioControls how the viewBox is scaled and aligned inside the viewport (e.g. 'xMidYMid meet', 'none').
href / xlink:hrefReferences another element or resource by id or URL (used by <use>, <textPath>, <image>).
idA unique identifier so the element can be referenced by url(#id), <use> or CSS/JS.
offsetPosition of a gradient <stop> along the gradient, from 0 (0%) to 1 (100%).
gradientUnitsCoordinate system for gradient positions: 'objectBoundingBox' or 'userSpaceOnUse'.

Presentation Attributes (also settable as CSS)

AttributeDescription
fillThe interior paint colour of the shape (also a CSS property).
strokeThe outline paint colour of the shape (also a CSS property).
stroke-widthThe thickness of the outline (also a CSS property).
transformA list of transforms (translate, rotate, scale, skew, matrix) applied to the element.
opacityOverall opacity of the element from 0 to 1 (also a CSS property).
classOne or more CSS class names for targeting the element from a stylesheet.
ℹ️

viewBox and preserveAspectRatio are case-sensitive camelCase attributes. Writing 'viewbox' (all lowercase) will silently do nothing.

Ready to use your HTML skills?

Find web development internships and fresher jobs across India.

Browse Web Dev Internships