The client:media directive in Astro loads components only when a specified media query matches the user's screen size or device features. When the page loads, it checks the media query. If it matches, the component loads and becomes interactive. If not, the component is not loaded, saving resources. The directive listens for changes in the media query, such as window resizing, and loads or unloads the component dynamically. This allows responsive interactivity, where components appear only on certain screen sizes. For example, a component with client:media="(min-width: 600px)" loads only on screens 600 pixels wide or larger. If the user resizes the window smaller, the component unloads, and if resized larger again, it reloads. This behavior improves performance and user experience by adapting to device capabilities.