Skip to main content

CSS Snippet Library: Copy-Paste Ready

A curated collection of production-ready CSS snippets for common patterns. All use CSS variables — drop your :root tokens in and they work immediately.

1. Navigation Patterns

Glassmorphism Sticky Nav

.site-nav {
position: sticky;
top: 0;
z-index: 100;
display: flex;
align-items: center;
justify-content: space-between;
padding: 1rem 2rem;
background: rgba(15, 15, 15, 0.8);
backdrop-filter: blur(16px);
-webkit-backdrop-filter: blur(16px);
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.nav__links { display: flex; gap: 2rem; list-style: none; }
.nav__links a { opacity: 0.75; transition: opacity 0.2s; }
.nav__links a:hover { opacity: 1; }

Mobile Hamburger (CSS Only)

.nav-toggle { display: none; }
.hamburger { display: none; cursor: pointer; flex-direction: column; gap: 5px; }
.hamburger span { display: block; width: 24px; height: 2px; background: var(--color-text); transition: all 0.3s; }

@media (max-width: 768px) {
.hamburger { display: flex; }
.nav__links { display: none; flex-direction: column; position: absolute; top: 100%; left: 0; right: 0; background: var(--color-surface); padding: 1rem 2rem; }
.nav-toggle:checked ~ .nav__links { display: flex; }
}

2. Hero Patterns

Full-Screen Hero with Overlay

.hero {
position: relative;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
background: linear-gradient(rgba(0,0,0,0.55), rgba(0,0,0,0.55)),
url(var(--hero-image, '')) center/cover no-repeat;
color: white;
padding: 2rem;
}
.hero__content { max-width: 700px; }
.hero__title { font-size: var(--text-hero, clamp(2.5rem, 6vw, 5rem)); font-weight: 800; line-height: 1.1; }
.hero__subtitle { margin-top: 1rem; font-size: 1.25rem; opacity: 0.85; }
.hero__cta { margin-top: 2.5rem; display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }

Gradient Hero (No Image)

.hero--gradient {
background: linear-gradient(135deg,
var(--color-bg, #0f0f0f) 0%,
hsl(250, 60%, 15%) 50%,
var(--color-bg, #0f0f0f) 100%
);
}

3. Card Patterns

Standard Card

.card {
background: var(--color-surface, #1c1c1e);
border-radius: var(--radius-md, 8px);
padding: var(--space-8, 2rem);
border: 1px solid rgba(255,255,255,0.06);
box-shadow: var(--shadow-md);
transition: transform 0.3s ease, box-shadow 0.3s ease;
}
.card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); }

Pricing Card

.pricing-card {
background: var(--color-surface);
border-radius: var(--radius-lg, 16px);
padding: 2.5rem;
border: 1px solid rgba(255,255,255,0.08);
text-align: center;
transition: transform 0.3s, box-shadow 0.3s;
}
.pricing-card--featured {
border-color: var(--color-primary);
box-shadow: 0 0 0 2px var(--color-primary), var(--shadow-lg);
transform: scale(1.03);
}
.pricing-card__price { font-size: 3rem; font-weight: 800; line-height: 1; }
.pricing-card__period { font-size: 0.875rem; opacity: 0.6; }
.pricing-card__features { list-style: none; margin: 1.5rem 0; text-align: left; display: flex; flex-direction: column; gap: 0.75rem; }
.pricing-card__features li::before { content: "✓"; color: var(--color-primary); margin-right: 0.5rem; font-weight: 700; }

4. Button Patterns

Full Button System

.btn {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.5rem;
padding: 0.75rem 1.75rem;
border-radius: var(--radius-md, 8px);
font-weight: 600;
font-size: 1rem;
cursor: pointer;
border: none;
transition: all 0.2s ease;
text-decoration: none;
white-space: nowrap;
}
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.15); transform: translateY(-1px); }
.btn-secondary { background: transparent; color: var(--color-primary); border: 2px solid var(--color-primary); }
.btn-secondary:hover { background: var(--color-primary); color: #fff; }
.btn-ghost { background: rgba(255,255,255,0.06); color: var(--color-text); }
.btn-ghost:hover { background: rgba(255,255,255,0.12); }
.btn-sm { padding: 0.5rem 1.25rem; font-size: 0.875rem; }
.btn-lg { padding: 1rem 2.5rem; font-size: 1.125rem; }

5. Form Patterns

Minimal Dark Form

.form-group { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1.5rem; }
.form-label { font-size: 0.875rem; font-weight: 500; opacity: 0.85; }
.form-input {
background: transparent;
border: none;
border-bottom: 1px solid rgba(255,255,255,0.2);
color: var(--color-text);
padding: 0.75rem 0;
font-size: 1rem;
outline: none;
transition: border-color 0.25s;
width: 100%;
}
.form-input:focus { border-bottom-color: var(--color-primary); }
.form-input::placeholder { opacity: 0.4; }

6. Utility Classes Starter

/* Display */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* Text */
.text-center { text-align: center; }
.text-muted { color: var(--color-muted, #888); }
.gradient-text { background: linear-gradient(135deg, var(--color-primary), var(--color-accent, #00ff87)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }

/* Layout */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 1.5rem; }
.section { padding: clamp(3rem, 8vw, 6rem) 0; }
.flex-center { display: flex; align-items: center; justify-content: center; }