You shouldn't form an opinion on someone or something based purely on what you see on the surface, because usually after taking a deeper look, the person or thing will not be what you expected it to be.
When looking for something to read, people will often times only glance at the cover of a book before making a decision. Due to this, many books get overlooked merely due to the title or picture on the front of them being unappealing to the eye. However, if one were to open the book up and peer into its contents, they'd probably find that they were missing out on some interesting and valuable information. Hence, don't judge a book by its cover!
The phrase is also applied to people. How? Well, before getting to know someone, a person tends to first judge others based on their outward appearance, their nationality, or other external factors. It's a shame, though, because while a person might look rough on the outside, you can never truly know what they are like on the inside unless you 'open' them up and get to know them.
The phrase goes back to at least the mid-19th century, as seen in the newspaper Piqua Democrat, June 1867:
"Don't judge a book by its cover, see a man by his cloth, as there is often a good deal of solid worth and superior skill underneath a [???] jacket and yaller pants."
The print in the newspaper I was looking at was really small and hard to read, but even so, I tried quoting it as accurately as possible. Regardless, there was enough clarity to make out the phrase for sure.
* I was nervous about talking to a guy that had big muscles and tattoos, but he was way nicer than I thought he would be, so I guess you can't judge a book by its cover.
knowyourphrase.com - Meanings and Origins of Phrases and Idioms
Note: Did you know that the origins for many of the sayings you hear about are not really known or understood that well? A lot of the time, what you see on the page will be the more plausible theories for how an expression was born, but it's not a full confirmation, and shouldn't be seen as one.
The quotes, coming from old books, plays, newspapers, etc., are there to help the reader recognise how old some sayings are. I've tried to find the oldest written forms, but there is a possiblity that older citations exist and I missed them. If you'd like to inform me of an older written form of the phrase that dates further back, then feel free to contact me!
Phrases and Idioms
Once you're finished with this expression, don't forget that there are plenty of more phrases out there!