r/Frontend • • 13h 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 • • 16h 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 • • 6h ago

Fix Dev Server Host Errors Behind an HTTPS Tunnel

Thumbnail
instawormhole.com
0 Upvotes

r/Frontend • • 9h 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!