Sunday, 31 August 2008

The img tag: other attributes

NB: The code samples used in this post all have a full stop/period after the opening bracket like so <. This is to ensure the code displays on the page and isn’t interpreted as HTML by your browser - in which case it would be invisible. Of course, this full stop should not be used in reality.

In my post ‘How to wrap text around an image’ I mentioned other attributes you can use with the img (image) tag. Today, we will have a look at these.

Border - To add a border to an image simply include the border attribute as shown below:

<.img src=”yourimage.gif” border="1" />

This will create a border 1 pixel thick, but you can make this larger if you wish. Alternatively, you may not want a border at all, in which case simply use the value "0";

Height and width - It is a good idea to define the height and width of your image to ensure it displays correctly. Logically, you do this using the ‘height’ and ‘width’ attributes.

<.img src=”yourimage.gif” border="1" height="200" width="200" />

Alt and title - These can be used to add a description to your image, and are probably the most important attributes to use.

<.img src=”yourimage.gif” title=”myimage.gif, designed by Some Body” alt=”type a description of your image here” />

Although, ‘alt’ and ‘title’ appear to be one and the same (and some people do use them interchangeably) they are actually quite different, here’s why.

The text entered in the ‘alt’ attribute appears when the image is not displayed for some reason. This may be because the viewer has disabled images in their browser, or they may be a visually impaired person who uses a text to speech browser. Writing an accurate description of the content of the image will enable a visitor to see how relevant it is to the subject they are searching for, or give someone who can’t actually see your page a more rounded experience of visiting it - in the same way that visually impaired people sometimes use a narration service which adds a voice over to television programmes describing actions, landscapes etc. Don’t make this description too long, a nice, concise sentence is enough. For example, if you add a photograph of a red rose, the description could be ‘close up photo of a red rose in bloom’.

The ‘alt’ attribute is also visible to search engine bots, which can’t see images. So, if you blog about a visit to the Taj Mahal, and include a photo with the description ‘a photo of the Taj Mahal’ the bots will pick this up, and anyone (who for some reason) doesn’t know what the Taj Mahal looks like can visit your blog or site to find out.

The ‘title’ attribute, is used to provide extra information about the image itself, for example, it’s title, and the photographer or designer. Going back to the Taj Mahal example, you could use "Taj_Mahal.jpg, photographer Some Body, date 20/10/07". When a visitor holds their mouse cursor over your image, this information will appear in a little information box. Internet Explorer does the same with the ‘alt’ attribute, but this is non-compliant.

By the way, the ‘title’ attribute can be used with other tags, most commonly links.

One more thing, you may have noticed the there is a forward slash at the end of the image tags I have used. This is now the standard. HTML did not require image tags to be closed in this way, XHTML is now the standard and this requires all tags to be closed, but that is another post.

If you have any questions leave a comment below, and if you want to know more try the following links:

  • Find out about web standards
  • Find out more about web accesibility


  • A Little Bit of Fry and Blogging

    I have just discovered something quite mind-boggling: Stephen Fry has a blog - a website too! I know it isn’t unusual for celebs and famous folk to have an online presence, but usually they call in a designer and a ghost writer to run it all for them. However, much to my surprise, Britain’s poshest comedy actor* does it all himself. On his website he mentions designing his first site a decade ago!

    And now to make this relevant, here’s a prompt: Stephen Fry is an example of someone who challenged my preconceptions about him. Create a character who is similarly surprising, someone who seems to conform to a certain stereotype, but who in reality is far more complex.

    * If you discount Prince Philip, who doesn’t qualify because he isn’t pretending.



    This post was originally published on September 24th, 2007

    Saturday, 30 August 2008

    How to: Wrap text around an image

    Example ImageNB: The code samples used in this post all have a full stop/period after the opening bracket like so <. This is to ensure the code displays on the page and isn’t interpreted as HTML by your browser - in which case it would be invisible. Of course, this full stop should not be used in reality.

    As you can see the text on this page wraps around the image on the left. It is easy to create the same effect on your own site or blog with the use of ‘align’ within the image tag. If that sounds complex, fear not, it really isn’t. This is what you would use to align an image to the left.

    <.img src=”yourimage.gif” align=”left” />

    You could also align to the right, or center - note the use of the American spelling, this is the correct form. Align simply tells your browser where it should position an image on a page.

    To create some space between the image and your text you can define the amount of horizontal and vertical space by using ‘hspace’ and ‘vspace’ like so:

    <.img src=”yourimage.gif” align=”left” hspace="5" vspace="5"/>

    This creates a nice area of white space between your text and the image, which looks neater and less crowded. You can, of course, adjust these amounts.

    There are other attributes you can use with the image tag, but I’ll discuss those in another post. For now, I hope this of some use to Diddums :-)

    First published on February 12th, 2007

    My Top 11 Tools

    There’s an interesting thread over at the Authority Blogger forum* about ‘must have’ tools. Of course, different bloggers have different priorities, so the responses have varied quite a bit. However, there are some constants - for example, Firefox, it does seem to be the browser of choice for most bloggers. I thought I’d list my choices here, and explain why these particular tools suit my purposes.

    • Firefox: Do I really need to explain more? There are many great things about FF, not least the fact that it so easily customisable. The range of add ons grows by the day and when it is combined with Greasemonkey, Firefox becomes far more than just a means of viewing web pages.
    • Rough Draft: I have blogged about Rough Draft before, mainly because it is so incredibly useful. If you are looking for a small, fast word processor with special tools for writers, do take a look - oh, and did I mention, it’s free!
    • WordWeb: Every writer needs a good dictionary and thesaurus, and WordWeb is both. It sits in your desktop toolbar and can be activated with a click, it’s also compatible with Rough Draft.
    • Google Reader: Google’s own feed reader. I wasn’t keen at first, but over time it has improved and I now find it the easiest way to keep up with new posts from my favourite blogs. Feeds can be sorted into categories using tags, which is really useful because it means I can keep a separate list just for research.
    • WordPress: I use the self-hosted version - as you can see. Yes, there are numerous blogging platforms available, but WP is a bit like the Firefox of blogging. It’s easy to use, extremely customisable and it’s free.
    • Google Analytics: Google’s free blog and site statistic tracker and analyser. In other words it tracks your visitors and gives you all sorts of useful info about how they use your site. I have a stats package provided with my hosting service, but I tend to use Google instead, simply because I find it easier to figure out what everything means.
    • Thunderbird: Mozilla’s free email client. Once again, there are other options, but Thunderbird, is very fast, customisable, and user friendly. You can use it as feed reader too.
    • Google Alerts: A free service which tracks words or phrases. I use it to keep track of how my blog posts are being used, and also to keep up with the latest information about various topics.
    • Internotes: A sticky notes Firefox extension. Really useful for adding a description or reminder to a web page you want to write about or refer to later.
    • Ace HTML: A free HTML editor - not a WYSIWYG, you have to write the code yourself. It’s simple to use, and defaults to XHTML, but you can also work in HTML, PHP, XML, CSS and several other formats.
    • PhotoImpact - No, it’s not as glam as Photoshop, but it does everything I want and creates new layers automatically, having to do that manually in Photoshop is really annoying.



    My final choice was Winamp, mainly because I am using it at the moment. However, any music player would do, it’s the music that really counts - you can see my writing soundtrack in the nearest sidebar.



    So, what about you? What are your favourite tools?



    * I think you might need to register to read the thread, but it is free and well worth it. 



    First published on October 14th, 2007

    Test Post

    This is a test post for design purposes, please ignore