Are cheats legal in GTA 5?

Are cheat codes legal in GTA 5? You can't use cheat codes in online, but it only works in story mode . If you try it in online, then it won't work.