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

Save Automatically?

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

              
                <!-- Updated 2023 -->

<div class="mask">
		<div class="container">
			<section class="list" aria-hidden="true">
				<header class="header list__header">
					<span class="header__name">Conversations</span>
				</header>
				<div class="chatlist">
					<button id="chat1" class="chat" tabindex="-1">
						<span class="chat__user">Nadia</span>
						<span class="chat__message">How is it going?</span>
					</button>
					<button id="chat2" class="chat" tabindex="-1">
						<span class="chat__user">Susan</span>
						<span class="chat__message">
							<span class="chat__sent">
								<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
								<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
							</span>
							The exam was very easy, don't you think?
						</span>
					</button>
					<button id="chat3" class="chat" tabindex="-1">
						<span class="chat__user">Mark</span>
						<span class="chat__message">
							<span class="chat__sent">
								<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
								<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="20 6 9 17 4 12"></polyline></svg>
							</span>
							Hey, did you see what happened to the car?
						</span>
					</button>
				</div>
			</section>
			<section class="conversation" aria-hidden="false">
				<header class="header">
					<button class="btn btn--list" title="Show chat list" tabindex="0">
						<svg class="btn__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="8" y1="6" x2="21" y2="6"></line><line x1="8" y1="12" x2="21" y2="12"></line><line x1="8" y1="18" x2="21" y2="18"></line><line x1="3" y1="6" x2="3.01" y2="6"></line><line x1="3" y1="12" x2="3.01" y2="12"></line><line x1="3" y1="18" x2="3.01" y2="18"></line></svg>
					</button>
					<div class="header__info">
						<span class="header__status"></span>
						<span class="header__name">Nadia</span>
					</div>
					<div class="header__actions">
						<button class="btn btn--camera" tabindex="0" title="Start videocall">
							<svg class="btn__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="23 7 16 12 23 17 23 7"></polygon><rect x="1" y="5" width="15" height="14" rx="2" ry="2"></rect></svg>
						</button>
						<button class="btn btn--close" tabindex="0" title="Close chat">
							<svg  class="btn__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
						</button>
					</div>
				</header>
				<div class="messages">
					<div class="messages__bubble messages__bubble--left">
						<span class="messages__text">Hey!</span>
					</div>
					<div class="messages__bubble messages__bubble--left">
						<span class="messages__text">How is it going?</span>
					</div>
				</div>
				<footer class="footer">
					<input type="text" class="footer__input" placeholder="Write a message..." tabindex="0" autocomplete="off">
					<button class="btn btn--send" title="Send message" tabindex="0">
						<svg class="btn__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>
					</button>
				</footer>
			</section>
		</div>
	</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Poppins:[email protected];700&display=swap');


// Resets
* {
	margin: 0;
	padding: 0;
	box-sizing: border-box;
	outline: 0;
}

button {
	border: 0;
	background-color: transparent;
	cursor: pointer;
}



// Variables
$gray-9: hsl(0, 0%, 13%);
$gray-8: hsl(0, 0%, 26%);
$gray-7: hsl(0, 0%, 38%);
$gray-6: hsl(0, 0%, 46%);
$gray-5: hsl(0, 0%, 62%);
$gray-4: hsl(0, 0%, 74%);
$gray-3: hsl(0, 0%, 88%);
$gray-2: hsl(0, 0%, 93%);
$gray-1: hsl(0, 0%, 96%);
$white: hsl(0, 0%, 100%);
$primary: hsl(226, 56%, 54%);
$primary-darker: hsl(226, 56%, 35%);
$secondary: hsl(46, 56%, 54%);
$secondary-darker: hsl(46, 56%, 35%);
$green: hsl(120, 100%, 26%);



// Global scope classes to use with JS
div.minimize {
	height: 40px;
}

div.list--active {
	transform: translateX(0);

	@media (max-width: 500px) {
		transform: translateX(50%);
	}
}



// Everything else
body {
	height: 100vh;
	position: relative;
	font-family: "Poppins", sans-serif;
	overflow-y: hidden;
	background: linear-gradient(305deg, hsl(178, 84%, 43%) 0%, hsl(284, 92%, 74%) 100%);
}



.mask {
	width: 300px;
	height: 400px;
	overflow: hidden;
	position: absolute;
	bottom: 0;
	right: 5rem;
	border-top-left-radius: 10px;
	border-top-right-radius: 10px;
	animation: appear 1s ease-in 0s;
	box-shadow: 0 10px 20px hsla(0, 0%, 0%, .15), 0 3px 6px hsla(0, 0%, 0%, .10);
	transition: height 400ms cubic-bezier(.65,.05,.36,1);

	@media (max-width: 500px) {
		right: 0;
		width: auto;
		height: 100%;
		border-radius: 0;
	}
}



.container {
	width: 600px;
	height: 400px;
	display: flex;
	flex-direction: row;
	transform: translateX(-300px);
	transition: transform 500ms cubic-bezier(.65,.05,.36,1);

	@media (max-width: 500px) {
		width: 100%;
		height: 100%;
		transform: translateX(0);
	}
}



.btn {
	width: 40px;
	height: 40px;
	transition: all 100ms ease-in-out;

	&:hover, &:focus {
		background-color: $primary;

		.btn__icon {
			color: $white;
		}
	}

	&__icon {
		width: 1.25rem;
		height: 1.25rem;
		color: $primary;
		vertical-align: middle;
	}

	&--send {
		border-radius: 3px;
		//flex-grow: 1;
	}
}



.list, .conversation {
	width: 300px;
	height: 400px;
	display: flex;
	flex-direction: column;

	@media (max-width: 500px) {
		width: 100vw;
		height: 100vh;
	}
}



.header {
	min-height: 40px;
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	align-items: center;
	border-bottom: 1px solid $gray-3;
	background-color: $gray-1;

	&__actions {
		display: flex;
		flex-direction: row;
	}

	&__info {
		display: inline-flex;
		flex-direction: row;
		align-items: center;
		flex-grow: 1;
		padding-left: 0.8rem;
		color: hsl(226, 48%, 27%);
		border-left: 1px solid hsl(210, 14%, 83%);
	}

	&__status {
		width: 8px;
		height: 8px;
		border-radius: 50%;
		background-color: hsl(97, 81%, 48%);
		margin-right: 0.4rem;
	}

	&__name {
		font-weight: 700;
		color: $primary;
	}
}



.messages {
	height: 100%;
	position: relative;
	display: flex;
	flex-direction: column;
	padding: 0.8rem;
	overflow-y: auto;
	background-color: $gray-2;

	&__bubble {
		display: inline-flex;
		flex-direction: row;
		margin-bottom: 0.8rem;
	}

	&__bubble--left {
		position: relative;
		justify-content: start;

		&:before {
			content: '';
			position: absolute;
			z-index: 0;
			bottom: -7px;
			left: 0;
			width: 8px;
			height: 8px;
			border-bottom-right-radius: 10px;
			background-color: $primary-darker;
		}
	
		.messages__text {
			position: relative;
			z-index: 1;
			max-width: 85%;
			color: $gray-1;
			background-color: $primary;
			border-bottom-left-radius: 0;
		}
	}
	
	&__bubble--right {
		position: relative;
		justify-content: end;

		&:before {
			content: '';
			position: absolute;
			z-index: 0;
			bottom: -7px;
			right: 0;
			width: 8px;
			height: 8px;
			border-bottom-left-radius: 10px;
			background-color: $secondary-darker;
		}
	
		.messages__text {
			position: relative;
			z-index: 1;
			max-width: 85%;
			color: $gray-9;
			background-color: $secondary;
			border-bottom-right-radius: 0;
		}
	}

	&__text {
		border-radius: 3px;
		padding: 0.6rem;
		overflow-wrap: break-word;
	}
}



.footer {
	display: flex;
	flex-direction: row;
	justify-content: space-between;
	padding: 0.8rem;
	border-top: 1px solid $gray-3;
	background-color: $gray-1;
	
	&__input {
		width: 80%;
		padding: 0.4rem 0.4rem 0.4rem 0.6rem;
		border-radius: 3px;
		border: 1px solid $gray-3;
		font-family: 'Poppins', sans-serif;
		transition: all 100ms ease-in-out;

		@media (max-width: 500px) {
			width: 100%;
			margin-right: 1rem;
		}
		
		&:focus {
			border: 1px solid $primary;
			box-shadow: inset 0 0 3px hsla(0, 0%, 13%, .6);
		}
	}	
}



.list {
	& .header {
		padding-left: 0.8rem;
	}
}



.chatlist {
	height: 100%;
	background-color: $gray-2;
	overflow-y: auto;
	padding: 0.8rem;
}



.chat {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: start;
	padding: 0.8rem;
	margin-bottom: 1rem;
	font-family: 'Poppins', sans-serif;
	background-color: $gray-1;
	box-shadow: 0 1px 1px hsla(0, 0%, 0%, .2);
	border-radius: 3px;
	border: 1px solid $gray-3;
	cursor: pointer;
	transition: all 100ms ease-in-out;
	
	&:hover, &:focus {
		border: 1px solid $primary;
		box-shadow: 0 1px 3px hsla(0, 0%, 0%, .3);
	}

	&__user {
		display: block;
		font-size: 1rem;
		font-weight: 700;
		color: $gray-9;
	}
	
	&__message {
		display: flex;
		flex-direction: row;
		align-items: center;
		width: 100%;
		font-size: 1rem;
		font-weight: 400;
		color: $gray-7;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	&__sent {
		display: flex;
		flex-direction: row;

		svg {
			width: 1rem;
			height: 1rem;
			stroke: $green;
		}
	}
	
	&__sent svg:last-of-type {
		margin: 0 0.3rem 0 -0.7rem;
	}
}



@keyframes appear {
	1% {
		transform: translateY(30px);
		opacity: 0;
	}

	25% {
		transform: translateY(-15px);
	}

	65% {
		transform: translateY(10px);
		opacity: 1;
	}

	80% {
		transform: translateY(-5px);
	}
	
	100% {
		transform: translateY(0);
	}
}
              
            
!

JS

              
                function addMessageToConversation () {

	// Save written message from input.
	let messageText = document.querySelector('.footer__input').value;

	// If message is empty...
	if (messageText.trim().length == 0) {

		return false;
		
	} else {

		// Add the message with the bubble to the conversation.
		document.querySelector('.messages').insertAdjacentHTML('beforeend', `<div class="messages__bubble messages__bubble--right"><p class="messages__text">${messageText}</p></div>`);

		// Clear the input.
		document.querySelector('.footer__input').value = '';

		// Return focus to input.
		//document.querySelector('.footer__input').focus();
	}
}



function showChatList () {

	document.querySelector('.container').classList.toggle('list--active');

	// Disable keyboard navigation for the conversation view.
	document.querySelectorAll('.conversation [tabindex="0"]').forEach((element) => {

		element.setAttribute('tabindex', '-1');

	});

	// Enable the keyboard navigation for the chat list.
	document.querySelectorAll('.list [tabindex="-1"]').forEach((element) => {

		element.setAttribute('tabindex', '0');

	});

	// Toggle aria-hidden in each section
	document.querySelector('.list').setAttribute('aria-hidden', false)
	document.querySelector('.conversation').setAttribute('aria-hidden', true)

	// Focus on first chat.	
	// setTimeout(() => {
	// 	document.querySelector('#chat1').focus();
	// }, 350);

}



function showConversation () {

	document.querySelector('.container').classList.toggle('list--active');

	// Enable the keyboard navigation for the conversation view.
	document.querySelectorAll('.conversation [tabindex="-1"]').forEach((element) => {

		element.setAttribute('tabindex', '0');

	});

	// Disable keyboard navigation for the chat list.
	document.querySelectorAll('.list [tabindex="0"]').forEach((element) => {

		element.setAttribute('tabindex', '-1');

	});

	// Toggle aria-hidden in each section
	document.querySelector('.list').setAttribute('aria-hidden', true)
	document.querySelector('.conversation').setAttribute('aria-hidden', false)

	/* Focus to input with timeout because otherwise the focus happens so fast that it breaks the transition and the conversation view goes out of the container. */
	setTimeout(() => {
		document.querySelector('.footer__input').focus();
	}, 350);
}



function minimizeChat () {

	document.querySelector('.mask').classList.toggle('minimize');

}



// Event listeners.
document.querySelector('.btn--list').addEventListener('click', showChatList);
document.querySelectorAll('.chat')
	.forEach((element) => element.addEventListener('click', showConversation));
document.querySelectorAll('.header__info, .list__header')
	.forEach((element) => element.addEventListener('click', minimizeChat));
document.querySelector('.btn--send').addEventListener('click', addMessageToConversation);

// Send message with enter key.
document.querySelector('.footer__input').addEventListener('keydown', (e) => {

	if (e.key == 'Enter') {

		addMessageToConversation();

	} else {

		return false;
		
	}
});
              
            
!
999px

Console