Deviance occurs when someone breaks an accepted code of behaviour. Deviant behaviour is not necessarily illegal and the code that has been broken is usually an unwritten code that everyone understands. It would be deviant, for example, to turn up at a funeral in a bright red suit, or to eat fish and chips in a school assembly. People would usually regard it as anti-social or abnormal behaviour.
It is possible to break the law without being deviant. Fly tipping (dumping rubbish in an unauthorised place) may be punishable by law, but very few people would regard it as deviant.
Deviance is socially defined. In other words, it is defined by how the people around you regard your behaviour. Walking through the high street with no clothes on would normally be regarded as deviant. Walking around naked in a nudist colony would be regarded as acceptable, since everyone around you has subscribed to the same code. Indeed if you were to walk around a nudist colony with your clothes on, you would find yourself being disapproved of.
As you will see from this example, deviance is very much to do with the social context.