SVGSVGElement: width-Eigenschaft

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Die width schreibgeschützte Eigenschaft der SVGSVGElement-Schnittstelle beschreibt die horizontale Größe des Elements als ein SVGAnimatedLength. Sie spiegelt das <svg>-Element-Attribut width wider, das möglicherweise nicht der gerenderten Breite des SVG entspricht.

Die CSS-Eigenschaft width hat Vorrang vor dem width-Attribut des <svg>-Elements, sodass der Wert möglicherweise nicht das Erscheinungsbild des Elements widerspiegelt. Wenn sowohl das Attribut viewBox als auch das Attribut width weggelassen werden, spiegelt die width-Eigenschaft die tatsächliche Breite wider.

Wert

Beispiel

js
const svg = document.querySelector("svg");
const inlineSize = svg.width;
console.dir(inlineSize.baseVal.value); // the `width` value

Spezifikationen

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGSVGElement__width

Browser-Kompatibilität

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
width

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

Siehe auch