r/Frontend • • 8h ago

How CSS :has() and @container let me cut ~200 lines of UI state JS in a <10KB zero-build tool

10 Upvotes

Hey everyone! A few weeks ago I shared a post here about how UTF-16 surrogate pairs and historical Unicode holes break naive math-offset text converters. A bunch of you gave super helpful feedback on Safari clipboard edge cases, which pushed me to clean up the CSS architecture of my little side project (100emoji.shop β€” single static HTML file, no bundler/minifier so view-source has the full readable code).

When building a live preview grid with 20+ text style cards and category filters, my initial instinct was the usual JS-heavy route: track filter/input state in JS, toggle .is-empty classes, listen to input/focus to collapse the header on mobile, and add viewport breakpoints so wide glyphs don't overflow.

While refactoring to keep the whole app under 10KB gzipped, I realized modern CSS can handle almost all of that UI state declaratively on the compositor/layout thread with zero JS listeners. Here are the 3 patterns that replaced ~200 lines of glue code for me:

1. Zero-JS Empty States with :has()

Previously, every time a filter or search ran, JS had to count visible cards and toggle an empty-state element:

// Old imperative glue
function syncEmptyState() {
  const visibleCount = grid.querySelectorAll('.preview-card:not([hidden])').length;
  emptyBanner.hidden = visibleCount > 0;
}

With :has(), the grid container already knows whether any unhidden card exists:

.empty-state-banner {
  display: none;
}

/* Show empty state automatically whenever no visible card remains */
.previews-grid:not(:has(.preview-card:not([hidden]))) + .empty-state-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1rem;
}

Now filtering logic only sets card.hidden = !matches and walks away. No state sync bugs, no extra DOM queries.

2. Auto-Collapsing the Mobile Hero Header on Input

On mobile screens, once someone taps the text input or starts typing, a tall hero banner wastes half the viewport above the virtual keyboard. Instead of binding focus/input/scroll handlers to toggle classes on <body>, :has() handles both focus and non-empty input natively:

.hero-header {
  max-height: 220px;
  opacity: 1;
  overflow: hidden;
  transition:
    max-height 0.28s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.2s ease,
    margin 0.28s ease;
}

body:has(#user-input:focus, #user-input:not(:placeholder-shown)) .hero-header {
  max-height: 0;
  opacity: 0;
  margin-bottom: 0.5rem;
}

Quick tip: make sure your <input id="user-input" placeholder=" "> has at least a non-empty placeholder string so :not(:placeholder-shown) reliably detects when text is present.

3. Per-Card Fluid Sizing with @container + cqi Instead of Viewport Media Queries

Unicode mathematical alphabets (like Double-Struck π•Žπ•–π•π•”π• π•žπ•– or Fraktur π”šπ”’π”©π” π”¬π”ͺ𝔒) have much wider advance widths than normal Latin characters, so fixed rem sizes overflow narrow grid columns fast.

Instead of juggling @media queries for 1-col, 2-col, and 3-col viewports, turning each card into an inline-size query container let every card scale its own typography from its actual column width:

.preview-card {
  container-type: inline-size;
  container-name: card;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  border-radius: 12px;
}

/* Font size scales smoothly with the card's own inline width */
.preview-output {
  font-size: clamp(0.95rem, 6.5cqi, 1.3rem);
  line-height: 1.4;
  overflow-wrap: anywhere;
}

@container card (max-width: 260px) {
  .card-actions {
    flex-direction: column;
    gap: 0.35rem;
  }
}

Takeaways & Caveats

  • Performance: Keeping :has() scoped to direct containers (.previews-grid:not(:has(...))) and specific IDs (#user-input) kept style recalculation under ~0.3ms in Chrome DevTools performance traces, even when typing fast on throttled CPU.
  • Browser support: :has() and @container inline-size queries have been baseline across Chrome, Edge, Firefox, and Safari for a good while now, so for modern utility tools we didn't need a JS fallback.

Curious if anyone else here has been ripping out small UI state listeners in favor of :has() / container queries lately, or if you've hit selector performance gotchas on much larger DOM trees? Happy to share more details if anyone is curious!


r/Frontend • • 5h ago

Fix Dev Server Host Errors Behind an HTTPS Tunnel

Thumbnail
instawormhole.com
0 Upvotes

r/Frontend • • 12h ago

Self Taught Front End Dev that learns through hands on implementation looking for tips

0 Upvotes

Hi, I run a website through blogger and I'm highly fluent in HTML5. Slowly learning CSS3. I do use JS6 but I don't write any of the boiler plate as it's still too advanced for me. I was wondering if you guys have suggestions to help me learn CSS3 and JS6 syntax? I struggle with rote memorization, but if I can tie a syntax line to a visual output I find that I remember it easier. Still working on learning the jargon. Also if you have the time I would love suggestions to further improve my live code. I've been doing front end coding for roughly 1 year and 2 months.
KittyPaine/pstrophyguides.blogspot.com: A centralized collection of interactive video game trophy guides and walkthrough assets, tracking the evolution of custom HTML5, CSS3, and DOM-based templates designed to optimize usability, searchability, and performance for gamers.


r/Frontend • • 15h ago

Should our company use design tokens or a design.md file?

0 Upvotes

I've been asked by my peers to begin using a design md file but I was thinking that lack of structure would make it difficult to maintain. The benefits is that our codebase can begin using our design tokens but we would lack the structure of a .json file or something else I could easily parse.

I'm curious what others are doing and if anyone has had any success convincing their teams to use design tokens files as opposed to a markdown file to capture these types of style variables.

Also, is it common to use a design system across projects still or is it easier to get by without them now?


r/Frontend • • 1d ago

Team building event ideas that work for hybrid teams

3 Upvotes

Half the team is remote, half is in-office. Most classic team-building activities fall flat for one group or the other.

Looking for ideas that feel fair and actually build connection across locations. What’s worked for your hybrid teams?


r/Frontend • • 2d ago

EPAM Frontend Engineer – JavaScript Technical Interview | What to Expect?

16 Upvotes

Hi everyone,

I recently applied for a Frontend Engineer position at EPAM and have an upcoming JavaScript technical interview.

Has anyone recently gone through the technical interview process at EPAM, particularly for a Frontend Engineer or Senior Frontend Engineer position?

I would really appreciate some guidance on the following:

  • What should I expect during the technical interview?
  • Which JavaScript concepts should I focus on?
  • Do they ask live coding questions or problem-solving exercises?
  • Do they cover DSA, React, TypeScript or frontend system design?
  • How difficult is the interview, and how long does it usually last?
  • Are there any specific topics or resources you would recommend preparing?

I applied for a position in the UAE, but interview experiences from other locations would also be helpful.

If anyone has recently interviewed at EPAM, I would really appreciate it if you could share your experience.

Thank you in advance!


r/Frontend • • 2d ago

For listing pages, do you store filters in the URL or component state?

4 Upvotes

I was working through a common frontend scenario: a product listing page with search, category filters and sorting.

There are two approaches I've used:

1. Keep everything in component state

const [category, setCategory] = useState("all");
const [sort, setSort] = useState("newest");

2. Store shareable filters in the URL

const params = new URLSearchParams(window.location.search);

const category = params.get("category") || "all";
const sort = params.get("sort") || "newest";

The URL approach has some useful advantages:

  • Filters survive a page refresh.
  • Users can share the exact filtered view.
  • Browser back and forward navigation can restore previous filters.

But it also means keeping the URL and UI state in sync, which can introduce extra complexity.

I'm curious how others handle this in production.

Do you generally keep filters in component state, sync them with URL parameters, or use a dedicated state-management solution?

Where do you draw the line?


r/Frontend • • 2d ago

The V8 JavaScript Runtime Undermined My Constant-Time JavaScript Library

Thumbnail
soatok.blog
1 Upvotes

r/Frontend • • 3d ago

Analytics dashboard for visualizing typing-game-cli round

Thumbnail
gallery
5 Upvotes

r/Frontend • • 4d ago

Share Private Client Demos With Six-Digit Email Codes

Thumbnail
instawormhole.com
0 Upvotes

r/Frontend • • 4d ago

Automated JEV-assisted superfast HTML website builder (OS; MIT)

0 Upvotes

JEV is an ultra-fast classifier from TypeSafe, that answers multiple-choice questions, and I use it to arrange the pre-defined UI elements into a webpage based on the user's prompt. For example, for the prompt e.g. "Frontend for login form" JEV would return something like the following:

"surface": { "type": "choice", "choice": "app-login", "confidence": 1,

"probabilities": { "app-login": 1, "app-signup": 0, "website": 0, "app-checkout": 0, … all 14 etc... etc... } }

And here the "app-login" is a ready-made UI element but one can modify it later in the app manually. So this is what gets inserted into resulting HTML, among other things.

Besides JEV there are many other elements you can play manually with e.g. replace and resize images, add and link pages etc.

Repo: https://github.com/GPTchatly/Forma
Free (with limits) hosted Forma Editor

Many of the UI elements are by Markmead's Hyperui, and Cole Bemis' Feather icons; Fancy Components (by Daniel Petho); Velora UI (Aigars Silkalns); Cult UI (Nolly Studio)


r/Frontend • • 5d ago

Run a Frontend and API Together From One Tunnel File

Thumbnail
instawormhole.com
6 Upvotes

r/Frontend • • 7d ago

Importing Python into React components - wtf?

Thumbnail
gallery
22 Upvotes

I didn’t realise this was possible. Christ webassembly allows for some useful things.


r/Frontend • • 7d ago

Where the Disabled Button Got Its Rule

Thumbnail
hipuku.dev
21 Upvotes

r/Frontend • • 7d ago

Moving our accessibility testing from a paid tool to Claude Code (~500 URLs, WCAG 2.2 AA)

0 Upvotes

QA lead at a large org. We currently do accessibility testing for about 500 website urls to meet WCAG 2.2 AA (all 55 success criteria). And we use a paid tool (like Deque) that helps automate part of this and rest done manually with screen readers and keyboard testing.

Now we are looking to use our AI budget and Claude code to create skills for finding and fixing accessibility issues across our sites. My major trouble is that the scale is huge - not 5-10 URLs or even less than 50.

So would love to hear from anyone already using AI for accessibility to help me out with this journey:

  1. What do you use it for: finding issues, sorting real issues from false positives, or fixing them in code? Roughly how many URLs, under or over 100?
  2. How much of WCAG do you cover with Claude skills versus manually? How bad are the false positives? Asking because paid tool gave us less.
  3. Are you able to run scans at scale on automation infra (like CI) with Claude? And do you report coverage and trends to leadership - if so any dashboard?
  4. What are the challenges with AI skills vs paid tool like Deque or Level Access? Anything you would suggest to keep in mind or be aware upfront?

r/Frontend • • 7d ago

Ran a Lighthouse audit on tiktok.com desktop web: 14.9s LCP, 5.1s JS execution, and broken bfcache (Performance: 34/100)

0 Upvotes

I got curious about why TikTok's desktop web client feels so sluggish on initial load, so I ran a Chrome DevTools Lighthouse audit (v13.5.0) on tiktok.com to see what the frontend bundle and rendering pipeline actually look like.

The overall scores came back at 34 for Performance, 73 for Accessibility, 54 for Best Practices, and 77 for SEO.

On the Core Web Vitals and rendering side, First Contentful Paint takes 8.0s, Largest Contentful Paint hits 14.9s, Time to Interactive reaches 20.5s, and Total Blocking Time is 1,090 ms. Out of 8.5s of main-thread work, 5.1s goes purely to parsing and evaluating JavaScript. Almost all of that CPU time is spent on cache.react_dom (around 2.5s) and their anti-bot telemetry script webmssdk.js (around 1.8s).

The initial payload is 4,475 KiB, and there are a lot of classic frontend optimization misses in the build. It ships 236 KiB of unused JS on initial load (their regional cookie consent script alone has ~90 KiB of dead code), 26 KiB of unused CSS, and 65 KiB of legacy Babel transforms and polyfills for Baseline features like Array.prototype.includes, Promise.allSettled, and standard classes. Their security SDK (secsdk-lastest.umd.js) is also served unminified, the 400x400 PNG logo is scaled down to 112x112 via CSS, and the custom woff2 fonts are missing font-display rules.

Two other frontend details stood out. First, their privacy loader triggers repeated Permissions-Policy console errors by attaching unload listeners, which alongside Cache-Control: no-store completely breaks Back/Forward Cache restoration. Second, basic markup accessibility is rough: several header icon buttons and the search link have no aria-labels, four text inputs lack associated labels, and white text on their #fe2c55 buttons only hits a 3.68:1 contrast ratio.

I get that they prioritize their mobile apps, so desktop web is clearly an afterthought, but it is still wild seeing a major production React app ship unminified scripts and ES5 polyfills in 2026. Have any of you run into similar bottlenecks trying to keep Core Web Vitals green when security or product teams mandate heavy fingerprinting SDKs on initial load?


r/Frontend • • 9d ago

How do you prevent stale API results in search-as-you-type interfaces?

5 Upvotes
      if (!response.ok) {
        throw new Error("Request failed");
      }

      const data = await response.json();
      setResults(data);
    } catch (error) {
      if (error.name !== "AbortError") {
        console.error(error);
      }
    }
  }

  if (query.trim()) {
    search();
  }

  return () => controller.abort();
}, [query]);

I'm curious how other developers handle this in production.

  1. Is debouncing + AbortController enough for most search interfaces?
  2. Do you also use request IDs to ignore stale responses?
  3. How do you handle loading and error states when requests overlap?

Interested in hearing what patterns have worked well in real projects.


r/Frontend • • 10d ago

Computing with CSS Layout

Thumbnail
noscript.ing
27 Upvotes

r/Frontend • • 9d ago

Exporting a TanStack Table to Excel with grouped rows as real outlines

Thumbnail
rowpine.com
3 Upvotes
RowPine exports a grouped TanStack table to Excel and get a flat sheet with the totals typed in as numbers. Edit a cell and nothing adds up anymore.

Groups become Excel outline levels you can collapse, totals are SUBTOTAL formulas, and filters, sort and hidden columns carry over. PDF and CSV come out of the same table. 

r/Frontend • • 12d ago

Recreating Apple’s genie effect on the web: how the window bends into a funnel and drains into the dock

Thumbnail
uicraft.in
12 Upvotes

r/Frontend • • 12d ago

Agentic Coding: Bet on the Primitives

Thumbnail
robinwieruch.de
11 Upvotes

r/Frontend • • 13d ago

Is learning HTML, CSS and JavaScript still worth it for freelancing?

124 Upvotes

Hi everyone, I'm 14 years old.

I'm currently learning web development. I know the basics of HTML, CSS, and JavaScript, and I'm currently working on my first practice landing page. It's a custom-coded website about instant ramen noodles.

In this project, I'm also trying to learn new things, like using Figma properly. I also plan to experiment with some AI editor tools, learn basic SEO, and try free hosting.

After finishing this project, I plan to make another project using WordPress, probably a multi-page website. Through this project, I want to learn more about WordPress and how to build websites with it. I also plan to work on one more project after that.

But there's one thing I've been wondering about.

When I started my first project, I thought I wasn't wasting my time learning HTML, CSS, and JavaScript. But now I see that many websites and landing pages are made using WordPress, website builders, or AI tools.

I also see a lot of posts from clients and agencies looking for someone who knows WordPress, CSS, Tailwind, SEO, and other tools, or someone who already has experience building websites.

So I sometimes wonder if I'm making a mistake or wasting my time learning HTML, CSS, and JavaScript, because my goal is to earn money through freelancing and support my other passions, like manga creation and game development.

I know freelancing involves a lot of other things too, like client communication, understanding requirements, and other skills.

I just wonder what advantages I can get from learning HTML, CSS, and JavaScript as a freelancer. What kinds of things can I do with these skills, and what else should I learn?

Thanks if you read all of this!


r/Frontend • • 12d ago

Publishing a JS framework

5 Upvotes

Im working on a project for myself. Its an unreviewed, unaudited and far from finished. It started of as a person curiosity and evolved from there.

Im asking because if i publish something on NPM, there are strict controls around versioning for which i havent burdened myself on my own projects (but clearly important when making something for a wider community). I also wonder if im overlooking any other details.

I wonder what best practices there are for something like this. Should i be publishing new versions with CI/CD? Are there any tips or advice on doing this in the modern js package ecosystem?


r/Frontend • • 14d ago

We've been building our own JavaScript framework and would love some feedback

5 Upvotes

Hey everyone,

We've been working on Avenx.js, an open-source JavaScript framework focused on compiler-driven reactivity, direct DOM updates and keeping the runtime lightweight.

The idea is to explore a different approach to building frontend applications without relying on a Virtual DOM. We're still actively developing the framework and have been working on improving its compiler, reactivity system and overall developer experience.

So far, the project has reached 192 forks and 150 listed contributors, which is pretty exciting for us.

We're curious what other JavaScript developers think about the approach.

  • Does the architecture make sense to you?
  • What's missing or could be improved?
  • Would you consider using something like this in a project?

We're especially interested in honest criticism and suggestions. There's still a lot to build, and fresh perspectives are always valuable.

GitHub Repository

Official Website

Thanks for taking a look!