A web page’s appearance and design can be enhanced with images. An image can be embedded into a web page using the HTML <img>
tag. Technically, images are linked to web pages rather than inserted into them. The referenced image is held in place by the <img>
tag. The <img>
tag lacks a closing tag, is empty, and only has attributes. The <img>
tag necessitates two attributes:
alt
– Specifies an alternative text for the imagesrc
– Specifies the path to the image
The path (URL) to the image is specified by the mandatory src
attribute. If the user is unable to view an image due to a slow connection, a mistake in the src
attribute, or because they are using a screen reader, the required alt
attribute offers an alternate text for the image.
The width and height of an image can be specified using the style
attribute. The width and height of the image are always specified in pixels by the width
and height
attributes. In HTML, the width
, height
, and style
properties are all acceptable. The folder name must be included in the src
attribute if your images are in a subfolder.
Certain websites link to an image hosted on a different server. Flash GIFs are supported by HTML. Place the <img>
tag inside the <a>
tag to use an image as a link. To make an image float to the left or right of text, use the CSS float
property.
The most popular image file formats, compatible with Chrome, Edge, Firefox, Safari, and Opera, are listed below:
- JPEG
- PNG
- GIF
- SVG
To define an image, use the <img>
element in HTML. To specify the image URL, use the HTML src
attribute. If an image can’t be displayed, use the HTML alt
attribute to define an alternate text for it. To specify the image size, use the CSS width
and height
properties or the HTML width
and height
attributes. To make the image float to the left or right, use the CSS float
property.
Adding Images to HTML and CSS
An image can be embedded into a web page using the HTML <img>
tag. Technically, images are linked to web pages rather than inserted into them. The referenced image is held in place by the <img>
tag. The <img>
tag lacks a closing tag, is empty, and only has attributes. The <img>
tag necessitates two attributes: The image path is indicated by src
, and the alternate text for the image is indicated by alt
. The path (URL) to the image is specified by the mandatory src
attribute. If the user is unable to view an image due to a slow connection, a mistake in the src
attribute, or because they are using a screen reader, the required alt
attribute offers an alternate text for the image.
Resizing Images with HTML and CSS
Using the height
and width
properties on the <img>
tag is one of the easiest ways to resize an image in HTML. The browser downscales (or upscales) the image if the required height and width of the image element don’t match the actual dimensions of the image. In CSS, the height
and width
can also be specified. If you set the width and height as well, the picture may become out of proportion. By using the CSS property to set the height to auto
and only specifying width, you can maintain the aspect ratio. To make it responsive, you can set the width as a percentage rather than an absolute value. Another option is to use the max-width
property. When both height and width are specified, the image is resized to fill the given space. It might alter the aspect ratio from the beginning.
Combining Images with CSS
Discover how to use the display: inline-block
property in HTML and CSS to display multiple images side by side.
.services-image {
padding: 50px 50px;
width: 50%;
}
Adjusting Font Weight with CSS
How can I use CSS to make the font-weight thin? Use CSS to make the h1
font-weight thin.