Material Design responsive grid system with flexible SCSS mixins and CSS classes for creating adaptive layouts across desktop, tablet, and phone devices
Configuration variables that define breakpoints, columns, spacing, and default behaviors across device types. These variables can be customized before importing the library to create custom grid configurations.
Variables that define the responsive breakpoints for different device types.
/**
* Responsive breakpoints map defining screen size thresholds
* Keys correspond to device types, values are minimum widths
* Phone breakpoint is 0px (applies to all sizes until tablet)
*/
$breakpoints: (
desktop: 840px,
tablet: 600px,
phone: 0px,
) !default;Usage Example:
// Customize breakpoints before importing
$breakpoints: (
desktop: 1024px,
tablet: 768px,
phone: 0px,
);
@use "@material/layout-grid" with (
$breakpoints: $breakpoints
);Variables that define the number of columns available at each device type.
/**
* Column count map defining number of columns per device type
* Desktop has 12 columns, tablet has 8, phone has 4
*/
$columns: (
desktop: 12,
tablet: 8,
phone: 4,
) !default;Usage Example:
// Create a 16-column desktop layout
$columns: (
desktop: 16,
tablet: 8,
phone: 4,
);
@use "@material/layout-grid" with (
$columns: $columns
);Variables that control margins and gutters for different device types.
/**
* Default margin map defining space between grid edge and first cell
* Applied to the outer grid container on each device type
*/
$default-margin: (
desktop: 24px,
tablet: 16px,
phone: 16px,
) !default;
/**
* Default gutter map defining space between adjacent cells
* Applied between cells within the grid on each device type
*/
$default-gutter: (
desktop: 24px,
tablet: 16px,
phone: 16px,
) !default;Usage Examples:
// Increase desktop spacing
$default-margin: (
desktop: 32px,
tablet: 16px,
phone: 16px,
);
$default-gutter: (
desktop: 32px,
tablet: 16px,
phone: 16px,
);
@use "@material/layout-grid" with (
$default-margin: $default-margin,
$default-gutter: $default-gutter
);
// Tighter mobile spacing
$tight-spacing: (
desktop: 24px,
tablet: 12px,
phone: 8px,
);
@use "@material/layout-grid" with (
$default-margin: $tight-spacing,
$default-gutter: $tight-spacing
);Variables that define fixed column widths when using the fixed-width grid modifier.
/**
* Column width map for fixed-width grid layouts
* Used when .mdc-layout-grid--fixed-column-width class is applied
* Default is 72px for all device types
*/
$column-width: (
desktop: 72px,
tablet: 72px,
phone: 72px,
) !default;Usage Example:
// Wider columns for desktop
$column-width: (
desktop: 80px,
tablet: 72px,
phone: 60px,
);
@use "@material/layout-grid" with (
$column-width: $column-width
);Variables that control default grid cell behavior.
/**
* Default column span for grid cells when no span class is specified
* Cells without explicit span classes will span this many columns
*/
$default-column-span: 4 !default;
/**
* Maximum width constraint for the entire grid
* Set to null for no maximum width constraint
* When set, grid will not exceed this width regardless of screen size
*/
$max-width: null !default;Usage Examples:
// Make cells span 3 columns by default instead of 4
@use "@material/layout-grid" with (
$default-column-span: 3
);
// Add maximum width constraint
@use "@material/layout-grid" with (
$max-width: 1200px
);
// Combine multiple customizations
@use "@material/layout-grid" with (
$default-column-span: 6,
$max-width: 1440px,
$default-margin: (
desktop: 32px,
tablet: 24px,
phone: 16px,
)
);Override all variables for a completely custom grid system:
// Define custom configuration
$custom-breakpoints: (
large: 1200px,
medium: 768px,
small: 0px,
);
$custom-columns: (
large: 16,
medium: 12,
small: 6,
);
$custom-spacing: (
large: 40px,
medium: 32px,
small: 20px,
);
// Import with custom configuration
@use "@material/layout-grid" with (
$breakpoints: $custom-breakpoints,
$columns: $custom-columns,
$default-margin: $custom-spacing,
$default-gutter: $custom-spacing,
$max-width: 1600px
);Override only specific aspects while keeping defaults:
// Only customize spacing, keep default breakpoints and columns
@use "@material/layout-grid" with (
$default-margin: (
desktop: 48px,
tablet: 32px,
phone: 24px,
),
$default-gutter: (
desktop: 32px,
tablet: 24px,
phone: 16px,
)
);Create different configurations for different themes:
// Tight theme
$tight-theme: (
margin: (desktop: 16px, tablet: 12px, phone: 8px),
gutter: (desktop: 16px, tablet: 12px, phone: 8px),
max-width: 1024px,
);
// Spacious theme
$spacious-theme: (
margin: (desktop: 48px, tablet: 32px, phone: 24px),
gutter: (desktop: 40px, tablet: 32px, phone: 24px),
max-width: 1600px,
);
// Apply theme
@use "@material/layout-grid" with (
$default-margin: map.get($spacious-theme, margin),
$default-gutter: map.get($spacious-theme, gutter),
$max-width: map.get($spacious-theme, max-width)
);Variables have dependencies and should be configured consistently:
$breakpoints keys must match $columns keys$default-margin keys must match device types in other maps$default-gutter keys must match device types in other maps$column-width keys must match device types in other maps$default-column-span should be ≤ smallest value in $columns maptessl i tessl/npm-material--layout-grid@13.0.0