In the effort to make 2D materials-based devices smaller, faster, and more efficient, it is important to control charge carrier at lengths approaching the nanometer scale. Traditional gating techniques based on capacitive coupling through a gate dielectric cannot generate strong and uniform electric fields at this scale due to divergence of the fields in dielectrics. This field divergence limits the gating strength, boundary sharpness, and pitch size of periodic structures, and restricts possible geometries of local gates (due to wire packaging), precluding certain device concepts, such as plasmonics and transformation optics based on metamaterials. Here we present a new gating concept based on a dielectric-free self-aligned electrolyte technique that allows spatially modulating charges with nanometer resolution. We employ a combination of a solid-polymer electrolyte gate and an ion-impenetrable e-beam-defined resist mask to locally create excess charges on top of the gated surface. Electrostatic simulations indicate high carrier density variations of $Delta n =10^{14}text{cm}^{-2}$ across a length of 10 nm at the mask boundaries on the surface of a 2D conductor, resulting in a sharp depletion region and a strong in-plane electric field of $6times10^8 text{Vm}^{-1}$ across the so-created junction. We apply this technique to the 2D material graphene to demonstrate the creation of tunable p-n junctions for optoelectronic applications. We also demonstrate the spatial versatility and self-aligned properties of this technique by introducing a novel graphene thermopile photodetector.