By law, a visitor is able to get married while you are in the U.S as long as you have a valid ESTA or other visa, and your return home at the end of your required term. However, if you are not from one of the valid countries who are able to apply for an ESTA, then you may find that convincing the US consulate that all you want to do is get married and not stay for longer than your stay can be difficult. There has been a very long list throughout history of people who have attempted to get married abroad and then apply for an adjustment of status in order to cut down the lengthy process of applying for a fiancé or marriage visa from overseas. Even if you do get the right visa and you make your trip, the border official is the next step in order to get through to the country, and if they do not believe your intentions then they may even exercise expedited removal.
In order to reduce any risks or problems of getting married in the US as a non-citizen, it is better to apply for a fiancé visa, but make sure that you do this far in advance of the set date for the wedding. This can make the visa process longer, but it may also lead to an easier entry. This will also make it easier for you if you change your mind and decide to settle in the U.S. after marriage giving you legal right to apply for a green card.
If you want to get married and then apply for a U.S. green card
If your intentions are to get married and then apply for a U.S. green card after entering the country with a visitor visa, then this is seen as a form of visa fraud, and can ultimately lead to removal proceedings rather than being granted a U.S. green card.
It is important to recognise that each state in the U.S. has different marriage laws, so it is important that you first check with the local county clerk or marriage official that the wedding that you want to carry out it wholly legal in that state. It is also important to check that you have all of the right documentation that is necessary so that your marriage is recognised in your home country. The different laws on marriage in the different states can cover age, blood tests, waiting periods, same-sex marriage and cousin marriage, so it is important to know exactly what is required and legal in the state before you get married.