Skip to content
GitHub11 stars

Renders content according to whether a CSS media query matches.

This window is narrower than 1024 pixels wide. Resize it to see the text change.

<MediaQuery Query="(min-width: 1024px)" Context="wide">
    <p class="media-query-text">
        This window is <strong>@(wide ? "at least" : "narrower than")</strong> 1024 pixels wide. Resize it to see the text change.
    </p>
</MediaQuery>

MediaQuery watches a media query: its content renders with whether the query matches, again whenever that changes. Until the browser has answered, and while prerendering, DefaultMatches applies.

Anatomy

@using Blazix.Primitives

<MediaQuery Query="(prefers-reduced-motion: reduce)" Context="reduced">
    ...
</MediaQuery>

API Reference

MediaQuery

Doesn't render its own HTML element.

ParameterTypeDefault
Queryrequired string -
DefaultMatches bool false
MatchesChanged EventCallback<bool> -
ChildContent

The part's content.

RenderFragment<bool>? -