Hexagonal boron nitride (hBN)-long-known as a thermally stable ceramic-is now available as atomically smooth, single-crystalline flakes, revolutionizing its use in optoelectronics. For nanophotonics, these flakes offer strong nonlinearities, hyperbolic dispersion, and single-photon emission, providing unique properties for optical and quantum-optical applications. For nanoelectronics, their pristine surfaces, chemical stability, and wide bandgap have made them the key substrate, encapsulant, and gate dielectric for two-dimensional electronic devices. However, while exploring these advantages, researchers have been restricted to flat flakes or those patterned with basic slits and holes, severely limiting advanced architectures. If freely varying flake profiles were possible, the hBN structure would present a powerful design parameter to further manipulate the flow of photons, electrons, and excitons in next-generation devices. Here, we demonstrate freeform nanostructuring of hBN by combining thermal scanning-probe lithography and reactive-ion etching to shape flakes with surprising fidelity. We leverage sub-nanometer height control and high spatial resolution to produce previously unattainable flake structures for a broad range of optoelectronic applications. For photonics, we fabricate microelements and show the straightforward transfer and integration of such elements by placing a spherical hBN microlens between two planar mirrors to obtain a stable, high-quality optical microcavity. We then decrease the patterning length scale to introduce Fourier surfaces for electrons, creating sophisticated, high-resolution landscapes in hBN, offering new possibilities for strain and band-structure engineering. These capabilities can advance the discovery and exploitation of emerging phenomena in hyperbolic metamaterials, polaritonics, twistronics, quantum materials, and 2D optoelectronic devices.