https://www.usconstitution.net/consttop_pvp.html
Constitutional Topic: Death of a Presidential Candidate
The Constitutional Topics pages at the USConstitution.net site are presented to delve deeper into topics than can be provided on the Glossary Page or in the FAQ pages. This Topic Page concerns the how the Constitution handles the death of a presidential candidate. This topic is handled in Article 2, Section 1, the 12th Amendment, and the 20th Amendment. The Topic Pages for Presidential Disability and the Electoral College are also of interest.
As morbid as it seems, one of the most common questions to be asked of this site is what happens if a presidential candidate dies? Though it does seem morbid, it is an important question. One of the most important features of a successful democracy is peaceful transition of power. By anticipating unfortunate but possible circumstances, the Constitution and U.S. law tries to ensure that the most powerful position in American politics has a contingency plan.
The answer is a complicated one, but very definitely defined - there are, in other words, bookends for the question. One bookend is the inauguration of the president and the vice president. Once the president-elect and the vice president-elect are sworn in, the line of succession kicks in.
Before the election
The other bookend is less solid - it is the election itself. When voters cast their votes in November, they are not actually casting votes for a specific person. Instead, they are casting votes for electors, persons chosen by the candidates' parties to attend a gathering of all electors in each state capital, where they cast the votes that officially elect a president.
If a presidential candidate dies after the party convention and before the election, particularly before ballots are printed, the party can select a new person to represent the party on the ticket. The choice will depend on the party's own rules. As the election nears, the situation gets more sticky, because elections take time to plan. Practically speaking, ballots must be printed, and if there is not enough time to do that, the election can still go on, though with the name of a now-dead candidate on the ballot - state law should dictate how such ballots would be handled. Vermont law (17 VSC 2475), for example, states that new ballots will be printed - but if the death occurs near enough to Election Day, it may not be possible to print new ballots.
While near-election death might be a problem for a Senator or a judge, where the voters are electing a specific person, in the case of the presidential election, the buffer of the electoral college would allow the election to continue.
con't