Erections happen in stages with the penis, starting soft and becoming gradually harder until it stands outward or upward. This happens most often in response to sexual arousal but can sometimes occur for no reason at all (particularly during puberty and the teen years). Erections can go away after ejaculation or on their own.
Source: Verywell Health