Return to Snippet

Revision: 56144
at March 12, 2012 10:06 by EvanHahn


Initial Code
<html class="no-js">

<head>

	<script>
	document.documentElement.className = document.documentElement.className.replace(/\bno-js\b/g, '') + ' js ';
	</script>

	<!-- ...  -->

Initial URL


Initial Description
Add the "no-js" class to your topmost html element, so you can use CSS to style JavaScript-free pages. This snippet will then replace that tag with "js", allowing you to style pages with JavaScript.

The excellent [HTML5 Boilerplate](http://html5boilerplate.com/) puts `no-js` in the `<html>` element and then uses [Modernizr](http://www.modernizr.com/) to replace it with `js`. If you don't want to use all of that stuff, this snippet does the same thing.

Initial Title
Remove "no-js" class from html tag, add "js" class

Initial Tags
css, javascript, class, html

Initial Language
HTML