Chapter 7: Geometry Properties

Beside SVG's styling properties, SVG also defines geometry properties. Geometry properties describe the position and dimension of the graphics elements circle, ellipse, rect, image, foreignObject and the svg element.

The cx, cy, x and y properties accept negative values. The r, rx, ry, width and height properties do not: a negative <length-percentage> is invalid. When an invalid negative value is specified for one of these properties, whether through a presentation attribute or a CSS declaration, it must be treated as if the property's initial value had been specified: auto for rx, ry, width and height, and 0 for r. A negative value therefore never puts the element into an error state; the @@ unknown term "used value" is determined by the property's normal resolution rules. The following table summarizes this handling.

Handling of negative values for the geometry properties
Property Value Initial Negative allowed? Negative computes to Used value of a negative value
cx, cy <length-percentage> 0 yes the specified value (kept as-is) the negative value (translates the shape)
r <length-percentage> 0 no 0 0; a circle with r = 0 is not rendered
rx, ry <length-percentage> | auto auto no auto resolved as auto: equal to the used value of the other radius, or 0 if the other radius is also auto or negative. An ellipse with a resolved radius of 0 is not rendered.
width, height <length-percentage> | auto auto no auto resolved as auto per the sizing table: 100% for the outermost svg, the intrinsic size for image, and 0 for all other elements.

7.1. Horizontal center coordinate: The ‘cx’ property

Name: cx
Value: <length-percentage>
Initial: 0
Applies to: circle and ellipse elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The cx property describes the horizontal center coordinate of the position of the element.

Negative values are permitted for cx; a negative value translates the center of the shape and does not disable rendering, unlike r, rx and ry (see the handling of negative values).

7.2. Vertical center coordinate: The ‘cy’ property

Name: cy
Value: <length-percentage>
Initial: 0
Applies to: circle and ellipse elements
Inherited: no
Percentages: refer to the height of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The cy property describes the vertical center coordinate of the position of the element.

Negative values are permitted for cy; a negative value translates the center of the shape and does not disable rendering (see the handling of negative values).

7.3. Radius: The ‘r’ property

Name: r
Value: <length-percentage>
Initial: 0
Applies to: circle element
Inherited: no
Percentages: refer to the normalized diagonal of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The r property describes the radius of the circle element.

A negative value for r is invalid; it is treated as if 0 had been specified (see the handling of negative values), so the circle is not rendered.

7.4. Horizontal radius: The ‘rx’ property

Name: rx
Value: <length-percentage> | auto
Initial: auto
Applies to: ellipse, rect elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The rx property describes the horizontal radius of the ellipse element and the curve radius of the rect element. When the computed value of ‘rx’ is auto, the used radius is equal to the absolute length used for ry, creating a circular arc. If both ‘rx’ and ‘ry’ have a computed value of auto, the used value is 0.

Regardless of how the value is calculated, the used value of ‘rx’ for a rect is never more than 50% of the used value of width for the same shape.

The auto behavior is new in SVG 2 for ellipse, matching the behavior for rect elements when rx was not specified.

A negative value for rx is invalid; it is treated as if auto had been specified (see the handling of negative values). It therefore resolves like auto: to the used value of ry, or to 0 if ry is also auto or negative.

7.5. Vertical radius: The ‘ry’ property

Name: ry
Value: <length-percentage> | auto
Initial: auto
Applies to: ellipse, rect
Inherited: no
Percentages: refer to the height of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animatable type: by computed value

The ry property describes the vertical radius of the ellipse element and the vertical curve radius of the rect element. When the computed value of ‘ry’ is auto, the used radius is equal to the absolute length used for rx, creating a circular arc. If both ‘rx’ and ‘ry’ have a computed value of auto, the used value is 0.

Regardless of how the value is calculated, the used value of ‘ry’ for a rect is never more than 50% of the used value of height for the same shape.

The auto behavior is new in SVG 2 for ellipse, matching the behavior for rect elements when ry was not specified.

A negative value for ry is invalid; it is treated as if auto had been specified (see the handling of negative values). It therefore resolves like auto: to the used value of rx, or to 0 if rx is also auto or negative.

7.6. Horizontal coordinate: The ‘x’ property

Name: x
Value: <length-percentage>
Initial: 0
Applies to: svg, rect, image, foreignObject elements
Inherited: no
Percentages: refer to the width of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The x property describes the horizontal coordinate of the position of the element.

7.7. Vertical coordinate: The ‘y’ property

Name: y
Value: <length-percentage>
Initial: 0
Applies to: svg, rect, image, foreignObject elements
Inherited: no
Percentages: refer to the height of the current SVG viewport (see Units)
Media: visual
Computed value: an absolute length or percentage
Animation type: by computed value

The y property describes the vertical coordinate of the position of the element.

7.8. Sizing properties: the effect of the ‘width’ and ‘height’ properties

See the CSS 2.1 specification for the definitions of width and height.

The CSS width and height properties are used for sizing some SVG elements. Specifically, they are used to size rect, image, foreignObject, and the outermost svg element. All of these elements have ‘width’ and ‘height’ presentation attributes. The properties are also used for laying out embedded elements from the HTML namespace.

Other SVG elements, such as nested svg elements, the use element, and the symbol element, also have ‘width’ and ‘height’ attributes, but do not accept them as CSS properties. On these elements, the width and height must be specified as XML attributes; CSS properties with the same names are ignored.

The used value of width may be constrained by the value of the max-width and min-width properties. The used value of height may be constrained by the value of the max-height and min-height properties.

The following table summarizes how the value auto for width and height is treated on different elements:

Element Value Treated as
svg auto 100%
image auto Calculated from the referenced image's intrinsic dimensions and aspect ratio, according to the CSS Default Sizing Algorithm
All other elements auto 0

New in SVG 2. Images embedded in SVG can now be auto-sized to the intrinsic size, or scaled to a fixed height or width according to the intrinsic aspect ratio. This matches the behavior of embedded images in HTML.

This means that, for example, a foreignObject object element will not shrink-wrap to its contents if auto is used.