This is controlled by the 25th Amendment—
(a) at the death, resignation, or removal of the president, the VP becomes President
(b) if the office of VP is vacant, the president can appoint a new VP with the approval of Congress
(c) if the president declares he is unable to carry out his duties, the VP serves as Acting President until the President can resume his duties, and
(d) if the president is unable to make the declaration, the VP and a majority of the cabinet or the Congress can declare the president unable to serve and the VP will become Acting President.
If the 25th cannot be used, the Presidential Succession Act comes into play. In this case the VP is followed by the Speaker of the House, the president Pro Tempore of the Senate, and the cabinet departments in order of creation.