You have landed a new position, and it is time to resign from your current job. If you do not have significant problems with your current company, you may deem it important to leave on good terms with your ex-coworkers/company. Perhaps you would want to do business with them or even return to the company later in your career.
Without giving every dirty detail of why you are leaving/taking a new position, let your employer know why you are moving on. People appreciate honesty. Leaving your ex-boss in the dark as to why you left only causes confusion and could breed resentment if not handled correctly. Reasonable people respect reasonable reasons for leaving (i.e., higher pay, a shorter commute, better benefits). Anyone worth staying on good terms with will understand and send you off with well-wishes.
Express your gratitude for the time you have spent in that position. If you are especially thankful for anything specific, mention it! Let your coworkers know you are leaving before you go. Make sure to say goodbye to them before you walk out of the office for the last time and if you appreciated working with them, let them know. Stay connected and check in with those you value—you may be able to help each other out in the future.
As soon as you know you are leaving, let your employer know. It gives them as much time as possible to find your replacement. This way, you can help them prepare for the transition and possibly help to train the new employee. The last thing you want to do is make your employer feel like you left them high and dry with little warning. The more time you give them, the better.
Get excited about your new position! You deserve it. Just make sure to leave your current job with respect—you never know how you could benefit each other!