HTML Images and Background
HTML Images and Background
DCIS1204
SEMISTER TWO
YEAR ONE
HTML Images
Note: It's a good practice to specify both the width and height attributes for an image, so that browser can allocate that much of space for
the image before it is downloaded. Otherwise, image loading may cause distortion or flicker in your website layout.You can use PNG,
JPEG or GIF image file based on your comfort but make sure you specify correct image file name in src attribute. Image name is always
case sensitive.The alt attribute is a mandatory attribute which specifies an alternate text for an image, if the image cannot be displayed.
Set Image Border
By default, image will have a border around it, you can specify border thickness in terms of pixels using border attribute. A thickness of 0
means, no border around the picture.
<!DOCTYPE html>
<html>
<head>
<title>Set Image Border</title>
</head>
<body>
<p>Setting image Border</p>
<img src = "/html/images/test.png" alt = "Test Image" border = "3"/>
</body>
</html>
HTML Images
By default, your webpage background is white in color. You may not like it, but no worries. HTML
provides you following two good ways to decorate your webpage background.
HTML Background with Colors
HTML Background with Images
Html Background with Colors
The bgcolor attribute is used to control the background of an HTML element, specifically page
body and table backgrounds.
Note − The bgcolor attribute deprecated in HTML5. Do not use this attribute.
The syntax to use bgcolor attribute with any HTML tag.
<tagname style=”background-color:color_value"...> It deprecated insteady use the following
syntax that is supported
HTML Background
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Colors</title>
</head>
<body style="background-color: yellow;" >
<!-- Format 1 - Use color name -->
<table width = "100%">
<tr>
<td>
This background is yellow
</td>
</tr>
</table>
</body>
</html>
HTML Background
<!DOCTYPE html>
<html>
<head>
<title>HTML Background Images</title>
</head>
<body>
<!-- Set table background -->
<table style=”background :/images/html.gif" width = "100%" height = "100">
<div style="background-image: url('img_girl.jpg');">
<tr><td>
This background is filled up with HTML image.
</td></tr>
</table>
</body>
</html>