Back to Content

Index

files/en-us/web/svg/reference/element/view/index.md

latest2.0 KB
Original Source

The <view> SVG element defines a particular view of an SVG document. A specific view can be displayed by referencing the <view> element's id as the target fragment of a URL.

Usage context

{{svginfo}}

Attributes

  • {{SVGAttr("preserveAspectRatio")}}
    • : This attribute defines how the SVG fragment must be deformed if it is embedded in a container with a different {{glossary("aspect ratio")}}. Value type: (none | xMinYMin | xMidYMin | xMaxYMin | xMinYMid | xMidYMid | xMaxYMid | xMinYMax | xMidYMax | xMaxYMax) (meet | slice)?; Default value: xMidYMid meet; Animatable: yes
  • {{SVGAttr("viewBox")}}
    • : This attribute defines the bound of the SVG viewport for the pattern fragment. Value type: <list-of-numbers>; Default value: none; Animatable: yes
  • {{SVGAttr("zoomAndPan")}} {{Deprecated_Inline}}
    • : This attribute specifies whether the SVG document can be magnified and panned. Value type: disable | magnify; Default value: magnify; Animatable: no

DOM Interface

This element implements the {{domxref("SVGViewElement")}} interface.

Example

SVG

svg
<svg viewBox="0 0 300 100" width="300" height="100"
      xmlns="http://www.w3.org/2000/svg">

  <view id="one" viewBox="0 0 100 100" />
  <circle cx="50" cy="50" r="40" fill="red" />

  <view id="two" viewBox="100 0 100 100" />
  <circle cx="150" cy="50" r="40" fill="green" />

  <view id="three" viewBox="200 0 100 100" />
  <circle cx="250" cy="50" r="40" fill="blue" />
</svg>

HTML

html




Result

{{EmbedLiveSample("Example", "85ch", "240px")}}

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}