How to style an image using CSS

The goal of this tutorial is to explain how to use cascading stylesheets to alter the display of images in html.

Let's start with this image. To include it in your webpage, you should write html like this:

<img alt="smile" src="smile.jpg">


But, that is a huge and unwieldy smiley face! You would really prefer to see it displayed with the following attributes:

You need to use a cascading stylesheet and set some styles on your "img" tag.

Link your html page to a stylesheet by adding this line in the "head" section of your html document:

    <link href="border.css" rel="stylesheet" type="text/css">
    <img alt="smile" src="smile.jpg">

The contents of the border.css file should be:

img {
  width: 200px;
  border: solid 6px black;

The end result should look like this: