Styles Package Use Cases

Real-world examples of using the UMD Styles Library

About This Guide

This guide demonstrates practical implementations of the UMD Styles Library for creating consistent, accessible designs.

Common Use Cases

🚀 Use Case 1: Quick Start - Setting Up Styles

Initialize the UMD Styles Library in your project with all utilities.

Implementation
// 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();
Result

✓ UMD fonts loaded (Interstate, Crimson Pro, Barlow Condensed)

✓ CSS variables available (--color-red, --spacing-md, etc.)

✓ Reset styles applied

✓ Utility classes ready to use

📐 Use Case 2: Grid System Classes

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).

Available Grid Gap Classes
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
Available Grid Border Classes
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
Gap Values

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

Usage Example
<!-- Standard three-column grid -->
<div class="umd-layout-grid-gap-three">
  <div>Item 1</div>
  <div>Item 2</div>
  <div>Item 3</div>
</div>

📏 Use Case 3: Spacing Utility Classes

The library provides comprehensive spacing utilities for both horizontal containers (max-width with padding) and vertical spacing (margin-bottom).

Horizontal Container Classes
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
Vertical Spacing Classes
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
Usage Example
<!-- 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>

📝 Use Case 4: Form Field Classes

The library provides a complete set of form field classes for creating accessible, consistent forms.

Available Form Classes
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
Validation States

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

Usage Example
<!-- 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>

🎨 Use Case 5: Automatic Web Component Styling

All UMD web components receive automatic base styling from the styles package. No additional configuration needed!

How Automatic Styling Works
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
Components with Special Styling
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
Component List

Base Components (automatic show/hide):

  • alert-page, alert-site, banner-promo
  • All carousel variants (cards, image, multiple-image, people, thumbnail)
  • All hero variants (brand-video, expand, logo, minimal)
  • media-inline, media-gif, quote
  • pathway, pathway-highlight
  • person-bio, person-hero
  • slider-events, slider-events-feed

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

Benefits
<!-- 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>
✅ Best Practices
⚡ Performance Tips

Related Resources