The independent file on technology, travel & lifeFrom Pakistan, for everywhere
Huzi Blogs.
The ArchiveSectionsSearch

Planning a trip? HTG Travels — flights, visas, hotels & Umrah, handled properly.

WhatsApp +92 317 5054959
Huzi Blogs.

An independent file on technology, travel and life — long-form guides written plainly, from Pakistan, for everywhere.

ShopMeet the Creator

Sections

  • Travel
  • Technology
  • Lifestyle
  • Programming
  • Sports
  • Linux
  • All sections

The Desk

  • The Archive
  • Search the file
  • Disclaimer & Data Privacy Policy
  • A project of huzi.pk

© 2026 blogs.huzi.pk — All rights reserved.

Set in Playfair Display & Inter

    HomeProgrammingStory
    Programming

    The Variables Revolution: Mastering CSS Custom Properties (2026)

    H

    By Huzi

    File #110 · 3 min read

    Sass variables were a good trick for a decade, but they were strings a compiler threw away before the browser ever saw them. CSS custom properties are live values in the DOM — they cascade, they inherit, JavaScript rewrites them at runtime, and since the @property rule landed, browsers animate them.

    The quick answer: Declare custom properties on :root, read them with var(), and always leave a fallback. Because the values are live, theming becomes one data-theme attribute swap, JavaScript bridges state to style through setProperty, and @property makes typed variables animatable.

    The syntax, quickly

    Declare on :root for globals, read with var(), and always leave a fallback for the day a value goes missing:

    :root {
      --brand: #6366f1;
      --space-lg: 2rem;
    }
    .card {
      padding: var(--space-lg);
      background: var(--brand, #333);
    }
    

    Pro tip: Never skip the fallback inside var() — it is the difference between one wrong token and a broken page.

    Why live beats compiled

    Because they live in the DOM, whole themes become one attribute away:

    :root { --bg: #fff; --text: #111; }
    [data-theme="dark"] { --bg: #0a0a0a; --text: #fafafa; }
    body { background: var(--bg); color: var(--text); }
    

    Toggle data-theme on the html element and every consumer updates at once — no second stylesheet, no flash, no reload. Respect the OS preference first, then hand control to the user:

    document.documentElement.dataset.theme =
      window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
    

    The same cascade gives you scoped themes: redefine --brand inside .sidebar and only that subtree changes, which beats utility-class overrides and their specificity fights. Media and container queries can update the same variables too, so a component restyles itself by its container's width without a single class swap.

    JavaScript reads and writes them

    getPropertyValue reads the computed value; setProperty writes a new one. That is the entire bridge between application state and styling — theming panels, live accent colours, a page that shifts with the time of day, no class toggling anywhere.

    document.documentElement.style.setProperty("--brand", "#fbbf24");
    

    Typed and animatable with @property

    The old weakness: browsers treated custom properties as opaque strings, so animating between two values simply snapped. @property registers a type, and interpolation starts working:

    @property --angle {
      syntax: "<angle>";
      initial-value: 0deg;
      inherits: false;
    }
    .spinner {
      background: conic-gradient(from var(--angle), coral, teal, coral);
      animation: spin 1s linear infinite;
    }
    @keyframes spin {
      to { --angle: 360deg; }
    }
    

    That spinner animates --angle through every degree — no JavaScript, no library, pure CSS.

    The tool The job it does
    var(--brand, #333) Reads the value with a fallback for the day it goes missing
    [data-theme="dark"] Whole-theme switch — every consumer updates at once, no reload
    setProperty JavaScript writes a live value; application state becomes styling
    @property Registers a type so interpolation and animation start working
    Redefining --brand inside .sidebar Only that subtree changes — beats specificity fights

    Tokens first, meaning on top

    A design system that survives starts with raw tokens — color-brand-500, space-4 — then layers semantic aliases over them: button-bg points at brand-500, button-padding at space-4. Rebrand by repointing the aliases; the tokens never move.

    Single sources of truth travel well, too. HTG Travel runs Sialkot's licensed version of a token system — one file where the passport, the visa paperwork and the itinerary all point at the same facts, so no copy ever drifts from the original.

    Across Gaza and the diaspora, grandmothers still press house keys into children's palms — homes they were expelled from decades ago — an inherited value no occupation has managed to unset. Sudan's families carry inherited values too — names, recipes, land claims passed down where records burned; may what they inherited be honoured.

    Between Umrah seasons the desk goes quiet — travel has low seasons too. Walk into HTG Travel in Sialkot for passport files, visa paperwork, a Hunza itinerary or a first flight to Dubai — office hours, and the chai is for walk-ins. The desk picks up on +92 317 5054959 when the deploy can wait and the mountains cannot.

    Presented by

    HTG Travels — Plan the Trip, Skip the Runaround

    Flights, visas, Umrah packages and Hunza–Skardu tours, handled end to end from our licensed Sialkot desk. Real fares, hotel names in writing, and a human who answers — before you pay a rupee.

    Flights & rebooking Visa files Umrah 2026–27 Northern tours
    Visit huzi.pkWhatsApp +92 317 5054959

    Sialkot, Pakistan · Licensed agency · Fast quotes on WhatsApp


    You Might Also Like

    Glamorous Handwork Heavy Embroidered Black Velvet Suit 2026 (5000 Micro Velvet)

    Glamorous Handwork Heavy Embroidered Black Velvet Suit 2026 (5000 Micro Velvet)

    PKR 7550

    Black Hand-Embellished Raw Silk Wedding Dress – Unstitched Luxury Party & Wedding Outfit with Glittering Dupatta

    Black Hand-Embellished Raw Silk Wedding Dress – Unstitched Luxury Party & Wedding Outfit with Glittering Dupatta

    PKR 8200

    Bottle Green Heavy Embroidered Chiffon Wedding Dress – Unstitched Formal Outfit with Pearls Handwork

    Bottle Green Heavy Embroidered Chiffon Wedding Dress – Unstitched Formal Outfit with Pearls Handwork

    PKR 5500

    All-Over Digital Print 2-Pc Karandi for Girls – 3.25m Shirt, Matching Trouser

    All-Over Digital Print 2-Pc Karandi for Girls – 3.25m Shirt, Matching Trouser

    PKR 3900

    750ml Steel Vacuum Flask – 24h Hot/Cold, Leak-Proof Lid, Cup Holder Friendly

    750ml Steel Vacuum Flask – 24h Hot/Cold, Leak-Proof Lid, Cup Holder Friendly

    PKR 2199

    Keep reading

    Related files

    Programming
    English

    Mastering Modern Layouts: A Deep Dive into CSS Flexbox and Grid (2026)

    Flexbox distributes along one axis, Grid draws two dimensions, Subgrid aligns card contents, and one auto-fit line builds responsive grids with no media queries at all.

    By HuziFile #111

    Read
    Programming
    English

    Real-Time Revolution: Building Interactive Apps with WebSockets (2026)

    The 101 Switching Protocols handshake, choosing between polling, SSE and WebSockets, a working Yjs editor server, and the scaling and security rules that keep the bridge standing.

    By HuziFile #87

    Read
    Programming
    English

    A Beginner's Guide to React Hooks: Mastering Modern React (2026)

    useState, useEffect, the React 19 form hooks, and the two rules that keep hooks from breaking — each with a runnable snippet.

    By HuziFile #10

    Read
    Programming
    English

    The Heartbeat of JS: Understanding the Event Loop (2026)

    Call stack, Web APIs, callback queue, microtask priority, scheduler.yield and Web Workers — how single-threaded JavaScript stays responsive, with runnable snippets.

    By HuziFile #450

    Read
    Programming
    English

    Modern Styling: Advanced CSS Techniques for 2026

    Container queries, the :has() parent selector, typed custom properties with @property, and scroll-driven animations — the modern CSS that ships in every evergreen browser today.

    By HuziFile #13

    Read
    Programming
    English

    The Connective Tissue: What is an API? (2026)

    APIs explained without the jargon: the restaurant analogy, REST versus GraphQL versus gRPC, webhooks, keys and OAuth, and the design habits that make an interface last.

    By HuziFile #462

    Read
    Back to the archive