In criminal law, "offence" is always the one correct term. A crime is an offence against the community and a breach of the law. For example, smoking in an enclosed workplace is an offence under the Health Act 2006. We could use "is a violation of", but usually only when we are trying to explain the term "offence" to someone who does not understand it.
When talking about rules, we tend to use "violation". For example, "Appearing in class in pyjamas is a violation of School Rule No. 321."