Despite its compactness, the human eye can easily focus on different distances by adjusting the shape of its lens with the help of ciliary muscles. In contrast, traditional man-made optical systems achieve focusing by physical displacement of the lenses used. But in recent years, advances in miniaturization technology have led to optical systems that no longer require complicated mechanical systems to tune and adjust optical performance. These systems have found wide use in photonics, displays and biomedical systems. They are either based on arrays of microlenses with fixed focal lengths, or use external control to adjust the microlens focal length. An intriguing example is the tunable liquid lens, where electrowetting or external pressure manipulates the shape of a liquid droplet and thereby adjusts its optical properties. Here we demonstrate a liquid lens system that allows for autonomous focusing. The central component is a stimuli-responsive hydrogel integrated into a microfluidic system and serving as the container for a liquid droplet, with the hydrogel simultaneously sensing the presence of stimuli and actuating adjustments to the shape--and hence focal length--of the droplet. By working at the micrometre scale where ionic diffusion and surface tension scale favourably, we can use pinned liquid-liquid interfaces to obtain stable devices and realize response times of ten to a few tens of seconds. The microlenses, which can have a focal length ranging from -infinity to +infinity (divergent and convergent), are also readily integrated into arrays that may find use in applications such as sensing, medical diagnostics and lab-on-a-chip technologies.