Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove JS-conditional classes #3222

Merged
merged 2 commits into from
Mar 6, 2025
Merged

Conversation

adamaveray
Copy link
Contributor

Currently a no-js class is added to the <html> element, which is immediately replaced with a js class to allow targeting styles to whether JavaScript is or isn't enabled. This works well however has a few drawbacks:

  1. It is mostly incompatible with server-side-rendered frameworks. For example, using a React-based SSR framework causes warnings due to a props mismatch on hydration, so the only safe way to perform the class swapping would be waiting until hydration has completed leading to FOUT.

  2. Requires coordination of HTML and CSS so could not reliably be part of e.g. a CSS-only library or a WordPress plugin without control of the site's theme.

  3. Requires managing an inline script which on its own is additional complexity and also complicates configuring a JavaScript content security policy.

Things have progressed since the class-based approach was developed, and there is now a scripting media condition available to achieve the same thing without needing any HTML nor JS.

The scripting media condition reached Baseline 2023 support so it is a little on the edge of broad support, however considering the drawbacks of the current approach and the entire principle of progressive enhancement that adjusting styles based on JS availability is built on I think it can begin to be adopted in new projects and H5BP can start directing developers towards adopting it as a new best practice compared to the previous class-based approach.

I've added a mention of the new approach to the documentation including examples & references. If this proposal is accepted I can also open a PR in H5BP's main.css project to add an example like the existing responsive media queries if the maintainers are interested.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@coliff
Copy link
Member

coliff commented Mar 6, 2025

Great PR - thank you! I fully agree that this should be removed.. I was thinking about this just yesterday actually.

@coliff coliff requested a review from roblarsen March 6, 2025 15:24
@roblarsen
Copy link
Member

I missed removing it when I removed Modernizr THANKS!

@roblarsen roblarsen merged commit c37e7b7 into h5bp:main Mar 6, 2025
8 checks passed
@roblarsen
Copy link
Member

I might cut an interim release.

@coliff
Copy link
Member

coliff commented Mar 6, 2025

@roblarsen - there's a lot of docs stuff I'd like to update... shall we set a 'deadline' to get it updated? next week sometime?

@roblarsen
Copy link
Member

Sounds good. I've got time this week

@adamaveray adamaveray deleted the feature/remove-no-js branch March 6, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants