# MediaQuery
**Also known as:** Breakpoint, Responsive
## Description
MediaQuery renders content by what the browser's matchMedia reports: the layout decisions CSS cannot express, such as rendering a different component or none at all. It offers the predefined screen queries, built from the live theme breakpoints, and any custom media query, and reports its state to the page as a bindable value.
## Parameters
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| CascadingTheme | `BitTheme?` | null | The theme of an enclosing BitThemeProvider. Only its breakpoints are read, to resolve a ScreenQuery; they win over the --bit-bp-* CSS variables. |
| ChildContent | `RenderFragment?` | null | The content of the element to render if the specified query is matched. |
| DefaultMatched | `bool` | false | The matched state to render with until the browser answers the query, to avoid a flash of the wrong content while prerendering. Ignored when IsMatched is bound. |
| Element | `string?` | null | The custom html element used for the root node (div by default): a span where only inline content is allowed, an li in a list. A void element or an invalid name falls back to div. |
| IsMatched | `bool` | false | The current matched state of the query. An output: the browser owns it, so bind it rather than setting it one way, which freezes it; seed it with DefaultMatched. (two-way bound) |
| Matched | `RenderFragment?` | null | The content to be rendered if the provided query is matched (an alias for ChildContent). |
| NotMatched | `RenderFragment?` | null | The content to be rendered if the provided query is not matched. |
| NoWrapper | `bool` | false | Renders the active content without the wrapping root element, so what describes an element (class, style, id, dir, aria-label, ...) is ignored and the focus is not kept across a flip. See Element for when only the div is in the way. |
| OnChange | `EventCallback<bool>` | | The callback for every change of the matched state, also called once with the first answer of the browser. |
| Query | `string?` | null | The custom media query to be matched: any valid CSS media query, including the features other than the width, with or without a leading @media. Takes precedence over ScreenQuery. |
| ScreenQuery | `BitScreenQuery?` | null | The predefined screen query to be matched, built from the live theme breakpoints (the --bit-bp-* CSS variables). |
| Template | `RenderFragment<bool>?` | null | The content for both states, receiving the matched state. It is updated rather than rebuilt when the query flips, so the state inside it survives. Takes precedence over Matched, ChildContent and NotMatched. |
| AriaLabel | `string?` | null | Gets or sets the accessible label for the component, used by assistive technologies. |
| Class | `string?` | null | Gets or sets the CSS class name(s) to apply to the rendered element. |
| Dir | `BitDir?` | null | Gets or sets the text directionality for the component's content. |
| Disabled | `bool` | false | Gets or sets a value indicating whether the component is disabled and cannot respond to user interaction. |
| ForceAnimation | `bool` | false | Gets or sets a value indicating whether the component's animations play at their full duration even when reduced motion is requested. |
| HtmlAttributes | `Dictionary<string, object>` | new Dictionary<string, object>() | Captures additional HTML attributes to be applied to the rendered element, in addition to the component's parameters. An attribute written on the component wins over an entry of the same name. |
| Id | `string?` | null | Gets or sets the unique identifier for the component's root element. |
| Style | `string?` | null | Gets or sets the CSS style string to apply to the rendered element. |
| TabIndex | `string?` | null | Gets or sets the tab order index for the component when navigating with the keyboard. |
| Visibility | `BitVisibility` | BitVisibility.Visible | Gets or sets the visibility state (visible, hidden, or collapsed) of the component. |
## Public Members
| Name | Type | Default Value | Description |
| :--- | :--- | :------------ | :---------- |
| UniqueId | `Guid` | Guid.NewGuid() | Gets the readonly unique identifier for the component's root element, assigned when the component instance is constructed. |
| RootElement | `ElementReference` | | Gets the reference to the root HTML element associated with this component. |
## Enums
### BitScreenQuery Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Xs | 0 | Extra small query: [@media screen and (max-width: 599.98px)] |
| Sm | 1 | Small query: [@media screen and (min-width: 600px) and (max-width: 959.98px)] |
| Md | 2 | Medium query: [@media screen and (min-width: 960px) and (max-width: 1279.98px)] |
| Lg | 3 | Large query: [@media screen and (min-width: 1280px) and (max-width: 1919.98px)] |
| Xl | 4 | Extra large query: [@media screen and (min-width: 1920px) and (max-width: 2559.98px)] |
| Xxl | 5 | Extra extra large query: [@media screen and (min-width: 2560px)] |
| LtSm | 6 | Less than small query: [@media screen and (max-width: 599.98px)] |
| LtMd | 7 | Less than medium query: [@media screen and (max-width: 959.98px)] |
| LtLg | 8 | Less than large query: [@media screen and (max-width: 1279.98px)] |
| LtXl | 9 | Less than extra large query: [@media screen and (max-width: 1919.98px)] |
| LtXxl | 10 | Less than extra extra large query: [@media screen and (max-width: 2559.98px)] |
| GtXs | 11 | Greater than extra small query: [@media screen and (min-width: 600px)] |
| GtSm | 12 | Greater than small query: [@media screen and (min-width: 960px)] |
| GtMd | 13 | Greater than medium query: [@media screen and (min-width: 1280px)] |
| GtLg | 14 | Greater than large query: [@media screen and (min-width: 1920px)] |
| GtXl | 15 | Greater than extra large query: [@media screen and (min-width: 2560px)] |
| SmToMd | 16 | Small through medium query: [@media screen and (min-width: 600px) and (max-width: 1279.98px)] |
| SmToLg | 17 | Small through large query: [@media screen and (min-width: 600px) and (max-width: 1919.98px)] |
| SmToXl | 18 | Small through extra large query: [@media screen and (min-width: 600px) and (max-width: 2559.98px)] |
| MdToLg | 19 | Medium through large query: [@media screen and (min-width: 960px) and (max-width: 1919.98px)] |
| MdToXl | 20 | Medium through extra large query: [@media screen and (min-width: 960px) and (max-width: 2559.98px)] |
| LgToXl | 21 | Large through extra large query: [@media screen and (min-width: 1280px) and (max-width: 2559.98px)] |
### BitVisibility Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Visible | 0 | The content of the component is visible. |
| Hidden | 1 | The content of the component is hidden, but the space it takes on the page remains (visibility:hidden). |
| Collapsed | 2 | The component is hidden (display:none). |
### BitDir Enum
| Name | Value | Description |
| :--- | :--- | :---------- |
| Ltr | 0 | Ltr (left to right) is to be used for languages that are written from the left to the right (like English). |
| Rtl | 1 | Rtl (right to left) is to be used for languages that are written from the right to the left (like Arabic). |
| Auto | 2 | Auto lets the user agent decide. It uses a basic algorithm as it parses the characters inside the element until it finds a character with a strong directionality, then applies that directionality to the whole element. |
## CSS Variables
Public CSS custom properties read off the component's root. Set one on `:root` to restyle every instance, on any ancestor to restyle the ones inside it, or on the `Style` of one instance to restyle it and every instance nested inside it, which inherits the value too - a parameter changes one alone, as does the real CSS property on its `Style` / `Styles` when that property does not inherit (`opacity`); an inherited one (`color`, `font-family`) reaches the nested instances that do not set it themselves.
| Name | Default Value | Description |
| :--- | :------------ | :---------- |
| `--bit-bp-xs` | 0 | The start of the Xs band, which a ScreenQuery is built from. |
| `--bit-bp-sm` | 600px | The start of the Sm band, which a ScreenQuery is built from. |
| `--bit-bp-md` | 960px | The start of the Md band, which a ScreenQuery is built from. |
| `--bit-bp-lg` | 1280px | The start of the Lg band, which a ScreenQuery is built from. |
| `--bit-bp-xl` | 1920px | The start of the Xl band, which a ScreenQuery is built from. |
| `--bit-bp-xxl` | 2560px | The start of the Xxl band, which a ScreenQuery is built from. |
## Examples
\n**Basic**:
```razor
The screen is wider than the Sm band (GtSm).
The screen is narrower than the Md band (LtMd).
```
\n**Screen queries**:
```razor
This is Xs (Extra Small).
This is Sm (Small).
This is Md (Medium).
This is Lg (Large).
This is Xl (Extra Large).
This is Xxl (Extra Extra Large).
This is LtSm (Less Than Small).
This is LtMd (Less Than Medium).
This is LtLg (Less Than Large).
This is LtXl (Less Than Extra Large).
This is LtXxl (Less Than Extra Extra Large).
This is GtXs (Greater Than Extra Small).
This is GtSm (Greater Than Small).
This is GtMd (Greater Than Medium).
This is GtLg (Greater Than Large).
This is GtXl (Greater Than Extra Large).
This is SmToMd (Small through Medium).
This is SmToLg (Small through Large).
This is SmToXl (Small through Extra Large).
This is MdToLg (Medium through Large).
This is MdToXl (Medium through Extra Large).
This is LgToXl (Large through Extra Large).
```
\n**Matched & NotMatched**:
```razor
```
\n**Template**:
```razor
```
\n**Custom query**:
```razor
The width is between 400px and 700px.
The width is outside 400px to 700px.
The screen is in landscape orientation.
The screen is in portrait orientation.
The system prefers a dark color scheme.
The system prefers a light color scheme.
The primary pointer is precise (a mouse).
The primary pointer is coarse (a finger) or absent.
Reduced motion is requested.
Reduced motion is not requested.
```
\n**Theme breakpoints**:
```razor
Md is matched.
Md is not matched.
Md is matched.
Md is not matched.
Md is matched.
Md is not matched.
```
```csharp
private readonly BitTheme breakpointsTheme = new()
{
Layout = { Breakpoints = { Md = "700px", Lg = "900px" } }
};
```
\n**Element & NoWrapper**:
```razor
Wide content, rendered before the query is answered too.
Narrow content.
```
\n**Binding & OnChange**:
```razor
A button driven by the bound value
```
```csharp
private int changeCount;
private bool isSmallScreen;
private void HandleOnChange(bool value)
{
changeCount++;
}
```
\n**Accessibility**:
```razor
Pay now
View cart
```
\n**Cascading parameters**:
```razor
```
```csharp
private readonly BitMediaQueryParams[] mediaQueryParams =
[
new()
{
ScreenQuery = BitScreenQuery.GtSm,
Element = "span",
}
];
```
\n**Style & Class**:
```razor
Styled through the Style parameter (GtXs).
Styled through the Style parameter, not matched (GtXs).
Classed through the Class parameter (GtXs).
Classed through the Class parameter, not matched (GtXs).
```
\n**RTL**:
```razor
این محتوا در صفحههای بزرگتر از Xs نمایش داده میشود.
عرض صفحه کمتر از حد GtXs است.
```
Bands:
Less than:
Greater than:
Spans:
Document breakpoints (960px to 1279.98px):
BitThemeProvider (700px to 899.98px):
CSS variables (1100px to 1499.98px):
Your order ships
The screen is @(isSmallScreen ? "small" : "wide") (LtMd). OnChange calls: @changeCount