HTML Images
Table of Content:
An image is a visual representation of something. Images can improve the design and the apperance of a web page.
You have the basics of text, but pages without images are . . . well, a little boring. Pictures do a lot for a Web page, and they’re not that hard to work with. Still, you should know some things about using pictures in your pages. In this chapter, you get all the fundamentals of adding images to your pages.
In This Chapter
- Understanding the main uses of images
- Choosing an image format
- Creating inline images
- Changing image sizes
- Modifying images with filters
Adding Images to Your Pages
- External link
- Embedded images
- Background images
- Custom bullets
HTML Images Syntax
In HTML, images are defined with the tag.
The <img>
tag is empty, it contains attributes only, and does not have a closing tag.
The src attribute specifies the URL (web address) of the image:
Adding links to images
Linking to an External Image
Live Preview
Here Image and .html file should be in same directories or folder.
The href
points to an image file, not an HTML page. You can point to any
type of file you want in an anchor tag. If the browser knows the file type (for
example, HTML and standard image formats), the browser displays the file.
If the browser doesn't know the file format, the user's computer tries to
display the file using whatever program it normally uses to open that type of file.
Adding inline images using the <img> tag
A.P.J. Abdul Kalam
A.P.J. Abdul Kalam, in full Avul Pakir Jainulabdeen Abdul Kalam (born October 15, 1931, Rameswaram, India—died July 27, 2015, Shillong), Indian scientist and politician who played a leading role in the development of India's missile and nuclear weapons programs. He was president of India from 2002 to 2007.
Live Preview
The image (img) tag is the star of this page. This tag allows you to grab an image file and incorporate it into the page directly. The image tag is a one- shot tag. It doesn’t end with </img>. Instead, use the /> characters at the end of the img definition to indicate that this tag doesn’t have content.
You might have noticed that I italicized A.P.J. Abdul Kalam in the page,
and I used the <em> tag to get this effect. </em> stands for emphasis, and
<strong>
means strong emphasis. By default, any text within an <em></em>
pair is italicized, and <strong>...</strong> text is boldfaced. Of course, you
can change this behavior with CSS.
src (source)
The src
attribute allows you to indicate the URL (Uniform Resource
Locator) of the image. This can be an absolute or relative reference. Linking
to an image in your own directory structure is generally best because you
can't be sure an external image will still be there when the user gets to the
page.
alt (alternate text)
The alt
attribute gives you an opportunity to specify alternate text describ-
ing the image. Alternate text information is used when the user has images
turned off and by screen-readers. Internet Explorer (IE) automatically cre-
ates a ToolTip (floating text) based on the alternate text.
You can actually add a floating ToolTip to any element using the title attribute. This works in all standards-compliant browsers, with nearly any HTML element
height and width
The height
and width
attributes are used to indicate the size of the image.
The browser uses this information to indicate how much space to reserve on
the page
You can use the style attribute to specify the width and height of an image.
Alternatively, you can use the width and height attributes:
One Example of height and width
Fixed size: width 130 height 130
Enlarged: width 160 (no height specified)
Stretched: width 80 height 150
align Attribute
No aligh
You have to dream before your dreams can come true. Look at the sky. We are not alone. The whole universe is friendly to us and conspires only to give the best to those who dream and work. Man needs his difficulties because they are necessary to enjoy success. Great dreams of great dreamers are always transcended.
We should not give up and we should not allow the problem to defeat us. Be more dedicated to making solid achievements than in running after swift but synthetic happiness. Climbing to the top demands strength, whether it is to the top of Mount Everest or to the top of your career.
aligh right
You have to dream before your dreams can come true. Look at the sky. We are not alone. The whole universe is friendly to us and conspires only to give the best to those who dream and work. Man needs his difficulties because they are necessary to enjoy success. Great dreams of great dreamers are always transcended.
We should not give up and we should not allow the problem to defeat us. Be more dedicated to making solid achievements than in running after swift but synthetic happiness. Climbing to the top demands strength, whether it is to the top of Mount Everest or to the top of your career.
left aligh
You have to dream before your dreams can come true. Look at the sky. We are not alone. The whole universe is friendly to us and conspires only to give the best to those who dream and work. Man needs his difficulties because they are necessary to enjoy success. Great dreams of great dreamers are always transcended.
We should not give up and we should not allow the problem to defeat us. Be more dedicated to making solid achievements than in running after swift but synthetic happiness. Climbing to the top demands strength, whether it is to the top of Mount Everest or to the top of your career.
Live Preview
Choosing an Image Format
Almost nobody uses raw images on the Web because they’re just too big and unwieldy. Usually, Web images are compressed to take up less space. All the types of image files you see in the computer world (BMP, JPG, GIF, and so on) are essentially different ways to make an image file smaller. Not all the formats work on the Web, and they have different characteristics, so it’s good to know a little more about them.
BMP
The BMP format is Microsoft’s standard image format.
JPG/JPEG
The JPG format (also called JPEG) is a relatively old format designed by the Joint Photographic Experts Group. (Get it? JPEG!) It works by throwing away data that’s less important to human perception. Every time you save an image in the JPG format, you lose a little information.
GIF
The GIF format was developed originally for CompuServe, way before the
Web was invented. This format was a breakthrough in its time and still has
some great characteristics.
GIF is a lossless algorithm so, potentially, no data is lost when converting an
image to GIF (compare that to the lossy JPG format). GIF does its magic with
a color palette trick and a run-length encoding trick
PNG
Open-source software advocates created a new image format that combines some of the best features of both JPG and GIF, with no legal problems. The resulting format is Portable Network Graphics, or PNG. This format has a number of interesting features, such as
- Lossless compression
- Dynamic color palette
- No software patents
- True alpha transparency
Images with respect to Folder
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:
Images on Another Server
Background Image
Background Image