Tutorials

Latest Word » Tutorials » 5 Ways to Spice up Your Images with CSS
5 Ways to Spice up Your Images with CSS

5 Ways to Spice up Your Images with CSS

Tags:

Here are a few simple tricks to add some flavor to your typical bland images. Using Photoshop to style each image can be tedious and difficult to maintain in the long run. These following CSS techniques will help you ease that pain! If you have some of your own techniques, please share them!

Drop Shadow Effect

Add a drop shadow by using a background image with some padding.

HTML

<img class="shadow" src="sample.jpg" alt="" />

CSS

img.shadow {
	background: url(shadow-1000x1000.gif) no-repeat right bottom;
	padding: 5px 10px 10px 5px;
}

Double Border Effect

This technique is probably the most common one out there right now. We create the double border effect by doing the following:

HTML

<img class="double-border" src="sample.jpg" alt="" />

CSS

img.double-border {
	border: 5px solid #ddd;
	padding: 5px; /*Inner border size*/
	background: #fff; /*Inner border color*/
}

Framed Image Effect

Best described on www.webdesignerwall.com, this technique basically layers a transparent image on top to create this effect. For those who need to get around the IE6 PNG issue, check out my tutorial here for details.

HTML

<div class="frame-block">
	<span>&nbsp;</span>
	<img src="sample.jpg" alt="" />
</div>

CSS

.frame-block {
	position: relative;
	display: block;
	height:335px;
	width: 575px;
}
.frame-block span {
	background: url(frame.png) no-repeat center top;
	height:335px;
	width: 575px;
	display: block;
	position: absolute;
}

Watermark Effect

You can add a watermark effect by lowering the opacity of the main image and allowing the background image to seep through. *Note this is just for the visual effect – To implement the protection check out the CSS Watermark Tutorial.

HTML

<div class="transp-block">
	<img class="transparent" src="sample.jpg" alt="" />
</div>

CSS

.transp-block {
	background: #000 url(watermark.jpg) no-repeat;
	width: 575px;
	height: 335px;
}
img.transparent {
	filter:alpha(opacity=75);
	opacity:.75;
}

Image with Caption

Add a quick caption using absolute positioning and transparency.

HTML

<div class="img-desc">
	<img src="sample.jpg" alt="" />
	<cite>Salone del mobile Milano, April 2008 - Peeta</cite>
</div>

CSS

.img-desc {
	position: relative;
	display: block;
	height:335px;
	width: 575px;
}
.img-desc cite {
	background: #111;
	filter:alpha(opacity=55);
	opacity:.55;
	color: #fff;
	position: absolute;
	bottom: 0;
	left: 0;
	width: 555px;
	padding: 10px;
	border-top: 1px solid #999;
}

Related Posts

Author Bio

My name is Soh Tanaka and I am a Los Angeles based designer/front-end developer specializing in CSS driven web design with an emphasis on usability and search engine optimization. I also run a CSS Gallery which is updated daily with the best CSS websites from around the world. Come check it out!

You can learn more about me or Twitter  Follow me on twitter for more updates and resources!

Did You Enjoy This Post?

subscribe  Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.

+ Add Comment72 Peeps Have Spoken Their Minds...

  1. Martin

    Wow these look really great. I think a lot more people should use the caption one. It’s really useful.
    Thanks again :)

  2. Lymorn

    I’m impressed, it work’s on IE.
    I tried to set background for images, but it didn’t work the way I was expecting.
    It’s good to know that now it work’s correctly.

  3. Swizec

    I do the caption one differently, that is, replace positioning with margins and abuse position: absolute just to get it to float above the image.

    This is because absolutely positioned elements are, correctly, displayed positioned according to browser borders, not parent element borders and you can get yourself into trouble quickly actually positioning an absolutely positioned element.

    *adds blog to RSS*

  4. Kaan

    Nice work

  5. Tay

    Hey, great article!

    It’s amazing how far a little polish on certain elements can go to creating a really professional finish.

    Fantastic site by the way…

  6. Mark

    Neat tricks, the only one that I’d caution people on is the watermark effect as it is not a true watermark and people can easily save an unmarked file via right click menu or a spider script. A true watermark (or flash type app) protects the image.

  7. Citizen Z

    The use of -moz-opacity is unnecessary unless you’re trying to support Firefox 0.8. (See the notes here.)

  8. wallpapers

    love the watermark example – very useful – thx

  9. Stormy Seas Photography

    Excellent post. Photography sites , including my own can benefit from this post.

    Thanks,

    Stormy Seas Photography
    http://www.stormyseasphotography.com

  10. Ben Grace

    Nice site. Great set of tools, especially the caption one.

  11. david

    hey, these are some nifty tricks … i particularly like the caption effect.

    however, the watermark is virtually useless. it might deter someone from stealing the image, but anyone who makes the effort to right click and save, will quickly learn that the watermark is only superimposed onto the image.

    none the less, thanks for sharing! :)

    cheers

    david
    http://www.davidsmeaton.com

  12. Soh

    Thank you all for the feed back :-)

    Swizec:
    Thanks for your tips on absolute positioning :-) I’ll definitely look out for that.

    Citizen Z:
    Thanks for the -moz-opacity tip, taking them out now!

    For those who would like to take the water mark effect a step further please check out my CSS Watermark Tutorial, although its not 100% steal proof, its a step further than this example above~

    Thanks again everyone :-)

  13. Nicholi

    These are great. The caption on the image looks nice. But how would I do it with several images with different widths?

  14. Lee

    I have been trying to do this for some time. Thank you for the tips.

  15. Soh

    Hey Nicholi,

    Try this one:

    View Demo

    .img-desc p {
    	float: left;
    	background: #111;
    	-moz-opacity:.55;
    	filter:alpha(opacity=55);
    	opacity:.55;
    	color: #fff;
    	position: absolute;
    	bottom: 0;
    	left: 0;
    	width: 100%;
    	padding: 10px 0;
    	margin: 0;
    	border-top: 1px solid #999;
    }
    .img-desc p span {
    	float: left;
    	padding: 5px 20px;
    }
    
  16. ahmei

    hey fantastic job! Appreciate it.

  17. G Dey

    Very nice and useful post.

    I am using the shadow trick in my ebay listings and since EBAY doesn’t support DOCTYPE, so it doesn’t work in IE but it is fine in Firefox.

    Can someone help me as how to fix that for IE ?

  18. woot

    Average

  19. IIssNan

    Nice tricks!
    Can I translate this article into chinese?
    thanks.

  20. ponie325

    GREAT WORK!~
    very useful to me!~
    3Q~

  21. Harry Roberts

    Some nifty stuff there, although cite is probably the wrong element to use unless you are citing something. Some captions may be citations from other sources, but not all. Picky I know, but I reckon a span would be the better element to use…

  22. David Hucklesby

    You’ll need to add a new declaration for opacity to work in IE 8. See here.

  23. Jon Haarstad

    Excellent collection of styling options. This sure beats the need to design things image by image. I really like your caption style… Great stuff.

  24. got my thumbs up.

    Works a treat.

  25. zrce

    wow thats great!

  26. techappeal

    Hi, i wanted to use your drop shadow method on my web site, but i just dont know how the background image “shadow-1000×1000.gif” needs to look like thank you and i will wait for your response

  27. Soh

    Hey Techappeal, here is the link to the drop shadow image.

    http://www.sohtanaka.com/web-design/examples/drop-shadow/shadow-1000×1000.gif

    Nothing fancy here, just a white square with a 5px drop shadow with the opacity set to 25% :-)

    Thank you all for the feedback :-)

  28. muneer

    ya really nice

  29. David Hutchison

    Great stuff. I’m trying it with the modification to work with images of any width. Only problem is when I try to add padding so that the text flowing around it is not right against the image. When I do this the transparent caption extends into the padding. Any thoughts?

  30. Soh

    Hey David~

    Check out this Demo.

    Instead of using <cite>, I used <p><span> this time. There was a padding issue and it was getting cut off by the overflow:hidden;

    Let me know if this was the issue you were having, if not can you please provide a sample link?

  31. Karen Timby

    Thanks for posting this! These are easy and will really put a polish on some pages I have that are pretty bland.

  32. David Hutchison

    Soh,

    Thanks for the demo but didn’t do the trick. I’ll send you a link as soon as it’s live. The problem comes when adding:

    img { padding-right: 10px;)

    so the text flowing around will have a little room. Then the transparent overlay also covers the padding.

    If I modify the width:100% to say 95% it works, but of course that removes the ability to fit all image widths.

  33. Soh

    Oh, I think I was misunderstanding you David :-p

    Did you mean you just want a margin so the outer paragraph text is not butting up to the image? If so, instead of adding a padding, you should switch to a margin~

    hehe but I think a link would solve this confusion, Ill just hang loose for your link :-)

    Thanks!

  34. Pat Anzanello

    I have one question about the use of shadow in the images of my blog posts: if they have different sizes is there a way to make the “shadow” match the image size with coding?
    Thank you!

  35. Soh

    If your asking about making the shadow effect fully liquid, yes there is a way. But the most simplest way is to use just one image that is big enough to cover most image sizes used on your website. Were you having trouble getting the shadow effect on your blog? Let me know, thanks~

  36. Craig Farrall

    Wow, this is a fantastic post, I have learnt a great deal from this, and will be doing some of these techniques in my upcoming websites.

    Thanks :)

  37. Sesso

    Great site.

  38. passie

    In the caption demo, is there a way to make the text not transparent ?

  39. Soh

    Hey Passie!

    I would first take off the transparency in the CSS, then add a 1×1 transparent png background stretching/repeating in the background. That would be the easiest way in my opinion~

  40. Imeily

    Nice tips, especially image with caption.

  41. Sudeep Tamrakar

    Nice tips. I am gonna apply it on my websites.

    thanks

  42. Dan

    Hello

    I try it with success with firefox or safari but with IE there are some problems

    look the test on this page : http://www.phonethik.com/spip.php?page=une

    thank for your help

  43. Soh

    Hey Dan, I would try to take out the div wrapping your image description (inside of the p and span tag) and replace it with a strong tag (any inline element). That should get you closer to where you need to be~

  44. Dan

    Thank you Soh, it’s perfect !

  45. Kate

    Great image effect (borders) I have not had a chance to try any more yet but many thanks.

    Love the theme too Soh.
    K

  46. Obadiah

    Useful post. I already use most of these techniques, but it’s good to know the other options.

    Thanks

  47. Ashwani

    Hello Soh,

    All effects are really superb, thanks :)
    I’ve used image shadow effect from here and its working really great.
    but i’ve a little problem. I need drop shadow all around the image, means at every side of image. there are lot of images and size of every image is different and i need only single class to give effect at these all images. So is it possible to make shadow at every side of image.

  48. create own website

    i like double border effect every time i see image with grey double border i was ask my self how they do that

  49. Syamil

    Is there a way to turn the coding into a simple plugin so I can install it without messing with my CSS?

    Thanks

  50. enque

    For Image With Caption you can also use a definition list.
    Like so:

    <dl class="pics">
    <img src="Path to your Image" />
    <dt class="captionBox" > </dt>
    <dd class="caption">
    This Is my Picture
    </dd>

    </dl>

    The good thing about it is you can define the background opacity without affecting the foreground text and without using a PNG.
    The bad thing is this doesn’t validate but it works fine in FF, Safari and Opera on MAC.
    I’ll need to test on IE.

    See it in action here: <a href="http://komuniq8.com/caption">here</a>

  51. yasin

    thaks…

  52. Daniel Groves

    Really need to try out some of these idea in the HiddenCSS re-think. BTW, nice lo design, I like it!

  53. aldrin

    Brilliant! I never thought that it would be possible to have it. Very nice and useful effect, I also check it on IE6,7 AND 8 and so far it works.

    Nice Job and thanks for sharing!

  54. cathy

    Thanks so much for this!

  55. ricky

    I need an example where I can display an image along with source/credits of image. Is there any good example available ? I need some reference. Thanks.

  56. John

    Great work, I was just poking around your site again for ideas. Wanted to let you know that the drop shadow effect isn’t lining up properly on Chrome v2.0.1.

    Keep it up, love your stuff!

    John

  57. lcyfer

    drop shadow
    IE cannot,

    are OK.

    Why?

  58. lcyfer

    sorry.
    drop shadow
    IE cannot,
    DOCTYPE HTML …TR/html4/loose.dtd
    DOCTYPE HTML …TR/html4/strict.dtd

    OK,
    DOCTYPE HTML …Transitional//EN

  59. rrmacman

    Cool ideas, thanks for sharing.

  60. sishimaru

    nhah..!

    i was looking for the trick to make a drop shadow effects with css for a weeks.

    Hi soh, thank you very much!

  61. agus

    Very nice Article
    thanks :)

  62. alisha

    have you got the same codes that work in fire fox ??

  63. vijaypal

    gud Article

  64. mohan

    superb

  65. ram

    Great work. How does the drop shadow work for non white backgrounds website. This works great if the site has white background but not with otehr colors.

  66. Rick

    I have made two rows of images with captions. How would I make the caption (.desc) so it displays over the image in the lower row instead of behind the lower row images? See example http://bit.ly/4qiFoG

    Thx it’s a great script

  67. Alex

    Good, and Useful!
    Thanks!

  68. aleksite

    two thumbs up for this! this is very useful!

  69. raghu

    hey nice post.. very usefull.. thankxx !

  70. Ranjit

    Nice idea.. Thanks for sharing.,

  71. Mooooo

    Coool, this is like the simplest and only working ‘image with caption’ effect that works for me… I am changing the simpler bits of the code.

    Question:
    How to automatically post title instead of manually entered text?

  72. ABM Adnan

    Thanks a lot for this post. I like the “Framed Image Effect”. I’m using it for my project.

Speak Your Mind...

Post HTMLNeed to Post HTML Code? Use Postable to post code friendly html. *Wrap all html code in <pre></pre> tags.
Post HTMLNeed to Keep Updated with Comments? Subscribe to comments now.

CSS Gallery