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

              
                <div class="grid-container resize">
	<header>User Name</header>
	<main>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem, ipsum dolor.</p>
		</div>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem ipsum dolor sit, amet consectetur adipisicing elit. Laborum doloremque tempora molestias repellat, ad unde reprehenderit, sint cumque libero quam similique reiciendis aperiam id aliquam, tempore earum nemo sequi recusandae.</p>
		</div>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem ipsum dolor sit amet.</p>
		</div>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem </p>
		</div>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem, ipsum dolor.</p>
		</div>
		<div class="msg">
			<span>上午 12:52</span>
			<p>Lorem </p>
		</div>
	</main>
	<footer>
		<textarea placeholder="輸入訊息"></textarea>
	</footer>
</div>

<button id="color-scheme-toggle" onclick="toggleColorMode()">
	<span id="toggle-icon" class="material-icons">dark_mode</span>
	<span id="toggle-text">Switch to Dark Theme</span>
</button>
              
            
!

CSS

              
                /*  -------- 預設 --------  */
:root, .light-mode {
	--gray-000:  #fff;
	--gray-100:  #f9f9fd;
	--gray-200:  #e8edf4;
	--gray-300:  #DBE2E7;
	--gray-400:  #CED7E0;
	--gray-500:  #A9B3BD;
	--gray-600:  #677889;
	--gray-700:  #495562;
	--gray-800:  #2D4155;
	--gray-900:  #1A2632;
	--gray-1000: #000;
}

/*  -------- 當使用者偏好深色模式 --------  */
@media (prefers-color-scheme: dark) {
	:root{
		--gray-000:  #000;
		--gray-100:  #1A2632;
		--gray-200:  #2D4155;
		--gray-300:  #495562;
		--gray-400:  #677889;
		--gray-500:  #A9B3BD;
		--gray-600:  #CED7E0;
		--gray-700:  #DBE2E7;
		--gray-800:  #e8edf4;
		--gray-900:  #f9f9fd;
		--gray-1000: #fff;
	}
}
.dark-mode{
	--gray-000:  #000;
	--gray-100:  #1A2632;
	--gray-200:  #2D4155;
	--gray-300:  #495562;
	--gray-400:  #677889;
	--gray-500:  #A9B3BD;
	--gray-600:  #CED7E0;
	--gray-700:  #DBE2E7;
	--gray-800:  #e8edf4;
	--gray-900:  #f9f9fd;
	--gray-1000: #fff;
}
	

/* basic style */

:root {
	--transition-base: .3s;
}


#color-scheme-toggle{
	display: inline-block;
	margin-top: 2rem;
	padding: 1rem 1.5rem;
	color: var(--gray-700);
	cursor: pointer;
	background-color: transparent;
	border: 1px solid currentcolor;
	border-radius: 2rem;
	transition: var(--transition-base);
	&:hover{
		color: var(--gray-900);
		background-color: var(--gray-200);
	}
	.material-icons, &:after{
		display: inline-block;
		vertical-align: middle;
	}
}




/* other style */

* {
	box-sizing: border-box;
}

html{
	font-size: 85%;
}

body{
	padding: 1rem;
	background: var(--gray-100);
}

.grid-container{
	background: var(--gray-200);
	&, textarea{
		color: var(--gray-800);
	}
}

header, main, textarea{
	padding: 1rem;
}

header{
	background: var(--gray-300);
}

main{
	overflow: auto;
}

.msg{
	display: flex;
	justify-content: flex-end;
	align-items: flex-end;
	margin-top: 1.5rem;
	& span {
		font-size: 80%;
		white-space: nowrap;
		opacity: .5;
	}
	& p {
		background: #67DC6F;
		padding: .75rem 1rem;
		margin: 0;
		margin-left: .5rem;
		color: #373737;
		border-radius: 1.25rem;
	}
}

footer{
	display: flex;
	border-top: 1px solid var(--gray-400);
}

textarea{
	background: transparent;
	flex-grow: 1;
	resize: none;
	margin-bottom: 1rem;
	&, &:focus{
		border: 0;
		outline: 0;
	}
	&::placeholder{
		color: var(--gray-500);
	}
}

.resize{
	position: relative;
	resize: both;
	overflow: auto;
	width: 300px;
	height: 500px;
	border-radius: .5rem;
	&:before, &:after{
		position: absolute;
	}
	&:before{
		content: "拉拉我👇";
		right: .5rem;
		bottom: 1rem;
		color: var(--gray-500);
	}
	&:after{
		content: "";
		right: 0;
		bottom: 0;
		display: block;
		border: 1rem solid;
		border-top-color: transparent;
		border-left-color: transparent;
		border-right-color: #ff09;
		border-bottom-color: #ff09;
	}
}

.grid-container{
	display: grid;
	grid-template-rows: min-content auto min-content;
	align-items: stretch;
}
              
            
!

JS

              
                // https://stackoverflow.com/questions/56393880/how-do-i-detect-dark-mode-using-javascript

const body = document.body;
const toggleIcon = document.getElementById("toggle-icon");
const toggleText = document.getElementById("toggle-text");

const iconString = ["light_mode", "dark_mode"];
const textString = ["Switch to Light Theme", "Switch to Dark Theme"];

// 套用初始文字
if (window.matchMedia('(prefers-color-scheme: dark)').matches){
	toggleIcon.innerText = iconString[0];
	toggleText.innerText = textString[0];
} else {
	toggleIcon.innerText = iconString[1];
	toggleText.innerText = textString[1];
}

function toggleString() {
    toggleIcon.innerText = (toggleIcon.innerText === iconString[0]) ? iconString[1] : iconString[0];
    toggleText.innerText = (toggleText.innerText === textString[0]) ? textString[1] : textString[0];
}

function toggleColorMode() {
	if(window.matchMedia('(prefers-color-scheme: dark)').matches){
		body.classList.toggle("light-mode");
	} else {
		body.classList.toggle("dark-mode");
	}
	toggleString();
}
              
            
!
999px

Console