HTML width 属性

前へ 全ての HTML 属性 次へ

定義と用法

width 属性は、要素の幅をピクセルで指定します。

注:input 要素の場合、width 属性は、<input type="image"> でのみ使われます。


適用

width 属性は、以下の要素で使用することができます:

要素 属性
<canvas> width
<embed> width
<iframe> width
<img> width
<input> width
<object> width
<video> width

Canvas の例

高さと幅が 200 ピクセルの <canvas> 要素:

<canvas id="myCanvas" width="200" height="200" style="border:1px solid">
Try it Yourself ❯

Embed の例

高さと幅が 200 ピクセルのフラッシュ・アニメーション:

<embed src="helloworld.swf" width="200" height="200">
Try it Yourself ❯

Iframe の例

高さと幅が 200 ピクセルの <iframe>:

<iframe src="/default.html" width="200" height="200"></iframe>
Try it Yourself ❯

Img の例

高さと幅が 42 ピクセルの画像:

<img src="smiley.gif" alt="Smiley face" height="42" width="42">
Try it Yourself ❯

Input の例

height と width 属性を持つ submit ボタンとして画像を定義する:

<form action="demo_form.html">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="image" src="img_submit.gif" alt="Submit" width="48" height="48">
</form>
Try it Yourself ❯

Object の例

高さと幅が 400 ピクセルのフラッシュ・アニメーション:

<object data="helloworld.swf" width="400" height="400"></object>
Try it Yourself ❯

Video の例

指定の幅と高さを持つビデオ・プレーヤ:

<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  <source src="movie.ogg" type="video/ogg">
  Your browser does not support the video tag.
</video>
Try it Yourself ❯

ブラウザ・サポート

width 属性は、要素ごとに以下のブラウザがサポートしています。

要素
canvas 4.0 9.0 2.0 3.1 9.0
embed Yes Yes Yes Yes Yes
iframe Yes Yes Yes Yes Yes
img Yes Yes Yes Yes Yes
input 1.0 Yes 16.0 Yes 1.0
object Yes Yes Yes Yes Yes
width Yes Yes Yes Yes Yes

前へ 全ての HTML 属性 次へ