🎨

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.

CSS Utility · v1.0.0 · 0 downloads

Download

curl -OL https://ahmedhabib.com/libraries/download/css-essentials
7
Modules
70+
Utilities
0
Dependencies
CSS3+
CSS Version

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

  1. Download CssEssentials.css
  2. Add <link rel="stylesheet" href="CssEssentials.css"> to your HTML head
  3. Use utility classes directly in your markup: class="flex-center animate-fade-in glass"
  4. 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
Center children both horizontally and vertically using flexbox.
.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}
.flex-between
Space children evenly with items centered vertically.
.flex-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.flex-col / .flex-wrap
Column direction and wrapping flex helpers.
.flex-col  { display:flex; flex-direction:column; }
.flex-wrap { display:flex; flex-wrap:wrap; }
.grid-2 / .grid-3 / .grid-4
Responsive auto-fill grids with 2, 3, or 4 column targets.
<div class="grid-3">
  <div>Card 1</div>
  <div>Card 2</div>
  <div>Card 3</div>
</div>
/* auto-fills, wraps on small screens */
.container
Centered container with max-width 1200px and responsive padding.
.container {
  width: 100%;
  max-width: 1200px;
  margin-inline: auto;
  padding-inline: var(--ce-space-lg);
}
.aspect-square / .aspect-video / .aspect-portrait
Fixed aspect ratio boxes using the native aspect-ratio property.
.aspect-square   { aspect-ratio: 1 / 1; }
.aspect-video    { aspect-ratio: 16 / 9; }
.aspect-portrait { aspect-ratio: 3 / 4; }
.sticky-top
Stick element to top of viewport on scroll with elevated z-index.
.sticky-top {
  position: sticky;
  top: 0;
  z-index: var(--ce-z-sticky);
}
.full-bleed / .overlay
Full-width breakout from container and absolute overlay cover.
.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
Animated gradient text using background-clip and custom properties.
.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
Balances line lengths in headings for more visually even wrapping.
.text-balance {
  text-wrap: balance;
}
/* Prevents orphaned words on last line */
.text-truncate
Single-line text truncation with ellipsis overflow.
.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.text-clamp-2 / .text-clamp-3
Multi-line truncation clamped to 2 or 3 lines with ellipsis.
.text-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.drop-cap
Decorative large first letter styled with the primary color.
.drop-cap::first-letter {
  float: left;
  font-size: 3.5em;
  line-height: 0.8;
  font-weight: 700;
  color: var(--ce-color-primary);
}
.underline-fancy
Animated underline that expands from left on hover.
.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
Anti-aliased font rendering for crisp text on macOS/iOS.
.font-smooth {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
.text-shadow-soft / .text-shadow-hard
Soft ambient shadow and hard retro offset shadow for text.
.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 / .prose-flow
Screen-reader-only hidden text and comfortable reading width.
.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

.animate-fade-in
Fade in from transparent to fully visible.
@keyframes ce-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.animate-fade-in {
  animation: ce-fade-in 0.5s var(--ce-ease-out) both;
}
.animate-slide-up / slide-down
Slide in with fade from below or above.
@keyframes ce-slide-up {
  from { opacity:0; transform:translateY(1rem); }
  to   { opacity:1; transform:translateY(0); }
}
/* .animate-slide-down mirrors with -1rem */
.animate-slide-left / slide-right
Horizontal slide entrances from left or right edges.
<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
Scale up from 90% to full size with a spring easing curve.
.animate-scale {
  animation: ce-scale 0.4s
    var(--ce-ease-spring) both;
}
/* Uses spring easing for a natural bounce */
.animate-bounce / .animate-pulse
Infinite bouncing motion and pulsing opacity effect.
.animate-bounce {
  animation: ce-bounce 1s ease infinite;
}
.animate-pulse {
  animation: ce-pulse 2s ease-in-out infinite;
}
.animate-spin / .animate-shake
Continuous rotation and horizontal shake for attention.
<i class="fa-solid fa-spinner animate-spin"></i>
/* Spins 360Β° continuously */

<button class="animate-shake">Error</button>
/* Quick horizontal shake */
.hover-lift
Lift element upward with elevated shadow on hover.
.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
Glowing ring effect around element on hover using box-shadow.
.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

.btn-base
Base button with hover state, focus ring, and primary color scheme.
<button class="btn-base">Click Me</button>

.btn-base {
  padding: 0.6em 1.2em;
  background: var(--ce-color-primary);
  color: #fff; border-radius: 8px;
}
.badge
Small pill-shaped badge with bold text for labels and counts.
<span class="badge">New</span>
<span class="badge" style="background:#22c55e">
  Active
</span>
.card-hover
Card wrapper with lift and shadow transition on hover.
<div class="card-hover">
  <img src="..." />
  <h3>Title</h3>
  <p>Description</p>
</div>
/* Lifts -4px + shadow on hover */
.tooltip
Pure CSS tooltip that appears above on hover via data-tooltip attribute.
<span class="tooltip"
      data-tooltip="Hello!">
  Hover me
</span>
/* No JS needed β€” uses ::after pseudo */
.divider
Horizontal line divider with centered text label between.
<div class="divider">OR</div>

/* Renders: ────── OR ────── */
/* Uses ::before and ::after flex lines */
.skeleton
Loading placeholder with animated shimmer gradient sweep.
<div class="skeleton"
     style="height:20px; width:60%">
</div>
/* Animates a shimmer effect across */
.avatar
Circular avatar for images or initial letters with fallback color.
<img class="avatar" src="photo.jpg" />
<span class="avatar">AH</span>
/* 40px circle, object-fit cover for imgs */
.pill / .ribbon
Inline pill tag with border and absolute corner ribbon banner.
<span class="pill">CSS</span>

<div style="position:relative">
  <span class="ribbon">New</span>
  Card content...
</div>
.progress-bar
Animated progress bar with gradient fill, set width via child element.
<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
Frosted glassmorphism effect with backdrop blur and semi-transparent background.
.glass {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.2);
}
.gradient-primary / sunset / ocean
Three preset gradient backgrounds for hero sections and banners.
.gradient-primary {
  background: linear-gradient(135deg,
    #4361ee, #7209b7);
}
.gradient-sunset { /* orange→pink→purple */ }
.gradient-ocean  { /* cyan→blue→indigo */ }
.shadow-soft / hard / inner / glow
Four shadow styles: ambient, retro offset, inset, and colored glow.
.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 blur without color β€” combine with your own background.
.blur-bg {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
/* Pair with background color for glass effect */
.noise-bg
Subtle noise texture overlay using inline SVG filter data URI.
<div class="noise-bg gradient-primary">
  Hero content here
</div>
/* ::after applies feTurbulence SVG noise */
/* Combine with any gradient background */
.border-gradient
Gradient border using background-clip trick with transparent border.
.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-polygon
Clip elements into circle or pentagon shapes using clip-path.
.clip-circle {
  clip-path: circle(50%);
}
.clip-polygon {
  clip-path: polygon(50% 0%, 100% 38%,
    82% 100%, 18% 100%, 0% 38%);
}
.filter-grayscale / .filter-sepia
Image filters that remove on hover with smooth transition.
<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

.hide-mobile / .hide-desktop
Toggle visibility based on viewport width (768px breakpoint).
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
}
@media (min-width: 769px) {
  .hide-desktop { display: none !important; }
}
.stack-mobile
Convert horizontal flex layout to vertical column on mobile.
<div class="flex-between stack-mobile">
  <div>Left</div>
  <div>Right</div>
</div>
/* Row on desktop, column on mobile */
.text-center-mobile
Center text alignment on small screens, left-aligned on desktop.
@media (max-width: 768px) {
  .text-center-mobile {
    text-align: center !important;
  }
}
.cq-stack / .cq-hide / .cq-grid
Container-query-aware utilities that respond to parent width, not viewport.
@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); }
}
Fluid spacing scale
Responsive spacing tokens that scale fluidly between viewport sizes using clamp().
--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

Color palette
10-color palette with primary, secondary, accent, semantic colors, and neutrals.
--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;
Neutral scale
5-step neutral gray scale from lightest to darkest for backgrounds and text.
--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 */
Spacing scale
7-step fluid spacing scale using clamp() for responsive sizing.
--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);
Border radius scale
4-step radius scale from subtle rounding to fully circular.
--ce-radius-sm:   4px;    /* subtle */
--ce-radius-md:   8px;    /* default */
--ce-radius-lg:   12px;   /* cards */
--ce-radius-full: 9999px; /* pill/circle */
Font size scale
5-step fluid typography scale from captions to headings.
--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);
Z-index scale
5-level z-index system to avoid z-index wars and maintain stacking order.
--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 */
Transition presets
3 easing curves: smooth ease-out, balanced ease-in-out, and playful spring bounce.
--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); */
Overriding tokens
Re-theme the entire library by overriding custom properties in your own stylesheet.
/* your-theme.css */
:root {
  --ce-color-primary: #059669;
  --ce-color-accent:  #d946ef;
  --ce-radius-md:     16px;
}
/* All components update automatically */
ESC