Navigation: uCss > Source > Modules
Modules: Config | Base | Layout | Theming | Typography | Patterns | Utilities
The Development Hub. This directory contains the raw, uncompiled source code of the uCss framework. It is the workspace for contributors and advanced users who want to understand the inner workings of the system.
Welcome to the uCss Source Code. While the Overview introduces what uCss is, this document explains how it works and why it is built this way. This guide is intended for developers who want to understand the framework's internal logic, customize it deeply, or contribute to its source.
Most CSS frameworks rely on Media Queries (screen size) to determine layout. uCss relies on Container Queries (context size).
This shift makes components truly portable. You can place a Card, a Form, or a Grid anywhereβin a modal, a sidebar, or a hero sectionβand it will adapt to its immediate parent without you writing a single extra line of CSS.
In uCss, CSS Variables (Custom Properties) are not just for colors; they are the primary interface for controlling the framework.
root.css): Defines the defaults.:root { --p: hsl(43 100% 50%); /* Global Primary */ }
.btn { background: var(--btn-bg, var(--p)); }
<div style="--p: blue;">
<button class="btn primary">I am Blue</button>
</div>
We organize our CSS to leverage the natural cascade rather than fighting it with !important or high specificity.
uCss is Internationalization-Ready out of the box. We strictly use CSS Logical Properties.
inline-start / inline-endblock-start / block-endinline-size / block-sizeThis means if you switch dir="rtl" on the <html> tag, the entire layout (margins, paddings, text-aligns, borders) flips automatically.
The src/ directory represents the Development Environment.
src/
βββ README.md # This Architecture Guide
βββ u.css # The Manifest (orchestrates imports)
βββ lib/ # The Modular Source Code
βββ config/ # THE BRAIN: Design tokens, colors, scales
βββ base/ # THE FOUNDATION: HTML Resets & Normalizers
βββ layout/ # THE SKELETON: Grid, Flex, Section
βββ typography/ # THE VOICE: Fluid type scales
βββ patterns/ # THE BODY: UI Elements (Cards, Buttons)
βββ theming/ # THE SKIN: Contextual themes, overlays
βββ utilities/ # THE TOOLS: Spacing helpers
src vs distThe dist/ (eg. stable/) folder contains flat, minified, and production-ready code, while src/ is for managing the source code. This approach is built for human readability and modularity.
Every file in both folders corresponds to a specific logical unit of the framework.
src/: Contains raw source files with heavy comments and individual @import statements:button/skins.css).@import to aggregate functionality.dist/: Generated by the build system.uCss is architected around a 7-Layer Model that moves from pure configuration to specific utilities. This structure ensures that dependencies flow in one direction: downwards.
| Layer | Directory | Responsibility | Dependency Rule |
|---|---|---|---|
| 1. Config | lib/config/ |
The Brain. Defines values (Variables) only. No selectors. | Can only act as root. |
| 2. Base | lib/base/ |
The Foundation. HTML resets, flow engine (html.css). |
Depends on Config. |
| 3. Patterns | lib/patterns/ |
The Organs. Complex Components (.btn, .crd). |
Depends on Config, Layout, Typo. |
| 4. Layout | lib/layout/ |
The Skeleton. Macro structures (.g, .s, .f). |
Depends on Config, Base. |
| 5. Theming | lib/theming/ |
The Skin. Contextual appearance (.set, .o). |
Depends on Config. |
| 6. Typography | lib/typography/ |
The Voice. Text styles (.t, .tx). |
Depends on Config. |
| 7. Utilities | lib/utilities/ |
The Tools. Micro-tweaks (.mg, .pd). |
Depends on Config. |
The file src/u.css acts as the Manifest. It contains zero CSS selectors. Its only job is to orchestrate the import order of the modules.
/* src/u.css */
@import 'lib/config/root.css'; /* 1. Load Variables (Optional, and not included in bundle) */
@import 'lib/base.css'; /* 2. Reset HTML */
@import 'lib/patterns.css'; /* 3. Load Components */
@import 'lib/layout.css'; /* 4. Build Layouts */
@import 'lib/theming.css'; /* 5. Apply Themes */
@import 'lib/typography.css'; /* 6. Set Type */
@import 'lib/utilities.css'; /* 7. Allow Overrides */
Why this order matters:
!important or high-spec chains to force overrides, so they must come last in the cascade.Our architecture is "Variable-First". This means the API of a component is its variables, not just its class name.
.btn (Triggers the visual appearance).--btn-bg (Configures the appearance).This separation allows for powerful Contextual Theming. A .btn.alt inside a .set.dark container can automatically change its logic by simply inheriting different variable values, without needing a modifier classes and custom css overrides.
A detailed breakdown of the lib/ directory contents.
lib/config)root/: The standard variable definitions.colors.css: PALETTE definitions (--p, --a, --bg).typography.css: SCALES for text (--t-fs-xl).layout.css: SPACING and sizing (--gap, --sc-max-w).blocksy.css / gutenberg.css: Compatibility layers for WordPress themes.root.css: The aggregator that exposes these as :root variables.lib/base)reset.css: Aggressive CSS reset (strips margins/padding from everything).html.css: The "Smart Flow" engine. It adds margin-block-start to elements only if they follow another element (* + *).content.css: Controller for the Flow engine. Includes .cs (Clean Stack - removes flow) and .csc (Content Stack - forces flow).lib/patterns)button.css: Button system with sizes, skins, and states.card.css: The main container component. Container-query aware.media.css: Aspect-ratio wrappers for img/video.link.css: The clickable-area expander (.lnk).lib/layout)grid/: The auto-responsive grid system.base.css: The core .g class logic.columns.css: Explicit column overrides (--g-cols).subgrid.css: Logic for nested grids (.sg).flex.css: Flexbox utility wrapper (.f).section.css: The page root structural element (.s).lib/theming)set.css: Contextual theme scopes (.set).overlay.css: Absolute positioned layers (.o).lib/typography)title.css: Headings (.t).text.css: Body text (.tx).text-align.css: Alignment utilities (.ta).lib/utilities)margin.css / padding.css: Spacing helpers (.mg, .pd).radius.css: Radius helpers (.rad).Our build system is custom-written in Node.js to handle the specific needs of a pure-CSS framework. It lives in scripts/.
build.js: The main orchestrator. usage: npm run build [target].index.js: Documentation generator. Renders Markdown to HTML and injects UI elements.bundle.js: Recursive resolver. Finds @import lines, reads the file, reads its imports, and flattens them into a single string.clean.js: Sanitizer. Removes JSDoc comments (/** ... */) but keeps copyright headers. Removes extra newlines.minify.js: Compressor. Removes all whitespace, shortens color codes, flattens newlines.prefix.js: Encapsulator. Logic to prefix all classes with .u- and variables with --u- for the dist/p/ build.compress.js: Gzip/Brotli generator. Creates .gz and .br variants for every output file.stats.js: Reporter. Calculates file sizes and logs them to the console after build.When you run npm run build, the following happens:
src/u.css is read. Imports are recursively traced.p, regex replaces .class -> .u-class.dist/target/u.clean.css is written.dist/target/u.min.css is written.gzip and brotli binaries are generated.The prefixing logic (scripts/prefix.js) is sophisticated. It knows how to:
.wp-block, .is-style-*, or standard HTML tags.@keyframes naming..btn.primary -> .u-btn.u-primary).The entire framework is surprisingly lightweight thanks to our optimization pipeline.
π₯ Offline Usage: You can also download the full stable release (.zip) containing all compiled assets.
| File | Full | Clean | Min | Gzip | Brotli | Download |
|---|---|---|---|---|---|---|
u.css (Full) |
~165KB | ~147KB | ~126KB | ~18.4KB | ~14.3KB | src β’ clean β’ min |
root.css |
~21KB | ~12KB | ~11KB | ~2.5KB | ~2.1KB | src β’ clean β’ min |
base.css |
~2.1KB | ~1.3KB | ~0.9KB | ~0.3KB | ~0.3KB | src β’ clean β’ min |
layout.css |
~70KB | ~67KB | ~57KB | ~7.1KB | ~5.2KB | src β’ clean β’ min |
typography.css |
~15KB | ~10KB | ~8.6KB | ~1.6KB | ~1.3KB | src β’ clean β’ min |
components.css |
~50KB | ~45KB | ~40KB | ~6.5KB | ~5.6KB | src β’ clean β’ min |
theming.css |
~17KB | ~15.6KB | ~14KB | ~3.3KB | ~2.8KB | src β’ clean β’ min |
utilities.css |
~10KB | ~7.3KB | ~6.2KB | ~1.1KB | ~0.9KB | src β’ clean β’ min |
Note: These stats are for the Full Framework. If you cherry-pick modules or even single files (see Modules), it is significantly smaller.
We welcome contributions! If you want to improve uCss, please follow these standards.
padding: 20px;padding: var(--gap);margin-left, border-topmargin-inline-start, border-block-start.crd.crd__body.crd.dark (chained), you can add .crd--dark as fallback (for parent container lookup modifiers use suffix like --sm variant).--my-var)..btn).button-group.css).[!TIP] Comment your code: We use JSDoc-style comments in CSS.
/** * @section Button * @description The main interaction element. */
html.css)How do we get perfect vertical rhythm without margins?
We use the lobotomized owl selector's successor: * + *.
/* Simplified Logic */
.flow > * + * {
margin-block-start: var(--flow-space, 1em);
}
This means "Every element that follows another element gets top margin".
root.css)The root.css file is effectively a switchboard. It maps "Semantic Intent" (e.g., "I want a Primary Color") to "Raw Value" (e.g., "Blue").
All components connect to the switchboard, not the value.
If you pull the main plug (change --p in root), all the lights (buttons, links, active states) change color instantly.
A quick lookup for where things live.
| Feature | Directory |
|---|---|
| Grid System | src/lib/layout/grid/ |
| Flexbox | src/lib/layout/flex.css |
| Buttons | src/lib/patterns/button/ |
| Typography | src/lib/typography/ |
| Global Vars | src/lib/config/root/ |
| Mixins | None (We use composition) |
root.css)The single source of truth. Contains Design Tokens for:
--p (Primary), --a (Accent), --bg, --srf.--t-fs-* (Heading sizes), --tx-fs-* (Body sizes).--sc-max-w (Max width), --gap.html.css: The Engine. Resets browser defaults and implements "Smart Flow" logic (* + *) to provide natural vertical rhythm for naked HTML elements using CSS variables.content.css: The Controller. Provides .cs (App Mode) to kill flow variables for layouts, and .csc (Content Mode) to restore them for prose. Also includes .cl (Clear List).section.css (.s): The root container. Handles responsive padding and max-width constraints (1366px default).grid.css (.g): Auto-fit grids using minmax(). No "12 column" mental overhead unless you strictly need it.flex.css (.f): Modern flexbox utilities with variable-based keys.title.css (.t): Fluid headings. Scales from mobile to desktop using clamp().text.css (.tx): Body copy with optimal line-heights.card.css (.crd): The "do everything" box. Composite architecture (media, content, header, body, footer).button.css (.btn): Interaction elements.media.css (.med): Aspect-ratio keepers.link.css (.lnk): The "Clickable Card" pattern solver.set.css (.set): Contextual scopes. .set.dark inverts colors for that section and all its children.overlay.css (.o): Absolute positioning for background images/gradients.margin (.mg) / padding (.pd): Spacing helpers using logical properties.radius (.rad): Consistent corner rounding.If you are contributing to uCss, here is how the magic happens.
We use a Node.js-based build system (scripts/build.js) instead of a complex bundler like Webpack or Vite. Why? Because we only output CSS.
@import matching src/lib.npm run build: Builds src/ -> dist/stable/ (or latest depending on branch).npm run build full: Builds all release channels (latest, prefixed, stable) sequentially../build.sh: Legacy shell wrapper (optional)./stable/): Production-ready. Use this for live sites. Automatically deployed from main./latest/): Testing/Beta. Automatically deployed from dev.We don't just copy files. Our dist assets go through a rigorous optimization pipeline to ensure maximum performance and compatibility:
@import statements into single-file bundles (like u.css or layout.css) to reduce HTTP requests./stable: Locked to the current major version. Safe for production./latest: Bleeding edge. Good for testing new features.For production usage, use the Stable channel.
Speed up connection time to our CDN:
<link rel="preconnect" href="https://ucss.unqa.dev">
<link rel="stylesheet" href="https://ucss.unqa.dev/latest/u.min.css">
<!-- Optional: Config Override -->
<link rel="stylesheet" href="https://ucss.unqa.dev/latest/lib/config/root.css">
If you only want the Grid system:
<link rel="stylesheet" href="https://ucss.unqa.dev/latest/lib/layout/grid.min.css">
site/ folder (local dev environment).Navigation: uCss > Source > Modules
License: MPL-2.0 Copyright: Β© 2025 Alive π