h16 HTML Images
HTML Images 图像图片 provides a visual content for web pages, enhancing user experiences and conveying information. They can be photographs, graphics, icons, or illustrations. To insert an image on HTML document we can use <img> tag.
Reason to use Images
HTML offers various elements for embedding, manipulating, and controlling images, contributing to the aesthetics and functionality of websites. Understanding image tags, attributes, and responsive design principles is essential for effective web development. We usually use images within hero section on the product page, it required src and alt attributes.
- Increase Readbility: Using proper images/graphics can increase the readibility of our website, like what kind of products or services we provide.
- SEO Impact: If we can use images with proper attributes that does not effect the loading time can be benificial to improve the website SEO.
There are lots of other advantages to use images we will know in this article.
Examples of HTML images
In the bellow examples we will see how to set the width, height, title, how to make image more attarctive on the webpage! and so many many other things on images.
You can use PNG, JPEG, or GIF image files based on your comfort but make sure you specify the correct image file name in src attribute. Using alt attribute is a good practice. it specifies an alternate text for an image if the image cannot be displayed.
Inserting an Image in HTML
src -- source
You can insert any image in your web page by using <img> tag. The <img> tag is an empty tag, which means that, it can contain only list of attributes and it has no closing tag.
<DOCTYPE html> <html> <head> <title>Using Image in Webpage</title> </head> <body> <p>Simple Image Insert</p> <img src="logo.png" alt="Test Image" /> </body> </html>
Importing images from another folder
Usually, we keep all the images in a separate directory. So let's keep HTML file test.htm in our home directory and create a subdirectory images inside the home directory where we will keep our image as test.png. Assuming our image location is "/html/images/test.png", try the following example.
<!DOCTYPE html> <html> <head> <title>Using Image in Webpage</title> </head> <body> <img src="/html/images/logo.jpg" alt="Test Image" /> </body> </html>
alt -- alternative
Set Image Width and Height
You can set image width and height based on your requirement using width and height attributes. You can specify width and height of the image in terms of either pixels or percentage of its actual size.
<!DOCTYPE html> <html> <head> <title>Set Image Width and Height</title> </head> <body> <p>Setting image width and height</p> <img src="logo.jpg" alt="Test Image" width="450" height="200" /> </body> </html>
Set Image Border
By default, image will have a border around it, you can specify border thickness in terms of pixels using border attribute. A thickness of 0 means, no border around the picture.
<!DOCTYPE html> <html> <head> <title>Set Image Width and Height</title> </head> <body> <p>Setting image width and height</p> <img src="logo.jpg" alt="Test Image" alt="Test Image" border="3" /> </body> </html>
Set Image Alignment
By default, image will align at the left side of the page, but you can use align attribute to set it in the center or right.
<!DOCTYPE html> <html> <head> <title>Set Image Width and Height</title> </head> <body> <p>Setting image width and height</p> <img src="logo.jpg" alt="Test Image" border="3" align="right" /> </body> </html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
2014-05-18 Windows Myeclipse 10 安装 Perl 插件
2010-05-18 14个优化网站性能提高网站访问速度技巧
2009-05-18 如何查看sql server版本号
2009-05-18 BlogEngine.NET Extensions
2009-05-18 BlogEngine.NET Widgets
2008-05-18 C语言程序设计 练习题参考答案 第八章 文件(2)
2008-05-18 C语言程序设计 练习题参考答案 第八章 文件(1)