Skip to content

Media Utilities

This component defines CSS variables for responsive design breakpoints in Metro UI.

The media component establishes CSS variables that correspond to the standard breakpoints used throughout the Metro UI framework. These variables are used for creating responsive layouts and components that adapt to different screen sizes.

The file defines the following CSS variables for media breakpoints:

VariableDescription
--media-fsFullscreen breakpoint
--media-xsExtra small screens breakpoint
--media-smSmall screens breakpoint
--media-ldLow-density screens breakpoint
--media-mdMedium screens breakpoint
--media-lgLarge screens breakpoint
--media-xlExtra large screens breakpoint
--media-xxlDouble extra large screens breakpoint
--media-xxxlTriple extra large screens breakpoint

These variables are derived from the corresponding LESS variables defined in the ../include/vars file.

These CSS variables can be used in your custom CSS to create responsive designs that align with Metro UI’s breakpoints:

@media (min-width: var(--media-md)) {
/* Styles that apply to medium screens and above */
.my-element {
display: flex;
}
}
@media (max-width: calc(var(--media-md) - 1px)) {
/* Styles that apply to screens smaller than medium */
.my-element {
display: block;
}
}

Metro UI uses these breakpoints internally for its responsive utility classes. For example, classes like .d-none-md (hide on medium screens and above) or .d-flex-lg (display as flex on large screens and above) rely on these breakpoint variables.

The breakpoints follow this hierarchy from smallest to largest:

  1. --media-fs (Fullscreen)
  2. --media-xs (Extra Small)
  3. --media-sm (Small)
  4. --media-ld (Low Density)
  5. --media-md (Medium)
  6. --media-lg (Large)
  7. --media-xl (Extra Large)
  8. --media-xxl (Double Extra Large)
  9. --media-xxxl (Triple Extra Large)
  1. Consistent Breakpoints: Use these variables instead of hardcoded pixel values to ensure consistency with Metro UI’s responsive behavior.

  2. Mobile-First Approach: Start with styles for the smallest screens and then use min-width media queries with these variables to add styles for larger screens.

  3. Avoid Breakpoint Proliferation: Stick to these standard breakpoints rather than creating custom ones to maintain consistency across your application.

  4. Testing: Always test your responsive designs at each of these breakpoints to ensure proper layout and functionality.

.my-grid {
display: grid;
grid-template-columns: 1fr;
gap: 1rem;
}
@media (min-width: var(--media-sm)) {
.my-grid {
grid-template-columns: repeat(2, 1fr);
}
}
@media (min-width: var(--media-md)) {
.my-grid {
grid-template-columns: repeat(3, 1fr);
}
}
@media (min-width: var(--media-lg)) {
.my-grid {
grid-template-columns: repeat(4, 1fr);
}
}

This example creates a responsive grid that displays 1 column on mobile, 2 columns on small screens, 3 columns on medium screens, and 4 columns on large screens.