Tuesday, June 1, 2010

How to hide an image inside text in an HTML page

Last week I showed you an old trick using which you can hide one image inside another image in such a way that the hidden image is revealed only when you select the image on Internet Explorer. Today I’m going to show you another trick.

Unlike the previous trick which worked only on IE, this one doesn’t work on IE at all. Take any modern web browser like Firefox, Opera and Chrome and open this page. You will see a wall of text. Now press CTRL+A to select the whole page. You should see an image. Click anywhere on the page and the image disappears.

This is a wonderful demonstration of a CSS3 declarations called ::selection.

::selection allows you to override the browser-level or system-level text highlight color with a color of your choice. This is one of those clever CSS tricks web developers can take advantage of to make their site stand out from the crowd.

Here is the code that makes this possible.

::selection {
    background: #00ff00; /* Webkit and Presto */
::-moz-selection {
    background: #00ff00; /* Gecko */

The first code works on Webkit based browsers such as Chrome and Safari and the Presto engine powered Opera. The second code works on browsers running the Gecko engine such as Firefox, Flock etc.

When this code is added to a webpage’s style sheet, the browser text highlight color is overridden by the one you specify, #00ff00 in this case.

In our hidden image example, different sections of the text was enclosed within a <span> and a different text highlight color was used. But this wasn’t done by hand - doing this manually would be a monumental task. I used a generator.


Go to this site and paste a chunk of text into the box. Don’t worry if the text you entered is of small length. It will be repeated if inadequate. Then enter the URL of the image you want to hide. Set the number of colors to 256 (128 is too less) and select a suitable text width.

Smaller sized images works better because the width of the output is limited to 220 characters. If your image has a horizontal pixel count of 220, each pixel will be replaced by one character. If the pixel count is more some information will be lost. In my example, the image was large and hence you could see pixelization.

Once you click on generate you will get a preview and also the code. Select the code and paste it on to your webpage.

Create pictures on Microsoft Excel
Hide files within other files with Plain Sight


Post a Comment

Popular Posts