An avalanche photodiode for detecting ultraviolet photons, said photodiode comprising: • a first semiconductor layer lowly doped according to a first conductivity type, n or p, • a second semiconductor layer lowly doped according to said first conductivity type and located on top of said first layer, • a third layer located above said second layer and configured to form a blocking junction to a layer therebelow in a reverse biased state of the diode, a surface of the diode above said third layer being configured to be exposed to photons to be detected, • at least said first and second layers (1, 2) are of SiC, • a fourth layer of SiC and doped according to a second conductivity type opposite to said first conductivity type is arranged above said second layer, the fourth layer extends all the way over said second layer forming said third layer and a pn-junction to said second layer in the area to be exposed to the photons to be detected, • a first electrode arranged in electrical contact with said first layer and • a second electrode above the fourth layer, arranged laterally outside said surface and next to an outer lateral border defining said surface, wherein an active region of a high electric field for avalanche multiplication of charge carriers by said photons in said second layer is created in operation of the diode by applying a voltage close to the breakdown voltage of the diode across said electrodes (6,7), the thickness of said fourth layer and the doping concentration thereof are adapted to obtain an effective surface charge density of said fourth layer in a region laterally outside the surface and next to the outer lateral border, so that an electric field strength substantially equal to a critical electric field strength of the diode at a pn- junction formed below said fourth layer laterally outside said surface and next to the outer lateral border upon application of the said voltage across said electrodes (6,7) is obtained, and an edge termination extension of the diode as of said lateral border is obtained by a reduction of said effective surface charge density in the direction laterally away from said surface, the edge terminal extension having at least one etched step (12, 13), a highly doped layer of SiC doped according to a first type of conductivity is provided between the first layer and the second layer, characterized in that said highly doped layer extends only under an active region of the device and not further than to a first etched step of the edge termination extension. • a first semiconductor layer lowly doped according to a first conductivity type, n or p, • a second semiconductor layer lowly doped according to said first conductivity type and located on top of said first layer, • a third layer located above said second layer and configured to form a blocking junction to a layer therebelow in a reverse biased state of the diode, a surface of the diode above said third layer being configured to be exposed to photons to be detected, • at least said first and second layers (1, 2) are of SiC, • a fourth layer of SiC and doped according to a second conductivity type opposite to said first conductivity type is arranged above said second layer, the fourth layer extends all the way over said second layer forming said third layer and a pn-junction to said second layer in the area to be exposed to the photons to be detected, • a first electrode arranged in electrical contact with said first layer and • a second electrode above the fourth layer, arranged laterally outside said surface and next to an outer lateral border defining said surface,