|
| 1 | +--- |
| 2 | +title: "SVGMarkerElement: orient property" |
| 3 | +short-title: orient |
| 4 | +slug: Web/API/SVGMarkerElement/orient |
| 5 | +page-type: web-api-instance-property |
| 6 | +browser-compat: api.SVGMarkerElement.orient |
| 7 | +--- |
| 8 | + |
| 9 | +{{APIRef("SVG")}} |
| 10 | + |
| 11 | +The **`orient`** property of the {{domxref("SVGMarkerElement")}} interface is a string that reflects the {{SVGAttr("orient")}} attribute of the given {{SVGElement("marker")}} element. It defines how the marker is rotated when it is placed at its position on the shape. |
| 12 | + |
| 13 | +Unlike {{domxref("SVGMarkerElement.orientType")}} and {{domxref("SVGMarkerElement.orientAngle")}}, which provide read-only access to the orientation as an enumerated type and angle respectively, the `orient` property allows directly getting and setting the `orient` attribute as a string. |
| 14 | + |
| 15 | +## Value |
| 16 | + |
| 17 | +A string. Possible values are: |
| 18 | + |
| 19 | +- `"auto"` |
| 20 | + - : The marker is automatically rotated to follow the direction of the path at the point where it is placed. |
| 21 | +- `"auto-start-reverse"` |
| 22 | + - : If placed by `marker-start`, the marker is oriented 180° different from the orientation that would be used if `auto` were specified. For all other markers, `auto-start-reverse` means the same as `auto`. |
| 23 | +- An `<angle>` value (e.g., `"45deg"`, `"0.5turn"`) |
| 24 | + - : The marker is rotated by the specified angle, measured from the horizontal. |
| 25 | +- A `<number>` value (e.g., `"45"`) |
| 26 | + - : The marker is oriented at the specified angle in degrees. |
| 27 | + |
| 28 | +## Examples |
| 29 | + |
| 30 | +### Accessing the `orient` property |
| 31 | + |
| 32 | +```html |
| 33 | +<svg |
| 34 | + viewBox="0 0 100 100" |
| 35 | + width="300" |
| 36 | + height="300" |
| 37 | + xmlns="http://www.w3.org/2000/svg"> |
| 38 | + <defs> |
| 39 | + <marker |
| 40 | + id="arrow" |
| 41 | + viewBox="0 0 10 10" |
| 42 | + refX="5" |
| 43 | + refY="5" |
| 44 | + markerWidth="12" |
| 45 | + markerHeight="12" |
| 46 | + orient="auto-start-reverse"> |
| 47 | + <path d="M 0 0 L 10 5 L 0 10 z" /> |
| 48 | + </marker> |
| 49 | + </defs> |
| 50 | + <polyline |
| 51 | + points="10,90 50,10 90,90" |
| 52 | + fill="none" |
| 53 | + stroke="black" |
| 54 | + marker-start="url(#arrow)" |
| 55 | + marker-mid="url(#arrow)" |
| 56 | + marker-end="url(#arrow)" /> |
| 57 | +</svg> |
| 58 | +<output></output> |
| 59 | +``` |
| 60 | + |
| 61 | +```css hidden |
| 62 | +body { |
| 63 | + font-family: system-ui; |
| 64 | +} |
| 65 | + |
| 66 | +output { |
| 67 | + display: block; |
| 68 | + font: inherit; |
| 69 | + white-space: pre; |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +We can read the `orient` property and then set it to a new value: |
| 74 | + |
| 75 | +```js |
| 76 | +const marker = document.querySelector("marker"); |
| 77 | +const log = document.querySelector("output"); |
| 78 | + |
| 79 | +if ("orient" in marker) { |
| 80 | + // Read the current orient value |
| 81 | + log.textContent = `orient: "${marker.orient}"\n`; // "auto-start-reverse" |
| 82 | + |
| 83 | + // Set a new orient value |
| 84 | + marker.orient = "90deg"; |
| 85 | + log.textContent += `after setting "90deg": "${marker.orient}"`; |
| 86 | +} else { |
| 87 | + log.textContent = "orient is not supported in this browser"; |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +{{EmbedLiveSample("Examples", "", "340")}} |
| 92 | + |
| 93 | +## Specifications |
| 94 | + |
| 95 | +{{Specifications}} |
| 96 | + |
| 97 | +## Browser compatibility |
| 98 | + |
| 99 | +{{Compat}} |
| 100 | + |
| 101 | +## See also |
| 102 | + |
| 103 | +- {{domxref("SVGMarkerElement.orientType")}} |
| 104 | +- {{domxref("SVGMarkerElement.orientAngle")}} |
| 105 | +- {{domxref("SVGMarkerElement.setOrientToAuto()")}} |
| 106 | +- {{domxref("SVGMarkerElement.setOrientToAngle()")}} |
| 107 | +- {{SVGAttr("orient")}} |
0 commit comments