An image forming apparatus can detect a leading edge and a width of a recording medium with a simple structure so as to prevent erroneous recording. A carriage has a recording head to form the image by scanning the recording medium. A detector is provided in the carriage so as to detect a leading edge of the recording medium.