Image Size - Width and Height: Concept Note 3 Using HTML Images

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Concept Note 3

Using HTML Images


 The <img> tag defines an image in an HTML page.
 The <img> tag has two required attributes: src and alt.
 Images are not technically inserted into an HTML page, images are linked to HTML pages.
The <img> tag creates a holding space for the referenced image.
 The <img> tag is an empty tag, which means that it can contain only list of attributes and it
has no closing tag.
Attributes of the <img> tag

Attribute Value Description

alt text Specifies an alternate text for an image

height pixels Specifies the height of an image

src URL Specifies the URL of an image

width pixels Specifies the width of an image

Image Size - Width and Height


The style attribute can be used to specify the width and height of an image.The values are specified in
pixels (use px after the value).
Example: <img src="image.jpg" alt="image" style="width:128px;height:128px;">

Alternatively, you can use the width and height attributes. The values are specified in pixels by
default, no need to add px after the value.
Example:
<img src="html5.gif" alt="HTML5" width="128" height="128">
Both the options are available in HTML5.

Images in Another Folder


If not specified, the browser expects to find the image in the same folder as the web page.However, it
is common to store images in a sub-folder. You must then include the folder name in the src attribute:

Example:
<img src="/images/image.jpg" alt="sample text">

Aligning images
For the image to align middle, top, or bottom use the CSS property vertical-align.
For the image to align left or right use the CSS property float.
Image Floating
Use the CSS float property to let the image float to the right or to the left of a text.

SYNTAX: <img style= “float: value” >

Vertical Align Property


The vertical-align property sets the vertical alignment of an element.

SYNTAX: <img style= “vertical-align: value” >

You might also like