Contents
HTML Image Tag: Main Tips
- HTML
<img>
tag defines an image in an HTML page. - To link an image to another document, use the
<img>
inside <a> tags.
Use and Purpose of img
HTML <img>
tag sets an area for an image. The img scr
attribute is required (usually a link).
Tip: the img element only needs an opening tag.
This image above was added with the following code, including the HTML image tag.
Note: images are not inserted into an HTML page, but linked to the HTML page.
- Easy to use with a learn-by-doing approach
- Offers quality content
- Gamified in-browser coding experience
- The price matches the quality
- Suitable for learners ranging from beginner to advanced
- Free certificates of completion
- Focused on data science skills
- Flexible learning timetable
- Simplistic design (no unnecessary information)
- High-quality courses (even the free ones)
- Variety of features
- Nanodegree programs
- Suitable for enterprises
- Paid Certificates of completion
- A wide range of learning programs
- University-level courses
- Easy to navigate
- Verified certificates
- Free learning track available
- University-level courses
- Suitable for enterprises
- Verified certificates of completion
Attributes to Use
alt
It indicates an alternative text for an image when it cannot be displayed.
crossorigin
It specifies that images are from third-party websites, allowing cross-origin access.
height
It defines image height in pixels.
longdesc
It adds an URL to a detailed description of an image.
<img src="image.png" alt="Doggo" width="205" height="205" longdesc="#description">
src
img src
sets the URL of an image.
width
It defines image width in pixels.
Deprecated Attributes
align
It defines the alignment of an image according to surrounding elements. Not supported in HTML5.
You should use CSS instead. Learn how to position elements in the Horizontal & Vertical Align tutorial.
border
It defines border width around an image. Not supported in HTML5.
Instead, use CSS border
property. Learn how in the CSS Borders tutorial.
<img src="image.png" alt="Doggo with a 5 pixels border" border="5">
hspace
It creates a whitespace on the left and the right side of an image. Not supported in HTML5.
Instead, use CSS margin
property. Learn how in the CSS Margins tutorial.
vspace
It creates a whitespace on top and bottom of an image. Not supported in HTML5.
Instead, use CSS margin
property. Learn how in the CSS Margins tutorial.