SVG <テキスト>


SVGテキスト-<テキスト>

<text>要素は、テキストを定義するために使用されます。


例1

テキストを書く:

I love SVG! Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="30" width="200">
  <text x="0" y="15" fill="red">I love SVG!</text>
</svg>

例2

テキストを回転します。

I love SVG Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="60" width="200">
  <text x="0" y="15" fill="red" transform="rotate(30 20,40)">I love SVG</text>
</svg>


例3

<text>要素は、<tspan>要素を使用して任意の数のサブグループに配置できます。各<tspan>要素には、異なるフォーマットと位置を含めることができます。

数行のテキスト(<tspan>要素を含む):

Several lines: First line. Second line. Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="90" width="200">
  <text x="10" y="20" style="fill:red;">Several lines:
    <tspan x="10" y="45">First line.</tspan>
    <tspan x="10" y="70">Second line.</tspan>
  </text>
</svg>

例4

リンクとしてのテキスト(<a>要素を含む):

I love SVG! Sorry, your browser does not support inline SVG.

SVGコードは次のとおりです。

<svg height="30" width="200" xmlns:xlink="http://www.w3.org/1999/xlink">
  <a xlink:href="https://www.w3schools.com/graphics/" target="_blank">
    <text x="0" y="15" fill="red">I love SVG!</text>
  </a>
</svg>