HTMLGoodies
The ultimate html resource
Earthweb.com


About the Double-Underlined Links


Become a Partner




Search Clipart.com:



internet.commerce















HTML Goodies : Primers : HTML Primer: Basic HTML: Images

HTML GOODIES TO GO NEWSLETTER


Other Related Newsletters

Basic HTML: Images


By Joe Burns

(with updates by editorial staff)

Use these to jump around or read it all
Placing Images
What's Happening
Image Formats
Where To Get Images
Activating Images

By now you know enough to write a very nice, text-based home page, but it is the ability of the World Wide Web to provide pictures, technically called images, graphics, or sometimes icons, that has made it so popular. In this Primer, you'll learn how place an image on your page and also how to turn an image into a link to another page.


Placing An Image On Your Page

The command to place an image is constant. You will use the same format every time.

Now might be a good time to talk about where to store everything because you're starting to call for additional items to fill up your home page. Until now, all you did was put text on the page. Now you're going to place an image.

At this point in your HTML career, it's a good idea for you to place whatever images you are going to use in a subdirectory called "images". That means place the image in a directory (to be called "images") under the directory where your web pages are located (which would be the "root" directory for your site). There's more on that coming up in Primer #7.

Here's the format for placing an image:

<IMG SRC="image.gif" ALT="some text" WIDTH=32 HEIGHT=32>

By replacing "image.gif" with "homepage.gif", one of my own graphics, you get this...

Here's What's Happening

  • IMG stands for "image." It announces to the browser that an image will go here on the page. Yes, the image will pop up right where you write in the image tag.

  • SRC stands for "source." This again is an attribute, a command inside a command. It's telling the browser where to go to find the image. Again, it's best for you to place the images you want to use in a subdirectory called "images". This way you can call for the image by name with just the subdir name in front of it, like this: /images/imagename.gif. Right now, let's just get it to work.

  • image.gif is the name of the image. Notice it's following the same type of format as your HTML documents. There is a name (image) then a dot and then there is a suffix (gif).

  • ALT stands for "alternate text". This tells the browser that if it can't find the image, then just display this text. It also tells anyone who can't view your image what the image is about. For example a disabled user using a screen reader, or dare I mention it, Search Engines.

  • "some text" is where you put the text describing your image.
  • WIDTH stands for just that, the width of the image in pixels. It can range from 1 pixel to, well, just about any number, but generally will be less than the width of the web browser.

  • HEIGHT stands for, as you might guess, the height of the image in pixels. Again, the height can be just about anything, but generally will be less than the height of the web browser.


Image Formats

There are four basic formats you will find on the World Wide Web. Each is denoted to the browser by a different suffix. Remember that "name.suffix" discussion from Primer #1?

  • .gif This is pronounced "jif" or "gif" (hard "G") depending on whom you speak to. I have always said "jif", like the peanut butter. This is an acronym for Graphics Interchange Format.
         The format was invented by Compuserve and it's very popular. The reason is that it's a simple format. It's a series of colored picture elements, or dots, known as pixels, that line up to make a picture. Your television's picture is created much the same way. Browsers can handle this format quite easily.

  • .png Pronounced as 'ping', this stands for Portable Network Graphic. This is ultimately the replacement for .gif, with partial transparency options, but browser support is sometimes disappointing, so try experimenting but don't expect miracles in older browsers! Even some of the newer ones don't like partial transparency.

  • .jpeg or .jpg (pronounced "j-peg") There are two names to denote this format because of the PC and MAC formats allowing 3 and 4 letters after the dot. JPEG is an acronym for Joint Photographic Experts Group, the organization that invented the format.
         The format is unique in that it uses compression after it's been created. That's fancy computer talk that means that when the computer is not using a .jpeg image it folds it up and puts it away. For example, if the picture is 10K bytes when displayed, it may be only 4K bytes when stored. Nice trick, huh? It saves on hard drive space, but also tends to require a bit of memory on your part to unfold the image.
         Someone always writes to me to tell me that .gif images also use compression. Yes, they do, but only when they are first created into that format. After that, no compression. JPEG, on the other hand, uses compression throughout its life to fold up smaller than it really is.

  • .bmp (pronounced "bimp") This is a "bitmap." You will probably never place a bitmap as an image, although now Internet Explorer browsers allow it. A bitmap is an image that a computer produces and places for you. A counter is an example.
         Even though Internet Explorer will allow you to place an image as a BMP, I wouldn't. No other browsers will be able to display it. Go with .gif or JPEG.


    Where Do I Get Images For My Page?

    They are literally everywhere. There are plenty of sites out there that offer tons of free images. Plus, since you've been surfing, you've seen hundreds of images already. If you see something on someone's page that you really like, ask to use it. Don't just take it. That's not right and could be against copyright law. Ask. You'll probably get the image. In no time you'll have a slew to use on your page. One great place to start is our own JupiterImages, which has literally hundreds of thousands of images for use on your web pages.


    Activating An Image

    Okay, this gets a little fancy. In Primer #4, I showed you how to create a hypertext link. What it did was create blue words on your page so someone could click on them and then jump to another site. Well, here we're going to set it up so an image becomes clickable or "active." The viewer would click on the image, instead of on blue words, to make the hypertext link. I'll make a link to my home page using the image above.

    Here's the format:

    <A HREF="http://www.htmlgoodies.com"><IMG SRC="homepage.gif" ALT="Home"></A>

    Look at it again. See what happened? I placed an image tag where I would normally have placed words. However, in case the image isn't visible for any reason I've added some alternate text stating where the link goes.

    Here's what you get with that format. Lay your pointer on the image, but don't click. You'll see the entire image is active:

    Home

    Neat, huh? But what's with that new border around the image? That's what happens when you activate an image. It attempts to turn blue, or whatever color the page is set to, like the wording it's replacing, so it places what's known as a "border" around the image. Some people like it. I don't, and I know how to get rid of it.

    To make the border disappear, we need a tiny bit of CSS. This used to be done using the Border attribute, but that's unfortunately no longer with us...

    Here's the format:

    <IMG STYLE="border: none;" SRC="homepage.gif" ALT="Home">

    See what I did? I added some CSS that denoted that there should be no border. You can go the other way too if you'd like. Make it "border: 55px solid blue;" if you want. It'll just make a huge border. Note that the CSS is in quotes.

    Here's what you get using the CSS

    Home

    Again, lay your pointer on the image without clicking. You'll see that it is active but doesn't carry that annoying blue border.

    And that brings this to a close. Tomorrow you'll deal almost exclusively with attributes in order to manipulate your images. You'll truly impress your friends with this one.

    Placing Images
    What's Happening
    Image Formats
    Where To Get Images
    Activating Images

    Tools:
    Add htmlgoodies.com to your favorites
    Add htmlgoodies.com to your browser search box
    IE 7 | Firefox 2.0 | Firefox 1.5.x
    Receive news via our XML/RSS feed

    IT Management Networking & Communications Web Development Hardware & Systems Software Development Earthwebnews.com



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    IBM Whitepaper: Service Component Architecture Enabling XML Web Services for Java Programmers
    IBM Whitepaper: Innovative Collaboration to Advance Your Business
    Intel Article: Using Power & Display Context in the Intel Mobile Platform SDK
    Internet.com eBook: Real Life Rails
    IBM SCA Center Article: Simplifying Composite Applications with Service Component Architecture
    Intel PDF: Quad-Core Impacts More Than the Data Center
    Internet.com eBook: The Pros and Cons of Outsourcing
    Go Parallel Article: Scalable Parallelism with Intel(R) Threading Building Blocks
    Intel PDF: Analysis of Early Testing of Intel vPro in Large IT Departments
    Internet.com eBook: Best Practices for Developing a Web Site
    Intel PDF: IT Agility through Automated, Policy-based Virtual Infrastructure
    IBM CIO Whitepaper: The New Information Agenda. Do You Have One?
    Microsoft Article: BitLocker Brings Encryption to Windows Server 2008
    IBM Whitepaper: Service Component Architecture & Java EE Integration
    Microsoft Article: RODCs Transform Branch Office Security
    Go Parallel Article: James Reinders on the Intel Parallel Studio Beta Program
    Avaya Article: Advancing the State of the Art in Customer Service
    IBM Whitepaper: How are other CIOs driving growth?
    Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
    Avaya Article: Avaya AE Services Provide Rapid Telephony Integration with Facebook
    Go Parallel Article: Getting Started with TBB on Windows
    HP eBook: Storage Networking , Part 1
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Go Parallel Video: Intel(R) Threading Building Blocks: A New Method for Threading in C++
    HP Video: Is Your Data Center Ready for a Real World Disaster?
    HP On Demand Webcast: Virtualization in Action
    Go Parallel Video: Performance and Threading Tools for Game Developers
    Rackspace Hosting Center: Customer Videos
    Intel vPro Developer Virtual Bootcamp
    HP Disaster-Proof Solutions eSeminar
    HP On Demand Webcast: Discover the Benefits of Virtualization
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Download: IBM WebSphere Application Server V7.0 Feature Pack for Service Component Architecture
    Actuate Download: Free Visual Report Development Tool
    Microsoft Download: Silverlight 2 Software Development Kit Beta 2
    30-Day Trial: SPAMfighter Exchange Module
    Red Gate Download: SQL Toolbelt
    IBM SCA Download: Start Building SCA Applications Today
    Iron Speed Designer Application Generator
    Microsoft Download: Silverlight 2 Beta 2 Runtime
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    IBM IT Innovation Article: Green Servers Provide a Competitive Advantage
    Microsoft Article: Expression Web 2 for PHP Developers--Simplify Your PHP Applications
    Featured Algorithm: Intel Threading Building Blocks - parallel_reduce
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES