Question:

How do you use the \texttt{ tag to insert an image into a webpage?}

Show Hint

Always include the \texttt{alt} attribute — it helps accessibility and shows text if the image cannot load.
Updated On: Feb 27, 2026
Hide Solution
collegedunia
Verified By Collegedunia

Solution and Explanation

Concept: <img> Tag

The <img> tag is used to display images on a webpage.

It is an empty tag (no closing tag required).


 

Important Attributes

AttributePurposeExample
srcSpecifies image path or URLsrc="photo.jpg"
altAlternative text if image failsalt="Beautiful sunset"
widthSets image widthwidth="300"
heightSets image heightheight="200"



 

Step-by-Step Explanation

StepExplanationCode
Step 1Basic syntax of image tag<img src="image.jpg" alt="Description">
Step 2Add local or online image sourcesrc="photo.jpg"
src="https://example.com/photo.jpg"
Step 3Add alternative text for accessibilityalt="A beautiful sunset"
Step 4Set width and height (optional)<img src="photo.jpg" alt="Sample" width="300" height="200">



 

Complete Example

<!DOCTYPE html> <html> <head>    <title>Image Example</title> </head> <body> <h2>My Image</h2> <img src="flower.jpg" alt="Flower Image" width="300"> </body> </html>
 

Conclusion

The <img> tag inserts images using the src attribute. The alt, width, and height attributes improve accessibility and display control.

Was this answer helpful?
0
0