Offside happens when an attacking player crosses the blue line into the offensive zone before the puck does. Think of it like this. The puck has to go into the zone first, and then you can follow it in. If both of your skates cross that blue line before the puck, the referee blows the whistle and there is a faceoff outside the zone.
The tricky part is that it is your skates that matter, not your stick. As long as one of your skates is touching or behind the blue line when the puck crosses it, you are onside. Players will sometimes drag a skate on the line to stay onside while reaching forward with their stick.
Delayed offside is when a player is offside but the attacking team has not touched the puck yet. If all the attacking players clear the zone before anyone touches the puck, the play continues without a whistle.
