Real-world examples of using the UMD Styles Library
This guide demonstrates practical implementations of the UMD Styles Library for creating consistent, accessible designs.
Initialize the UMD Styles Library in your project with all utilities.
// styles-init.js
import { typography, reset, reset as resetStyles } from '@universityofmaryland/web-styles-library';
async function initializeStyles() {
// Load UMD fonts
const fontStyles = document.createElement('style');
fontStyles.innerHTML = typography.fontFace.base64fonts;
document.head.appendChild(fontStyles);
// Apply reset styles
const resetElement = document.createElement('style');
resetElement.innerHTML = await resetStyles.toString();
document.head.appendChild(resetElement);
// Pre-render critical CSS (optional)
const { preRenderCss } = await import('@universityofmaryland/web-styles-library');
const criticalCss = await preRenderCss();
const criticalElement = document.createElement('style');
criticalElement.innerHTML = criticalCss;
document.head.appendChild(criticalElement);
}
// Initialize on import
initializeStyles();
✓ UMD fonts loaded (Interstate, Crimson Pro, Barlow Condensed)
✓ CSS variables available (--color-red, --spacing-md, etc.)
✓ Reset styles applied
✓ Utility classes ready to use
The UMD Styles Library provides two types of grid systems: Grid with Gaps (for spacing between items) and Grid with Borders (for table-like layouts).
Class Name | Columns | Description | Responsive Behavior |
---|---|---|---|
umd-layout-grid-gap-two |
2 | Two-column grid with standard gaps | Stacks to 1 column on mobile |
umd-layout-grid-gap-three |
3 | Three-column grid with standard gaps | Mobile: 1 col, Tablet: 2 cols |
umd-layout-grid-gap-three-large |
3 | Three-column grid with larger gaps on desktop | Mobile: 1 col, Tablet: 2 cols, Desktop: larger gaps |
umd-layout-grid-gap-four |
4 | Four-column grid with standard gaps | Mobile: 1 col, Tablet: 2 cols |
umd-layout-grid-gap-four-centered |
4 | Four-column grid where first item spans 2 columns | Mobile: 1 col, Tablet: 2 cols |
umd-layout-grid-gap-stacked |
1 | Single column with consistent vertical spacing | Always single column |
Class Name | Columns | Description | Border Style |
---|---|---|---|
umd-layout-grid-border-two |
2 | Two-column grid with borders | 1px solid #E0E0E0 |
umd-layout-grid-border-three |
3 | Three-column grid with borders | 1px solid #E0E0E0 |
umd-layout-grid-border-four |
4 | Four-column grid with borders | 1px solid #E0E0E0 |
Standard Gap: 16px (mobile), 24px (tablet), 32px (desktop)
Large Gap: 16px (mobile), 24px (tablet), 48px (desktop), 64px (high-def)
Stacked Gap: 32px vertical spacing between items
<!-- Standard three-column grid -->
<div class="umd-layout-grid-gap-three">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
The library provides comprehensive spacing utilities for both horizontal containers (max-width with padding) and vertical spacing (margin-bottom).
Class Name | Max Width | Padding | Use Case |
---|---|---|---|
umd-layout-space-horizontal-full |
100% | 16px (mobile), 40px (tablet), 64px (desktop) | Full-width sections |
umd-layout-space-horizontal-larger |
1400px | Same as above | Wide content areas |
umd-layout-space-horizontal-large |
1200px | Same as above | Standard content width |
umd-layout-space-horizontal-normal |
1000px | Same as above | Reading width |
umd-layout-space-horizontal-small |
800px | Same as above | Narrow content/forms |
umd-layout-space-horizontal-smallest |
600px | Same as above | Very narrow content |
Class Name | Mobile Margin | Tablet Margin | Desktop Margin | Use Case |
---|---|---|---|---|
umd-layout-space-vertical-landing |
48px | 96px | 120px | Major landing page sections |
umd-layout-space-vertical-landing-child |
24px | 32px | 40px | Elements within landing sections |
umd-layout-space-vertical-interior |
48px | 48px | 96px | Interior page sections |
umd-layout-space-vertical-interior-child |
24px | 24px | 24px | Elements within interior sections |
umd-layout-space-vertical-headline-large |
8px | 8px | 16px | After large headlines |
umd-layout-space-vertical-headline-medium |
8px | 8px | 8px | After medium headlines |
<!-- Container with reading width -->
<div class="umd-layout-space-horizontal-normal">
<h1 class="umd-layout-space-vertical-headline-large">Page Title</h1>
<p>Content with optimal reading width and proper spacing.</p>
</div>
The library provides a complete set of form field classes for creating accessible, consistent forms.
Class Name | Element Type | Description | Special Features |
---|---|---|---|
umd-field-input |
input | Base input field styling | Supports aria-invalid for validation states |
umd-field-input-date-wrapper |
div (wrapper) | Wrapper for date inputs | Custom calendar icon |
umd-field-input-time-wrapper |
div (wrapper) | Wrapper for time inputs | Custom clock icon |
umd-field-select-wrapper |
div (wrapper) | Wrapper for select dropdowns | Custom dropdown arrow |
umd-field-select |
select | Styled select dropdown | Consistent cross-browser styling |
umd-field-textarea |
textarea | Styled textarea | Auto-resize option |
umd-field-checkbox-wrapper |
div (wrapper) | Wrapper for checkbox + label | Custom checkbox styling |
umd-field-radio-wrapper |
div (wrapper) | Wrapper for radio + label | Custom radio styling |
umd-field-file-wrapper |
div (wrapper) | Wrapper for file inputs | Custom file button |
umd-field-file |
input[type="file"] | Hidden file input | Visually hidden, label styled |
umd-field-file-label |
span | Visual file button | Shows selected filename |
umd-field-set |
fieldset | Groups related form fields | Proper spacing and borders |
umd-field-set-item |
div | Individual field container | Consistent spacing between fields |
Valid State: Add aria-invalid="false"
to show green border
Invalid State: Add aria-invalid="true"
to show red border
Disabled State: Add disabled
attribute for disabled styling
<!-- Text input with validation -->
<div class="umd-field-set-item">
<label for="email">Email</label>
<input type="email" id="email" class="umd-field-input" aria-invalid="false">
</div>
<!-- Date input with wrapper -->
<div class="umd-field-input-date-wrapper">
<input type="date" class="umd-field-input-date">
</div>
All UMD web components receive automatic base styling from the styles package. No additional configuration needed!
Feature | CSS Applied | Purpose |
---|---|---|
Hidden Until Defined | :not(:defined) { display: none; } |
Prevents flash of unstyled content |
Block Display | :defined { display: block; } |
Standard block-level behavior |
Container Queries | :defined { container-type: inline-size; } |
Enables responsive component design |
Component | Special Styling | Description |
---|---|---|
umd-element-accordion-item |
Auto spacing: margin-top: 4px |
Consistent spacing between accordion items |
umd-element-brand-logo-animation |
Absolute positioning, z-index: 9 | Proper logo animation placement |
umd-element-card[data-display="list"] |
Auto spacing: margin-top: 16px |
Consistent list card spacing |
umd-element-navigation-sticky |
z-index: 9999 | Ensures navigation stays on top |
umd-element-scroll-top[data-layout-fixed="true"] |
Fixed positioning, responsive sizing | Scroll to top button placement |
umd-element-social-sharing[data-layout-fixed="true"] |
Fixed positioning on desktop | Social sharing sidebar |
Base Components (automatic show/hide):
Feed Components: umd-feed-events, umd-feed-news
Navigation Components: nav-item, nav-drawer, navigation-header, navigation-sticky
Layout Components: footer, breadcrumb, call-to-action, tabs, section-intro
<!-- Just use the component - styling is automatic! -->
<umd-element-hero data-theme="dark">
<!-- Component is hidden until JavaScript loads -->
<!-- Then displays as block with container queries enabled -->
</umd-element-hero>