大网数据广告活动
Web 标准与前端开发

HTMLInputElement: width property

· 52CE 我爱测

The **`width`** property of the HTMLInputElement interface specifies the width of a control. It reflects the input element's `width` attribute.

HTML DOM

The width property of the HTMLInputElement interface specifies the width of a control. It reflects the input element's width attribute.

The width property is valid for the image type only. It defines the preferred horizontal size of the image button, in pixels. The property value is the width of the content-box of the rendered button. CSS box model properties impacting the size of the control take precedence.

If no width is set and no CSS width properties impact the control, the width will be the intrinsic width of the image. If the image didn't load, the value will be the maximum intrinsic width of the alt text. The width will be 0 if the width is not known; if no width is set, no CSS dimensions apply, no image loaded, and either the value of the HTMLInputElement.alt is the empty string or no src is set.

Value

A number.

Examples

const inputElement = document.getElementById("imageButton");
console.log(inputElement.width);

Specifications

Browser compatibility

See also

  • HTMLInputElement.height
  • HTMLInputElement.src
  • HTMLInputElement.alt
  • HTMLButtonElement
  • button
  • input
  • img
  • CSS inline-size property
  • CSS width property
  • CSS aspect-ratio property
  • CSS box sizing module

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。