Introduction

Before reading this article please visit the following links:
HTML Links and Images
  • Links are found in nearly all web pages. Links allow the user to click their way from page to page.
  • Images are of various types.
For example, JPEG images, GIF images, PNG images and so on.

HTML Link: Hyperlink
HTML Link
HTML Links: syntax

In HTML, links are defined with <a> tag as in the following:
  1. <a herf= “url” >Link text </a>
Example
  1. <a herf= www.c-sharpcorner.com> c#corner </a>
Local Links

The example above uses an absolute URL (a full web address). A local link (link to the same web site) is specified with a relative URL (without http://www....).

Example
  1. <a href="htmlimages.gif">HTML Images</a>
HTML Links: Colors and Icons

When you move the mouse cursor over a link, two things will normally happen:
By default, links will appear like this in all browsers:
HTML Links: The target Attribute

The target attribute specifies where to open the linked document. This example will open the linked document in a new browser window or in a new tab.

Example
  1. <a href="http://www.c-sharpcorner.com/" target="_blank">Visit c#corner</a>
HTML Images
HTML Images

HTML Images Syntax
The alt Attribute
Example
  1. <img src="html5.gif" alt="The official HTML5 Icon">
HTML Screen Readers
Image Size: Width and Height
Example
  1. <img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Example
  1. <img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
Width and Height or Style
Example
  1. <html>
  2. <head>
  3. <style>
  4. img {
  5. width:100;
  6. }
  7. </style>
  8. </head>
  9. <body>
  10. <img src="html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
  11. <img src="html5.gif" alt="HTML5 Icon" width="128" height="128">
  12. </body>
  13. </html>
Images in Another Folder
Example
  1. <img src="/images/html5.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Example
  1. <img src="htmltags.gif" alt="HTML5 Icon" style="width:128px;height:128px">
Images on Another Server
Example
  1. <img src="http://www.google.com/images/google_gogreen.jpg">
Animated Images
Example
  1. <img src="programming.gif" alt="Computer Man" style="width:48px;height:48px">
Note that the syntax of inserting animated images is no different from non-animated images.

Using an Image as a Link

It is common to use images as links.

Example
  1. <a href="default.asp">
  2. <img src="smiley.gif" alt="HTML" style="width:42px;height:42px;border:0>
  3. </a>
Image Maps

For an image, you can create an image map, with clickable areas.

Example
  1. <img src="planets.gif" alt="Planets" usemap="#planetmap" style="width:145px;height:126px">
  2. <map name="planetmap">
  3. <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
  4. <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
  5. <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
  6. </map>
Image Floating

You can let an image float to the left or right of a paragraph.

Example
  1. <p>
  2. <img src="smiley.gif" alt="Smiley face" style="float:left;width:42px;height:42px">
  3. A paragraph with an image. The image floats to the left of the text.
  4. </p>

Chapter Summary