Frontend Masters Boost RSS Feed https://frontendmasters.com/blog Helping Your Journey to Senior Developer Wed, 22 Oct 2025 22:53:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.3 225069128 For Your Convenience, This CSS Will Self-Destruct https://frontendmasters.com/blog/for-your-convenience-this-css-will-self-destruct/ https://frontendmasters.com/blog/for-your-convenience-this-css-will-self-destruct/#respond Wed, 22 Oct 2025 22:53:33 +0000 https://frontendmasters.com/blog/?p=7492 In A Progressive Enhancement Challenge, I laid out a situation where the hardest thing to do is show a button you never want to show at all if the JavaScript loads and executes properly. I wrote of this state:

It seems like the ideal behavior would be “hide the interactive element for a brief period, then if the relevant JavaScript isn’t ready, show the element.” But how?! We can’t count on JavaScript for this behavior, which is the only technology I’m aware of that could do it. Rock and a hard place!

Scott Jehl blogged For Your Convenience, This CSS Will Self-Destruct, including an idea that fits the bill. It’s a @keyframes animation that hides-by-default then fades in after 2s. With this in place, in your JavaScript, you’d include a bit that ensures the button stays hidden, with a new class. That’s a win!

… a site’s JavaScript files can often take many seconds to load and execute, so it’s great to have something like this ready to bail out of anything fancy in favor of giving them something usable as soon as possible.

]]>
https://frontendmasters.com/blog/for-your-convenience-this-css-will-self-destruct/feed/ 0 7492
A Progressive Enhancement Challenge https://frontendmasters.com/blog/a-progressive-enhancement-challenge/ https://frontendmasters.com/blog/a-progressive-enhancement-challenge/#comments Fri, 03 Oct 2025 16:06:19 +0000 https://frontendmasters.com/blog/?p=7324 Let’s say you’ve got some interactive element.

This element works perfectly fine in just HTML, which is the foundation of progressive enhancement.

And now, in your JavaScript, the functionality this button provides isn’t really necessary anymore, and your plan is to hide this element.

What is the best way to accomplish this?

I think it’s good to think of this abstractly, but if what I’ve presented above is so abstract that it makes it hard to think about, here are some examples:

  1. A “Load More” anchor link that loads the next set of items (i.e. <a href="?page=3">Load More</a>) which you don’t need after JavaScript loads because you’ve implemented an infinite scroll UX.
  2. A “Save” button that saves user-entered information on the page to the database (i.e. <button onclick="save()">Save</button>) which you don’t need after JavaScript loads because you’ve implemented auto-saving functionality.

A “js” Class

A classic approach to this is hiding the button when you know JavaScript is available. You put something like this pretty early in your HTML:

<script>
  document.documentElement.classList.add("js");
</script>

If this executes, you’ve proven that JavaScript is available, so you hide the button:

html.js {
  .save-button {
    display: none;
  }
}

As appealing as this looks, it may not be the catch-all perfect solution.

Downsides:

  • You’ve proven here that JavaScript is available, but you aren’t checking if the particular JavaScript that does the auto-saving is loaded and has run successfully. You can probably account for that by applying a more specific class just for this situation and applying it after the code that implements auto-saving.
  • The longer you (necessarily) have to wait for the JavaScript to be done, the longer the button is visible on the screen. This is likely to cause a “flash” of the button being there where is doesn’t need really need to be.

On States

This question came up for me from a ShopTalk Show listener Tibor Leupold writing in asking about it. He was concerned about layout shift as a result of hiding the element(s) as well as the awkward UX.

Let’s get this one out of the way: couldn’t you just… leave the interactive elements there but change their functionality when the JavaScript loads? Maybe? Probably? That’s skirting the question though. Let’s assume the web is a big place with an unknowable amount of situations and that this particular situation of needing/wanting to hide an element with minimal impact is a reasonable one.

A way to think about our needs here is that there are three states to concern ourselves with:

  1. JavaScript is unavailable entirely
  2. Before the relevant JavaScript has loaded and executed
  3. The relevant JavaScript is loaded and executed successfully

No JS

We’re probably not going to hide the button by default, as we don’t have a mechanism for un-hiding it in a no-JS situation. So we basically don’t need to do anything to accomplish this state, just have the interactive element on the page and functional in HTML.

In the reverse situation, where you have an element on the page that only works with JavaScript, you can hide it in a no-JS situation like:

<noscript>
  <style>
    .js-only-interactive-element {
      display: none;
    }
  </style>
</noscript>

Before JS Loaded

This is the hardest state. In this state, perhaps we know that JavaScript is available, but we don’t know how long it’s going to take or even if the JavaScript we care about is going to execute successfully.

It seems like the ideal behavior would be “hide the interactive element for a brief period, then if the relevant JavaScript isn’t ready, show the element.” But how?! We can’t count on JavaScript for this behavior, which is the only technology I’m aware of that could do it. Rock and a hard place!

Maybe there is some extremely exotic technique involving HTML streaming that could delay the “send” of the interactive element down from the network for that brief blocking period? That’d be wild.

Another thing I think of is the behavior of font-display: block;. This is about the behavior of loading custom fonts via CSS @font-face. It can tell the browser how to behave while the custom font it loading. Do you want the browser to wait to see if the custom font loads and then “swap” to it? You’ve got options. The block value says:

Gives the font face a short block period and an infinite swap period.

Seems related! Maybe there is a way to bring this kind of behavior to progressive enhancement elements to mimic the behavior we want: “hide the interactive element for a brief period, then if the relevant JavaScript isn’t ready, show the element.” Help us, web platform.

JS Ready

This is a fairly straightforward state, but it’s the cause of the “flash” and potential layout shift.

function setUpInfiniteScroll() {
  // do all the work

  // at the end, say it's ready
  document.documentElement.classList.add("infinite-scroll-ready");
}
.infinite-scroll-ready {
  .load-more-link {
    display: none;
  }
}

The problem here is: how long is that “Load More” link going to be on the page before it disappears? Is it fairly instant? A few hundred milliseconds? Eight seconds? Never? (You really can’t know.)

Also: will the layout shift it triggers cause the user to potentially click on something they didn’t mean to? Maybe hiding can be done without the layout shift?

.infinite-scroll-ready {
  .load-more-link {
    visibility: hidden;
  }
}

Is there a better way?

I feel like people have been thinking about progressive enhancement for a couple decades now. Is there an extremely clean/simple way to do this that I’m just not seeing?

]]>
https://frontendmasters.com/blog/a-progressive-enhancement-challenge/feed/ 2 7324
Deciding on Using a Browser Feature via Baseline https://frontendmasters.com/blog/deciding-on-using-a-browser-feature-via-baseline/ https://frontendmasters.com/blog/deciding-on-using-a-browser-feature-via-baseline/#respond Tue, 04 Jun 2024 15:51:00 +0000 https://frontendmasters.com/blog/?p=2526 Google has this little widget called Baseline. Here’s a screenshot example:

The idea is for it to accompany a web platform feature so you can have a sense of what browsers support it. Web developers are rightfully skeptical of new web tech, wanting to know when they can actually use a feature, so this is helpful.

But there is crucial information missing here. Developers don’t decide to use a feature only based on browser support, but also:

  1. Based on if that feature could be considered a progressive enhancement
  2. Based on if that feature has a polyfill

Jeremy Keith brought this up and has a great point.

Not all browser features work the same way. For features that work as progressive enhancements you don’t need to wait for them to be widely available.

For example, if you’re looking at the View Transitions API, you’ll see:

And perhaps go awww bummer I can’t use it! But that would be wrong. You can use it. The API is designed such that you can write code that will use it if it’s available or not if it’s not. It’s really not a big deal.

That’s a beautiful part of progressive enhancement, as Jeremy says:

… there’s a real irony in a common misunderstanding around progressive enhancement: some people seem to think it’s about not being able to use advanced browser features. In reality it’s the opposite. Progressive enhancement allows you to use advanced browser features even before they’re widely supported.

]]>
https://frontendmasters.com/blog/deciding-on-using-a-browser-feature-via-baseline/feed/ 0 2526
Project Idea: Convert a PDF Form to a Web Form https://frontendmasters.com/blog/project-idea-convert-a-pdf-form-to-a-web-form/ https://frontendmasters.com/blog/project-idea-convert-a-pdf-form-to-a-web-form/#respond Fri, 22 Mar 2024 22:01:22 +0000 https://frontendmasters.com/blog/?p=1387 Jermey Keith visited a school doing this exact project, and I thought it was a great idea for learning:

There’s a specific module his students are partaking in that’s right up my alley. They’re given a PDF inheritance-tax form and told to convert it for the web.

You could make doing this job really well a whole full-stack experience, but it starts with a great front end.

I genuinely get excited by the potential for progressive enhancement here. Sure, there’s the obvious approach of building in layers; HTML first, then CSS, then a sprinkling of JavaScript. But there’s also so much potential for enhancement within each layer.

Got your form fields marked up with the right input types? Great! Now what about autocompleteinputmode, or pattern attributes?

Got your styles all looking good on the screen? Great! Now what about print styles?

Got form validation working? Great! Now how might you use local storage to save data locally?

I also love how with web forms, you don’t have to look at fields that are only required in certain circumstances. That’s implemented with progressive disclosure.

]]>
https://frontendmasters.com/blog/project-idea-convert-a-pdf-form-to-a-web-form/feed/ 0 1387