Use something like this
int ledState;
void loop()
{
if (digitalRead(button) == 0)
{
ledState = ! ledState;
// the NOT operator (!) toggles ledState between true and false
digitalWrite(ledPin, ledState);
}
}
connect the button between the input pin and ground
set the input pin as
INPUT_PULLUP in setup()
You should debounce the button. You can google that to see different ways