CSS Essentials
A zero-dependency CSS utility toolkit with 70+ utility classes, animations, pure-CSS components, and a design-token system for layout, typography, effects, and responsive design.
Download
curl -OL https://ahmedhabib.com/libraries/download/css-essentials
CSS Essentials is a single-file, zero-dependency CSS utility library that provides 70+ ready-to-use classes and custom properties organized into seven modules: Layout (flexbox/grid shortcuts), Typography (gradient text, truncation, drop caps), Animation (keyframe presets with hover helpers), Components (buttons, badges, tooltips, skeletons β no JS needed), Effects (glassmorphism, shadows, gradients, clipping), Responsive (visibility toggles, mobile stacking, container queries), and Tokens (a complete design-token system of custom properties for colors, spacing, radii, and typography). Drop it into any project and start building polished interfaces immediately.
Every front-end project starts with the same boilerplate β centering divs, truncating text, adding hover animations, creating card shadows, and setting up a spacing scale. You can reach for a heavyweight framework, but then you inherit thousands of classes you never use and a build step you don't want. CSS Essentials takes the opposite approach: one lightweight file with only the utilities that real projects actually need, organized into seven logical modules. Every class is designed to compose with others, and the underlying design-token system means you can re-theme the entire library by overriding a handful of custom properties. It targets modern CSS (custom properties, clamp(), aspect-ratio, backdrop-filter, container queries) while remaining small enough to audit in a single sitting.
-
Layout 12 utilities
Flexbox and grid shortcuts β flex-center, flex-between, flex-col, flex-wrap, grid-2 through grid-4 auto-fill columns, fixed container with auto margins, aspect-ratio boxes (square, video, portrait), sticky-top positioning, full-bleed breakout, and absolute overlay cover.
-
Typography 11 utilities
Text utilities β animated gradient text, text-balance for headings, single-line truncation with ellipsis, multi-line clamping (2 and 3 lines), font-smoothing for crisp type, decorative drop caps, fancy animated underlines, soft and hard text shadows, screen-reader-only visually hidden text, and prose-flow for comfortable reading widths.
-
Animation 12 utilities
Keyframe animations and hover helpers β fade-in, slide-up, slide-down, slide-left, slide-right, scale-in entrance, bounce, pulse glow, continuous spin, horizontal shake, hover-lift with shadow, and hover-glow ring effect. All animations use CSS custom properties for duration and easing.
-
Components 10 utilities
Pure CSS components requiring zero JavaScript β base button with focus ring, colored badges, hover-lift card with subtle shadow, CSS-only tooltip on hover, horizontal divider with centered text, skeleton loading placeholder with shimmer, circular avatar with fallback initial, pill-shaped tag, corner ribbon banner, and animated progress bar with striped fill.
-
Effects 10 utilities
Visual effects β frosted glassmorphism with backdrop-blur, linear gradient backgrounds (primary, sunset, ocean), multi-level shadows (soft, hard, inner, glow), background blur overlay, noise texture overlay via SVG data URI, gradient borders using background-clip trick, circle and polygon clipping masks, and grayscale/sepia image filters.
-
Responsive 8 utilities
Responsive design helpers β hide on mobile, hide on desktop, stack horizontal layouts to vertical on mobile, center text on small screens, container-query-aware components, and a full responsive spacing scale using clamp() for fluid --space-xs through --space-2xl values.
-
Tokens 10 utilities
Design-token system as CSS custom properties β a 10-color palette with light and dark variants, 7-step spacing scale (xs through 2xl), 4-step border-radius scale, 5-step font-size scale, 5-level z-index scale, and 3 transition-timing presets (ease-out, ease-in-out, spring bounce).
- Download CssEssentials.css
- Add <link rel="stylesheet" href="CssEssentials.css"> to your HTML head
- Use utility classes directly in your markup: class="flex-center animate-fade-in glass"
- Customize by overriding the CSS custom properties in your own stylesheet
<link rel="stylesheet" href="CssEssentials.css">
Layout
12 utilities for flexbox, grid, containers, and positioning
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display:flex; flex-direction:column; } .flex-wrap { display:flex; flex-wrap:wrap; }
<div class="grid-3"> <div>Card 1</div> <div>Card 2</div> <div>Card 3</div> </div> /* auto-fills, wraps on small screens */
.container { width: 100%; max-width: 1200px; margin-inline: auto; padding-inline: var(--ce-space-lg); }
.aspect-square { aspect-ratio: 1 / 1; } .aspect-video { aspect-ratio: 16 / 9; } .aspect-portrait { aspect-ratio: 3 / 4; }
.sticky-top { position: sticky; top: 0; z-index: var(--ce-z-sticky); }
.full-bleed { width: 100vw; margin-inline: calc(50% - 50vw); } .overlay { position:absolute; inset:0; }
Typography
11 utilities for text styling, truncation, and readability
.text-gradient { background: linear-gradient(135deg, var(--ce-color-primary), var(--ce-color-accent)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.text-balance { text-wrap: balance; } /* Prevents orphaned words on last line */
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.drop-cap::first-letter { float: left; font-size: 3.5em; line-height: 0.8; font-weight: 700; color: var(--ce-color-primary); }
.underline-fancy { background-image: linear-gradient( var(--ce-color-accent), var(--ce-color-accent)); background-size: 0% 2px; background-position: 0 100%; } .underline-fancy:hover { background-size: 100% 2px; }
.font-smooth { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
.text-shadow-soft { text-shadow: 0 1px 3px rgba(0,0,0,.12); } .text-shadow-hard { text-shadow: 2px 2px 0 var(--ce-color-neutral-300); }
.sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); } .prose-flow { max-width:65ch; line-height:1.75; }
Animation
12 keyframe animations and hover interaction helpers
@keyframes ce-fade-in { from { opacity: 0; } to { opacity: 1; } } .animate-fade-in { animation: ce-fade-in 0.5s var(--ce-ease-out) both; }
@keyframes ce-slide-up { from { opacity:0; transform:translateY(1rem); } to { opacity:1; transform:translateY(0); } } /* .animate-slide-down mirrors with -1rem */
<div class="animate-slide-left"> Slides in from the right edge </div> <div class="animate-slide-right"> Slides in from the left edge </div>
.animate-scale { animation: ce-scale 0.4s var(--ce-ease-spring) both; } /* Uses spring easing for a natural bounce */
.animate-bounce { animation: ce-bounce 1s ease infinite; } .animate-pulse { animation: ce-pulse 2s ease-in-out infinite; }
<i class="fa-solid fa-spinner animate-spin"></i> /* Spins 360Β° continuously */ <button class="animate-shake">Error</button> /* Quick horizontal shake */
.hover-lift { transition: transform 0.25s, box-shadow 0.25s; } .hover-lift:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.hover-glow:hover { box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.35); } /* Pairs well with border-radius */
Components
10 pure CSS components β no JavaScript required
<button class="btn-base">Click Me</button> .btn-base { padding: 0.6em 1.2em; background: var(--ce-color-primary); color: #fff; border-radius: 8px; }
<span class="badge">New</span> <span class="badge" style="background:#22c55e"> Active </span>
<div class="card-hover"> <img src="..." /> <h3>Title</h3> <p>Description</p> </div> /* Lifts -4px + shadow on hover */
<span class="tooltip" data-tooltip="Hello!"> Hover me </span> /* No JS needed β uses ::after pseudo */
<div class="divider">OR</div> /* Renders: ββββββ OR ββββββ */ /* Uses ::before and ::after flex lines */
<div class="skeleton" style="height:20px; width:60%"> </div> /* Animates a shimmer effect across */
<img class="avatar" src="photo.jpg" /> <span class="avatar">AH</span> /* 40px circle, object-fit cover for imgs */
<span class="pill">CSS</span> <div style="position:relative"> <span class="ribbon">New</span> Card content... </div>
<div class="progress-bar"> <div style="width:75%"></div> </div> /* Gradient fill with smooth transition */
Effects
10 visual effects β glass, gradients, shadows, clipping, and filters
.glass { background: rgba(255,255,255,0.15); backdrop-filter: blur(12px); border: 1px solid rgba(255,255,255,0.2); }
.gradient-primary { background: linear-gradient(135deg, #4361ee, #7209b7); } .gradient-sunset { /* orangeβpinkβpurple */ } .gradient-ocean { /* cyanβblueβindigo */ }
.shadow-soft { box-shadow: 0 4px 12px rgba(0,0,0,.08); } .shadow-hard { box-shadow: 4px 4px 0 #0f172a; } .shadow-inner { box-shadow: inset 0 2px 6px rgba(0,0,0,.1); } .shadow-glow { box-shadow: 0 0 20px rgba(67,97,238,.4); }
.blur-bg { backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); } /* Pair with background color for glass effect */
<div class="noise-bg gradient-primary"> Hero content here </div> /* ::after applies feTurbulence SVG noise */ /* Combine with any gradient background */
.border-gradient { border: 2px solid transparent; background-image: linear-gradient(#f1f5f9, #f1f5f9), linear-gradient(135deg, #4361ee, #f72585); background-clip: padding-box, border-box; }
.clip-circle { clip-path: circle(50%); } .clip-polygon { clip-path: polygon(50% 0%, 100% 38%, 82% 100%, 18% 100%, 0% 38%); }
<img class="filter-grayscale" src="..." /> /* Grayscale by default, color on hover */ .filter-grayscale { filter: grayscale(100%); transition: filter 0.3s ease; } .filter-grayscale:hover { filter: grayscale(0%); }
Responsive
8 utilities for visibility, layout shifts, and container queries
@media (max-width: 768px) { .hide-mobile { display: none !important; } } @media (min-width: 769px) { .hide-desktop { display: none !important; } }
<div class="flex-between stack-mobile"> <div>Left</div> <div>Right</div> </div> /* Row on desktop, column on mobile */
@media (max-width: 768px) { .text-center-mobile { text-align: center !important; } }
@container (max-width: 400px) { .cq-stack { flex-direction: column; } .cq-hide { display: none; } } @container (min-width: 600px) { .cq-grid { display:grid; grid-template-columns:repeat(2,1fr); } }
--ce-space-xs: clamp(0.25rem, 0.5vw, 0.375rem); --ce-space-sm: clamp(0.5rem, 1vw, 0.75rem); --ce-space-md: clamp(0.75rem, 1.5vw, 1rem); --ce-space-lg: clamp(1rem, 2vw, 1.5rem); --ce-space-xl: clamp(1.5rem, 3vw, 2rem); --ce-space-2xl: clamp(2rem, 4vw, 3rem);
Tokens
10 custom property groups for a complete design-token system
--ce-color-primary: #4361ee; --ce-color-primary-light: #6b83f2; --ce-color-primary-dark: #2a46d1; --ce-color-secondary: #7209b7; --ce-color-accent: #f72585; --ce-color-success: #22c55e; --ce-color-warning: #eab308; --ce-color-danger: #ef4444;
--ce-color-neutral-100: #f1f5f9; /* bg */ --ce-color-neutral-300: #cbd5e1; /* border */ --ce-color-neutral-500: #64748b; /* muted text */ --ce-color-neutral-700: #334155; /* body text */ --ce-color-neutral-900: #0f172a; /* headings */
--ce-space-xs: clamp(0.25rem, 0.5vw, 0.375rem); --ce-space-sm: clamp(0.5rem, 1vw, 0.75rem); --ce-space-md: clamp(0.75rem, 1.5vw, 1rem); --ce-space-lg: clamp(1rem, 2vw, 1.5rem); --ce-space-xl: clamp(1.5rem, 3vw, 2rem); --ce-space-2xl: clamp(2rem, 4vw, 3rem); --ce-space-3xl: clamp(3rem, 6vw, 4.5rem);
--ce-radius-sm: 4px; /* subtle */ --ce-radius-md: 8px; /* default */ --ce-radius-lg: 12px; /* cards */ --ce-radius-full: 9999px; /* pill/circle */
--ce-font-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem); --ce-font-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem); --ce-font-md: clamp(0.9rem, 0.85rem + 0.25vw, 1rem); --ce-font-lg: clamp(1.1rem, 1rem + 0.5vw, 1.25rem); --ce-font-xl: clamp(1.4rem, 1.2rem + 1vw, 1.75rem);
--ce-z-base: 1; /* default */ --ce-z-dropdown: 100; /* menus */ --ce-z-sticky: 200; /* fixed nav */ --ce-z-overlay: 300; /* backdrops */ --ce-z-modal: 400; /* dialogs */
--ce-ease-out: cubic-bezier(0.22, 1, 0.36, 1); --ce-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1); --ce-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1); /* Usage: transition: all 0.3s var(--ce-ease-out); */
/* your-theme.css */ :root { --ce-color-primary: #059669; --ce-color-accent: #d946ef; --ce-radius-md: 16px; } /* All components update automatically */