Protect Your Images with CSS Watermarks
Tags: Beginner
This is an extension to my previous tutorial regarding enhancing images with CSS. What I went over was how to visually achieve the watermark on your image, but now let’s take a step further and protect the image from it being downloaded.
Let me be upfront with the downside of the technique, it’s not fully steal-proof. Anyone with knowledge of CSS and that are web savvy can still easily take your images. This only prevents the average Joe from taking them.
I will be going over two methods that are easy to achieve with some simple CSS.
Method 1
One popular site that uses this similar technique is Flickr.com. What we are doing is simply overlaying a transparent 1×1 pixel stretched to fit the size of the protected image. When a user tries to right click and save the image, they are only able to get the blank image that is layered on top.
HTML
<div class="watermark"> <img class="blank" src="blank.gif" alt="" /> <img src="homeland-longbeach.jpg" alt="" /> </div>
CSS
.watermark {
background: #000 url(watermark.jpg);
width: 500px;
height: 341px;
margin: 0 auto;
display: block;
position: relative;
}
.watermark img.blank {
width: 100%;
height: 100%;
display: block;
position: absolute;
left: 0;
top: 0;
}
.watermark img{
filter:alpha(opacity=90);
opacity:.90;
}
This is very simple to implement, but one major flaw in this technique is that the image is clearly shown in the source code. Anyone that is web savvy will be able to follow the path of the image and snag it.
Method 2
This second method takes a blank image and applies the protected image as a background. For those thieves who are familiar with HTML, will find that the image referenced in the source code is only the blank image and they would have to follow the style sheet to find the protected image.
HTML
<div class="watermark"> <img class="blank homeland" src="blank.gif" alt="" /> </div>
CSS
.watermark {
background: #000 url(watermark.jpg);
width: 500px;
height: 341px;
margin: 0 auto;
display: block;
position: relative;
}
.watermark img.blank {
width: 100%;
height: 100%;
display: block;
position: absolute;
left: 0;
top: 0;
}
.watermark img{
filter:alpha(opacity=90);
opacity:.90;
}
/*--Method 2--*/
.watermark img.homeland {
background: url(homeland-longbeach.jpg) no-repeat;
}
Note that this technique is only recommended for small galleries. Since we need to create a class for every image, this can be tedious to add manually. For large sites running a dynamic image gallery with hundreds of images, it’s probably better to go with method 1.
Conclusion
These are just some techniques you can use to protect your images with CSS alone. To fully protect the images, using JavaScript or Flash to combine the two images (Watermark + Protected Image) together into one is probably the best way. If you have any comments, suggestions, or concerns, please let me know!
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
Follow me on twitter for more updates and resources!
Did You Enjoy This Post?
Subscribe via RSS or by email to get all upcoming tutorials and articles delivered straight to you.





+ Add Comment28 Peeps Have Spoken Their Minds...
Great Tip. Method 2 in both cases doesn’t work in IE, but who cares. :)
Bah! Thanks for catching that, fixed!
Was missing (Left: 0; top: 0;) :-p
Nice techniques, but for the more web savvy it’s really easy to bypass these methods.
A nice addition to this would be the .htaccess configuration for avoiding hot linking!
Depending on your browser, disabling CSS is 1 to 3 clicks away. That’s usually enough to keep Joe user at bay though :p
Thanks Patareco for your htaccess suggestion~ :-)
Mathieu, your right. If they disable the css its free game!
This tutorial was only meant to keep the average user off of your images, the savvy peeps will get their hands on it no matter what~ :-p
nice tip, but i can see in source code where is your image … so it is not bulletproof ;-)
Your pics is here
http://www.sohtanaka.com/web-design/examples/water-mark/homeland-longbeach.jpg
Just a simple ctrl+i on firefox.
Web is share not restrict ;)
(But nice post anyway thanks).
Flickr also uses similar technique
First of all, I’d like to say, great article! I really like reading about this stuff and the idea’s some people come up with.
But… I also wanted to point out, that all these protections are useless against a visitor with Firefox. Just open the Demo page, go to Tools > Page Info. Tada.
Nevertheless, it’s a very nice solution and will prevent a lot of less web-savy people from stealing the images. But, in the end, if you don’t want people to steal your image, you shouldn’t put in online. ;-)
http://www.sohtanaka.com/web-design/examples/water-mark/homeland-longbeach.jpg
A quick source search got me that, so this is easily exploitable. Also as @Soh has said, if they disable the CSS it’s also there in the open for them to grab. I think CSS is a poor way to go about protecting an image. The only fool proof way is to water mark the actual image or photo.
But great proof of concept, and it looks like it was a fun little experiment. Thanks for sharing!
Not to speak on behalf of Soh, but I think he fully understands this method is not bulletproof and can be hacked by someone who knows even the slightest HTML or is good with a browser.
I think his main point of this was to show a very quick way of watermarking with css. In my opinion, one other great thing this illustrates is the power of PNG overlays. They can be extremely powerful. For example http://www.webdesignerwall.com/tutorials/css-decorative-gallery/
Great post Soh!
Not to speak on behalf of John, who is not speaking on behalf of Soh, but… People! Read the second paragraph “Let me be upfront with the downside of the technique, it’s not fully steal-proof. Anyone with knowledge of CSS and that are web savvy can still easily take your images. This only prevents the average Joe from taking them.” Why take the time to comment that just how easy it is to steal an image? Why? Why am I commenting now? I am wasting my ti-
great work
Another way to protect your photo is by using free online image watermark. This tool (called Batch Watermarker) can automate the whole process of image watermarking. If you are away from your PC and don’t want to download any software, you can just use this online version of watermarking tool for free. It’s quick and it’s easy to use.
You can also download their full version of Batch Watermark software program if you want to watermark multiple image files in a folder with just a click of the mouse.
I want to know css’s position in my blog layout.
I mean, in body or head maybe
There is another way that exactly watermark your pic using php and GD2. I myself using the codeigniter watermark class, but there are some alternative that could be checked here http://phpclasses.ca/browse/package/3261.html .
Thanks for this info. I have just been trying to save an image from flikr.com and wondered why I got a blank image (1 x 1 gif). To circumvent the problem, I just simply taken a screen shot of the image I wanted and crop the resulting screen image in a photo editor.
Now because of your info, I simply saved the complete WEB page into my computer and browse the accompanying image folder and there goes the protected picture I’ve been trying hard to download.
Note: I didn’t have to be a WEB savvy to do this simple trick of getting the protected image from a WEB page..
Thanks a lot…
First of all, I’d like to say, great article! I really like reading about this stuff and the idea’s some people come up with.
thank you
Great tips! I used option #1 and it works great in IE but only the blank images shows in Firefox?! Any suggestions?
Dude thats not bad but I can still steal it, whats the point of making watermark if I can steal it :D not bad but not perfect. I can remove the watermark with firebug, and in that moment print the screen and save the image without watermark :P
Taken from 2nd paragraph of introduction.
“Let me be upfront with the downside of the technique, it’s not fully steal-proof. Anyone with knowledge of CSS and that are web savvy can still easily take your images. This only prevents the average Joe from taking them.”
Clearly, if your adding a watermark via jquery/css there is going to be a way around it. If you didn’t come here knowing that you shouldn’t be using this concept. The idea is, the average user will likely not have the knowledge to download the untouched image, if your showcasing a photographer’s website who’s visitors are going to be in this group, the script is an excellent solution.
Great work Soh!
Morale of the story- If you wanna protect your images …… well there’s no way really. It’s even possible to strip images off a flash anim nowadays.
Nice post though.
If you really wanted your image to be fully protected by a water mark wouldn’t you just watermark it yourself in photoshop? That way the watermark can’t be removed.
But it’s nifty to know you can do this with css.
Hey nice site by the way, I’ve been reading through your articles for a while and picking up some new techniques and getting ideas to revamp my own site. I’m looking to set up a similar business you’ve got running here, all though I’ll be focusing more on illustration and graphic design, as I’ve just finished my illustration course and need to get started in this industry, which seems overwhelming now because there are A LOT! of designers out there now days, whoah. I guess I’ll just start off small and gradually step up the ladder.
But once again, awesome site. It’s helping me a lot :D
This Is good it’s just unsafe I can easlly right click and click source code and download the image.
what you need to do is when the file uploads to put it in the image. So it’s stuck.
Very nice technique and explaination! Thanks a lot Soh!
Another technique is make the content with javascript and encrypted.
Speak Your Mind...