Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body id="mainBody">
	<div class="btn-group">
		<a target="_blank" href="https://www.insidethediv.com/how-to-make-website-dark-mode-css-html-javascript-example">More</a>
		
		<button onclick="MakeSiteDark()" id="btnMakeDark">Dark</button>
		<button onclick="MakeSiteWhite()" id="btnMakeWrite">White</button>
		
	</div>
	<div class="container">
		<h1>How to make website dark mode CSS HTML JavaScript Code Pen</h1>
		Lorem ipsum dolor sit amet consectetur adipisicing elit. Illo praesentium eius quaerat molestiae eveniet, rem facilis explicabo iusto aliquid amet repellendus recusandae accusantium cumque expedita eligendi, repudiandae commodi. Laudantium molestiae eveniet veritatis provident possimus enim. Tempora, voluptatum. Nobis doloribus blanditiis beatae, odio libero, fuga! Eaque aspernatur, atque quasi, vel sapiente natus fuga. Quidem eaque pariatur earum quae fuga consectetur excepturi eligendi recusandae debitis ipsam dolore, optio est voluptates blanditiis asperiores officia eum rem ipsa possimus reiciendis. Dolorem impedit incidunt, nesciunt ea dignissimos molestiae distinctio praesentium architecto rem quidem culpa ab? Officiis, est? Maxime itaque iusto veritatis maiores. Officiis eaque, ex!
	</div>
</body>
              
            
!

CSS

              
                .btn-group{
	position: fixed;
	top: 10px;
	right: 10px;
}
.btn-group button{
	font-size: 17px;
	padding: 2px 20px;
	cursor: pointer;
	border: 0px;
	box-shadow: 0px 0px 1px 2px #eee;
	cursor: pointer;
}

.btn-group #btnMakeDark{
	background: #333;
	color: #fff;
}

.btn-group #btnMakeWrite{
	background: #fff;
	text-color: #333;
}

.container{
	margin-top: 50px;
}

.dark-body{
	background: #000;
	color: #fff;
}

.white-body{
	background: #fff;
	color: #000;
}
              
            
!

JS

              
                function MakeSiteDark(){
	var mainBody = document.getElementById('mainBody');
	mainBody.classList.remove('white-body');
	mainBody.classList.add('dark-body');
}

function MakeSiteWhite(){
	var mainBody = document.getElementById('mainBody');
	mainBody.classList.remove('dark-body');
	mainBody.classList.add('white-body');
}
              
            
!
999px

Console