如何在 HTML 中显示图片?

htmlweb developmentfront end technology更新于 2026/1/17 10:52:17

在 HTML 中使用 <img> 标签显示图片。以下是 − 属性

属性
值
描述
Align
top
bottom
middle
left
right
已弃用− 指定图像的对齐方式。
Alt
text
指定替代文本
Border
pixels
已弃用 − 指定图像边框的宽度。
crossorigin
anonymous use-credentials
它允许来自第三方网站的图像与画布一起重复使用,这些网站允许跨域访问。
Height
pixels or %
指定图像的高度。
hspace
pixels
已弃用 − 要在对象左侧和右侧插入的空白量。
Ismap
URL
将图像定义为服务器端图像映射。
Longdesc
text
已弃用 − 指定长描述的 URI/URL - 这可以详细说明使用 alt 属性指定的较短描述。
Src
URL
the url of an image
Usemap
#mapname
将图像定义为客户端图像映射并与 <map> 和 <area> 标签一起使用。
Vspace
pixels
已弃用 − 插入到对象顶部和底部的空白量。
Width
pixels or %
设置图片的宽度(以像素或百分比为单位)。

示例

您可以尝试运行以下代码,将图片添加到网页文档中。 −

<!DOCTYPE html>
<html>
   <head>
      <title>HTML img Tag</title>
   </head>
   <body>
      <img src = "https://www.cainiaomax.com/html5/images/html5-mini-logo.jpg"
      alt = "Learn HTML5" height = "250" width = "270" />
   </body>
</html>

相关文章


有用资源