programminghead Logo

HTML Tutorial 6

Images in HTML

Images are found in nearly all Web-Pages. Images are used to Gave data output in the form of Media so user can Understand your content easily. Images also be used to add more attractive Design to your Web-page bu using Great Background etc.
So in this Tutorial we are going to Learn about HTML Images.

Image Tag <img>:

<img> or HTML Element Defines Images inside HTML Documents.
To add Images links to a web-page we have to use HTML's <img> Tag for that.By using <img> tag we can insert one or Images to out HTML Web-page.

src Attribute :

HTML src attribute Defines the path/URL for our Image Tag.
for adding path to our Image Tag we have to write src attribute inside image's Starting tag <img> and inside the Double quotas of src we have to gave our image's URL with image Extension. src="url".
LIKE :

HTML Image Syntax :


<html>
  <head>
       <title>HTML Image</title>
  </head>
  <body>
       <img src="image.png"/>
  </body>
</html>

Image Path :

There is two types of path to link Images:
Local
and External

Local Image Path :

There is not always the case when you have to insert Image that's only available on the Internet, there are many cases when you just have to insert a image from your Local Machine (Computer) or a file that available on the same Location/Folder/Directory.
in local web-page cases we can insert Image without giving the full path. Just the file name and followed by the file Extension (.jpg/.png/.jif)

HTML Local Image Example :


  <img src="myimage.jpeg"/> 

External Image Path :

If your image file is on the Different directory then your have to Give full Path of that image. Because by default Browser will search that image on the same path where your web-page is. For adding external image or image from different folder/Directory you have to give full Path of that file with name and followed by the file Extension (.jpg/.png/.jif)

HTML External Image Example :


  <img src="c:/Desktop/HTML/myimage.jpeg"/>

HTML Image alt Attribute :

Image alt Attribute is used as a Alternative text for your image. Like i am going to add a Image of statue of liberty. So when ever i or any use Hover his mouse over the image then the ALT attributes text will aper. Use will knows many things LIKE Image detail, who is in that image or when due to some cases Browser couldn't Load our image the this ALT attribute will gave Image name/data in the form of text.

HTML Image Size Attributes


  <img src="cat.png" alt="my cat, chittu"/>

Resizing Images in HTML

Every time we insert Images in HTML Document it will tag up space according to the image size. If image is 100X150 the it will take the 100px in width and 150px in height in our browser screen, and rest of the page will remain Empty.
But we can resize images so our Image can take up the full screen space or according to our Needs.
for that we have 2 ways.

1. HTML image resize attribute.
2. CSS size properties.

1. HTML image resize attribute :

HTML give us two HTML image resize attributes width="" and height="" attributes. so inside the double quotes we have to give our custom image size in Pixels (100px).

HTML Image Size Attributes


  <img src="myimage.png" width="400px" height="430px"/>

2. CSS Resize properties :

Same as HTML Image size Attributes we have Height and with properties in CSS. we have to target our Image in CSS using TagName or By giving id or class name to our Image Tag. After Targeting image we just have to gave Height and Width values in Pixels like this :


  img{
     width: 200px;
     height: 160px;
     }

if you are using ID or Class name in CSS please don't forget to add # before id name and . period before class name.


HTML Image Style :

HTML Image Border Style :

By default HTML Image has no Border. But we can add Little Border with color to Our image.
just target your Image by tag (img) name or by id (#idname). and inside the Curly braces add css border Property and gave a Color and size to your Image.

Image Border Style Example :


img{
 border: 3px solid red;
 }			

results

HTML Image Float Position Style :

for Changing default image Floating point (which is left) use CSS float property.

Image Float Example :


img{
 float: right;
 }			

results


HTML Image Display Style :

CSS display property can hide or show your Image inside HTML Document. to hide your Image you have to set CSS display property to none, if you want to show your picture back again the just set CSS display property to Block.

Image Display Style Example :


img{
 display: none;
 }			

Image Hover Style:

for adding a nice Hover Effect on Image. we have to use CSS :hover attribute right after the tag name/id. This will only runs the CSS Properties on Mouse Hover.

Image Hover Effect:


img:hover{
   opacity:0.4;
       }			

results

Move your Cursor/Mouse over The Image

Background Image :

To add a background image on an HTML element, we have HTML body background attribute and we also can add background image to any HTML Elemnt by using CSS property background-image:

Background body attribute

This Background attribute can add background image to HTML Document. we just have to write background attribute inside the body's starting tag background="url"


<body background="bgimage.jpg">
</body>				

CSS Background image property :

for adding background image using CSS Background image property we have to target our HTML Body tag first in CSS. then inside the we have to write the CSS Background image property background-image: and after that we have to gave our image's URL inside url's braces/brackets url(image url)

Background Image CSS


<html>
<head>
<title>HTML Images</title>
<style type="text/css">
  body{
       background-image: url('cat1.jpg');
      }
</style>
</head>
<body>
	Background Image Example
</body>
</html>	

HTML Image Opacity Style:

Using CSS Opacity property we can change the Default Opacity Value (which is 1). so our image output can be Customized like little Blurry/transparent. We have to Set Opacity between 0 to 1. So 0 is the Lowest and 1 is the Highest Opacity Value.

Background Image CSS


<html>
<head>
<title>HTML Images Opacity</title>
<style type="text/css">
  img{
      opacity: 4;
     }
</style>
</head>
<body>
    <img src="dog2.png"/>
</body>
</html>	

HTML Picture Element :

HTML Picture element is another Useful Element for adding multiple images but displaying one at a time. Look this way. i want to display 3 images in 3 different ways.
image 1: i want to display image 1 on smaller mobile screens.
image 2 : i want to display image 2 on little large Tablets screens.
Image 3 : i want to display Image 3 on Bigger PC/Laptop's Screens.
in that case with the help of Picture Element i can display Images according to the Device Width by Declaring images ones.

for that we have to write Picture Element <frame> and inside frame's starting and closing tags we have to source Element. inside the Source's starting tag we have to write media attributes who allow Picture Element to react according to given width. so give 2 different width in min-width: and last the 3ed element will be Image tag without any min-width: properties, Because this last image will be your Default image when other 2 source element doesn't fill the Device requirements.

Picture Element Example :


<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HTML Pictute Element</title>
</head>
<body>
	<picture>
	  <source media="(min-width: 650px)" srcset="img_3.jpg">
	  <source media="(min-width: 465px)" srcset="img_2.jpg">
	  <img src="img_1.jpg" alt="Flowers" style="width:auto;">
	</picture>
</body>
</html>
	
Comments

minecraft download for free

http://tinyurl.com/y3klomno
05:25 pm

I loved as much as you will receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an shakiness over that you wish be delivering the following. unwell unquestionably come more formerly again as exactly the same nearly very often inside case you shield this hike.

download minecraft pc

http://tinyurl.com/y27hkfa2
03:33 pm

Thank you for some other informative web site. The place else may just I am getting that type of information written in such an ideal method? I've a venture that I'm simply now running on, and I've been on the look out for such info.

g

http://tinyurl.com/y3ke6ke4
08:33 am

I could not refrain from commenting. Very well written!

g

http://t.co/kqj8vNIvv4
12:10 pm

My family members all the time say that I am wasting my time here at net, but I know I am getting experience every day by reading thes nice posts.

minecraft free download pc

http://tinyurl.com/y3zy37gp
03:13 pm

Highly descriptive article, I loved that a lot. Will there be a part 2?

g

http://tinyurl.com/y3ubbhub
04:00 am

This is a great tip especially to those new to the blogosphere. Short but very accurate information_ Appreciate your sharing this one. A must read article!

g

http://t.co/M1niauDCGi
04:46 am

You have made some decent points there. I looked on the internet to learn more about the issue and found most people will go along with your views on this web site.

minecraft download mojang

http://tinyurl.com/yxh766ve
07:45 pm

A motivating discussion is worth comment. I do believe that you need to publish more on this topic, it might not be a taboo subject but usually people do not talk about these subjects. To the next! Many thanks!!

mojang minecraft download

http://tinyurl.com/yy5nerzp
08:47 pm

For most up-to-date information you have to pay a quick visit web and on web I found this site as a best web site for newest updates.

minecraft download free pc

http://tinyurl.com/y42va3cj
04:25 pm

Hello! Quick question that's completely off topic. Do you know how to make your site mobile friendly? My website looks weird when browsing from my iphone4. I'm trying to find a template or plugin that might be able to resolve this problem. If you have any suggestions, please share. Appreciate it!

mojang minecraft download

http://t.co/9iLvUiRiTh
12:23 pm

Genuinely when someone doesn't know after that its up to other people that they will assist, so here it takes place.

free minecraft

http://bit.ly/2LpECFj
11:23 am

I'm truly enjoying the design and layout of your website. It's a very easy on the eyes which makes it much more pleasant for me to come here and visit more often. Did you hire out a developer to create your theme? Fantastic work!

gamefly

http://tinyurl.com/y5zynqsc
03:23 am

I am really loving the theme/design of your weblog. Do you ever run into any web browser compatibility issues? A couple of my blog readers have complained about my blog not operating correctly in Explorer but looks great in Safari. Do you have any suggestions to help fix this problem?

gamefly free trial

http://tinyurl.com/y3b93ey8
05:12 pm

Hi there! This post could not be written much better! Looking at this post reminds me of my previous roommate! He always kept preaching about this. I'll send this information to him. Pretty sure he's going to have a great read. Many thanks for sharing!

gamefly

http://tinyurl.com/y5eo2npk
10:34 am

I'll right away snatch your rss as I can't in finding your e-mail subscription hyperlink or newsletter service. Do you've any? Please permit me know in order that I may just subscribe. Thanks.

gamefly free trial

http://j.mp/2WgriUR
04:08 pm

If you want to get a good deal from this post then you have to apply such methods to your won weblog.

gamefly free trial

http://t.co/P92kf8Nt02
06:39 am

I wanted to thank you for this excellent read!! I definitely loved every bit of it. I have got you book marked to check out new stuff you post_

Write to Us