4 Simple & Attractive Ways To Style Images With CSS
Blogging, Programming, Web Development September 18th, 2007There are many different ways that you can style plain images with CSS. This is very useful for normal web development but probably more so for content publishing. If you’re like most content publishers, focusing on your writing rather than web programming, then here are four simple tricks for styling images withing your content.
Note: All of the example images are “floated” and have margins applied to push text away from them. I left that out of the code examples for simplicity.
1. Wrapping Text
The most basic of image styling techniques, wrapping text around images, can be done with one simple CSS addition. A normal image HTML tag will be written like:
<img src=”/path/to/image.jpg” />
This will display the image fine, but it will push all text to the bottom of it. If you want your text to wrap around the image, simply add a float style attribute to your image tag like so:
<img src=”/path/to/image.jpg” style=”float: right;” />
That’s it. If you want the image to be left-aligned, you would obviously change the property to “float: left;”
2. Single Border
More often than not, rectangular content images look odd without some kind of border. You could add a border in your image editing application, but it is much easier (and more flexible) to add the border with CSS. Simply add more styling to your image tag:
<img src=”/path/to/image.jpg” style=”border: 2px solid #f5e53e;” />
In this example, we have used the shorthand border property. The first value “2px” sets the width of the border, the second value “solid” defines the type of border, and the final value “#000000″ defines the color of the border. Check out w3schools for a list of all CSS border properties.
3. Double Border
What if you want your images to have a double border effect? Well, CSS only allows you to specify one border, but you can still make it happen. What you need to do is set a background color (inner border color), padding (inner border width), and outer border properties. Here we go:
<img src=”/path/to/image.jpg” style=”background-color: #f7d8a9; padding: 3px; border: 1px solid #6f3d29;” />
The only limitation of this method is that you cannot specify border styles for your inner border. You could, however, specify a background-image for it.
There are many things you can do with this technique, one of them being a polaroid effect. To achieve this, simply set the padding options independently so that you bottom padding is larger than the rest: “padding: 2px 2px 10px 2px;”
4. Image Captions

Before the tornado…
This technique builds upon the “polariod effect” that was just mentioned. We are going to include text within the inner border of the image. It requires a bit more HTML though. You need to enclose both your image and your caption inside of a container (a “p” in this example) and apply styling to that container. Here is an example:
<p style=”border: 1px solid #cccccc; padding: 6px; text-align: center; width: 125px;”><img src=”/path/to/image.jpg” />Caption text goes here.</p>
You may have noticed that I also specified a width for our container. There are other ways to do it, but hard-coding a width in there is the easiest. This image is “125px” wide, so I set the container to that width. Also, everything has been centered inside that container with “text-align: center;”
Other Not-So-Simple Techniques
There are tons of cool things you can do with images and CSS, but many of them require external stylesheets and wouldn’t work well within this blog post. Here are some of my favorites:
Conclusion
There they are, four simple techniques and four not-so-simple techniques for styling images within your content. Many of you might already be CSS experts, but I am pretty sure there are people out there wondering how to make images look attractive within their blog posts and other content.
Do you have any other tricks that you like to use for styling images? Do you think it’s easier to do this stuff with tables instead of CSS? Leave a comment and let us know.

September 21st, 2007 at 8:36 am
[...] 4 Simple Style Tips for Images Make your pictures look good [...]
September 21st, 2007 at 12:42 pm
[...] shows 4 examples how to style images with CSS. If you don’t know CSS, read it. And because he writes a lot of great posts about affiliate [...]
June 13th, 2008 at 1:40 am
[...] Mit CSS kann man auch den Cursor ändern und sogar sein eigenes Bild als Cursor anzeigen lassen. Bilder Style mit CSS, Erklärt, wie man mit CSS Style in seine Bilder bringt, wie Rahmen, Beschreibung…. CSS [...]
November 13th, 2008 at 1:15 pm
Many thanks. I have been looking for a quick and easy way to put captions under images without using table cells.
March 22nd, 2009 at 4:02 pm
Haha ^^ nice, is there a section to follow the RSS feed
January 18th, 2010 at 2:22 am
[...] Font Tester is a must check for every CSS lover, it’s a simplistic tool for generating your font style CSS code without coding it. I loved the character map here, but would have loved it more if we could upload our fonts for it to generate image replacement codes for sIFR or EOT files for it. Never mind, you can use sIFR Generator to do the same. Also check out image caption class out here. [...]
February 5th, 2010 at 4:40 am
[...] control style each image individually, you could add some css style code within the img src code. This site has a few suggestions __________________ WordPress Theme Grrl | Autism Merchandise | Doctor Who [...]
February 5th, 2010 at 5:36 am
[...] control style each image individually, you could add some css style code within the img src code. This site has a few suggestions on how to do it! __________________ WordPress Theme Grrl | Autism Merchandise | Doctor Who [...]