"If" is written as a father giving advice to his son. The father is giving the boy suggestions for ways to behave in approaching life and other people so as to become an outstanding adult member of society.
The advice is delivered through a series of situations the father describes with a negative behavior or reaction contrasted with a more desirable course of action. "If you can keep your head when all about you are losing theirs and blaming it on you" - the father follows this pattern throughout the poem.
The son is encouraged to strive for the higher moral ground, to behave honorably regardless of what others may or may not do. "If you can talk with crowds and keep your virtue, or walk with Kings and not loose the common touch" - the father concludes by telling his son that success in following these examples will give him "the Earth and everything that's in it," including achievement of being "a Man" in the best and fullest sense.