Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

cx — horizontal center coordinate in SVG

The CSS `cx` property sets the horizontal center coordinate of an SVG `circle` or `ellipse`. It accepts lengths and percentages; it is not a positioning property for ordinary HTML elements.

Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required

Syntax

cx: <length-percentage>;

cx sets the horizontal coordinate of the center of a circle or ellipse, not the shape's left edge. Its initial value is 0, and it is not inherited. Negative values are allowed.

The syntax is cx: <length-percentage>;, for example cx: 40px; or cx: 75%;. Percentages refer to the current SVG viewport's width, not the shape's width. viewBox defines the mapping of the coordinate system to the viewport.

On these shapes, the cx attribute is a presentation attribute participating in the CSS cascade. The example's circle { cx: 75%; } rule overrides cx="20". Setting cx on an ordinary HTML element is not equivalent to setting left.

In the example, the coordinate system's width is 200, so 75% places the center at 150. The expected result is a navy circle with center (150, 50) and radius 15 in a 200 × 100 SVG viewport. The example code and stated result were verified in an isolated environment. You can also run the example separately to see how it renders in your own browser.

Examples

<!doctype html>
<meta charset="utf-8">
<title>cx</title>
<style>
  circle { cx: 75%; fill: navy; }
</style>
<svg xmlns="http://www.w3.org/2000/svg" width="200" height="100" viewBox="0 0 200 100">
  <circle cx="20" cy="50" r="15" />
</svg>

Result

A navy circle with center (150, 50) and radius 15 in a 200 × 100 SVG viewport.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources