In HTML, you can use the <img>
tag to add images to your web pages. Here is the basic syntax for the <img>
tag:
<img src="image.jpg" alt="Alternative Text">
In this example, the src
attribute specifies the URL or file path of the image you want to display, and the alt
attribute provides alternative text to be displayed if the image cannot be loaded or if the user is using a screen reader.
You can also use several other attributes with the <img>
tag to control the size, alignment, and appearance of the image, such as:
width
andheight
attributes: specify the width and height of the image in pixelsstyle
attribute: allows you to add CSS styles to the image, such as setting a border or applying filtersclass
andid
attributes: allow you to apply styles and JavaScript behaviors to the image using CSS or JavaScript
Here is an example of how to use some of these attributes:
<img src="image.jpg" alt="Alternative Text" width="300" height="200" style="border: 1px solid black;">
This code will display the image with a width of 300 pixels, a height of 200 pixels, and a 1-pixel solid black border around it.
Note that the <img>
tag is a self-closing tag, which means it does not have a closing tag. Also, make sure to use appropriate file paths or URLs for the src
attribute to ensure the image displays correctly.