HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<ul class="rounded-messages reveal-messages messages-width-medium msg-animation-fast">
<li class="left">Hello!</li>
<li class="time"><strong>Yesterday</strong> 12:25 pm</li>
<li class="right-msg">Hey, how are you?</li>
<li>I'm doing well</li>
<li>What about you?</li>
<li class="right-msg">Hardy har har.</li>
<li class="right-msg"><img src="https://tse4.mm.bing.net/th?id=OIP.Ma51851cded2f1d4bf2da6ff1e98df912o0&pid=15.1">I'm doing great! ;)</li>
<li class="right-msg">LOL</li>
<li class="time"><strong>Yesterday</strong> 3:44pm</li>
<li>Heck, yea! FOOTBALL!</li>
<li>😁</li>
</ul>
<br/><br/>
$left-bg: #E3E2DF;
$left-color: #292929;
$right-bg: #27AE60;
$right-color: #F8F8F8;
$time-color: #555555;
body { padding: 0px; margin: 0px; }
.messages-width-small { width: 300px; }
.messages-width-medium { width: 400px; }
.messages-width-large { width: 500px; }
.messages-width-full { width: 100%; }
/* Basic List Styling */
ul.rounded-messages
{
list-style: none;
display: inline-block;
overflow: hidden;
font-size: 16px;
padding: 10px;
}
/* Animation */
@keyframes message-reveal-animation
{
from
{
opacity: 0;
margin-top: 40px;
}
to
{
opacity: 1;
margin-top: 10px;
}
}
ul.rounded-messages.reveal-messages li
{
visibility: hidden;
}
ul.rounded-messages.msg-animation-superfast li.msg-visible,
ul.rounded-messages.msg-animation-fast li.msg-visible,
ul.rounded-messages.msg-animation-slow li.msg-visible,
ul.rounded-messages.msg-animation-normal li.msg-visible,
ul.rounded-messages li.msg-visible
{
animation: message-reveal-animation;
animation-duration: 0.3s; /* Default Animation Length */
animation-iteration-count: 1;
visibility: visible
}
ul.rounded-messages.msg-animation-superfast li.msg-visible
{
animation-duration: 0.2s; /* Super Fast Animation Length */
}
ul.rounded-messages.msg-animation-slow li.msg-visible
{
animation-duration: 0.5s; /* Slow Animation Length */
}
/* Message Bubbles */
ul.rounded-messages li
{
position: relative;
clear: both;
display: block;
height: auto;
width: auto;
max-width: 50%;
word-wrap: break-word;
word-break: keep-all;
font-family: sans-serif;
text-align: left;
line-height: 1.5em;
margin: 2px 10px;
padding: 10px;
cursor: default;
border-radius: 15px;
}
/* Left Message Bubble */
ul.rounded-messages li:not(.right-msg),
ul.rounded-messages li.left-msg
{
float: left;
color: $left-color;
background: $left-bg;
}
ul.rounded-messages li:not(.right-msg)::before,
ul.rounded-messages li.left-msg::before
{
/* Left Message Bubble Tail */
content: "";
position: absolute;
top: 5px;
left: -10px;
border-top: 15px solid $left-bg;
border-left: 15px solid transparent;
}
/* Right Message Bubble */
ul.rounded-messages li.right-msg
{
float: right;
color: $right-color;
background: $right-bg;
}
ul.rounded-messages li.right-msg::before
{
/* Right Message Bubble Tail */
content: "";
position: absolute;
bottom: 5px;
right: -10px;
border-bottom: 15px solid $right-bg;
border-right: 15px solid transparent;
}
/* Bubble with image */
ul.rounded-messages li img
{
display: block;
max-width: 100%;
border-radius: 5px;
margin-bttom: 5px;
}
/* Bubble with no tail */
ul.rounded-messages li.no-tail::before,
ul.rounded-messages li.time::before
{
content: "";
display: none;
}
/* Time Stamp */
ul.rounded-messages li.time
{
width: 100%;
max-width: 100%;
background: transparent;
margin: 0px;
font-size: 12px;
text-align: center;
color: $time-color;
}
@media screen and (max-width: 500px)
{
/* Fit the screen for all chats */
ul.rounded-messages,
.messages-width-large,
.messages-width-medium,
.messages-width-small
{
width: 100%;
display: block;
}
}
(function(){
window.addEventListener('load', function(){
// Get all messages
var messages = document.querySelectorAll('ul.rounded-messages.reveal-messages li');
// Only try and show messages if some were found
if (messages.length > 0)
{
revealMessages(messages);
}
});
/**
* Function.....: Reveal Messages
* Author.......: Michael Rouse
* Parameters...: messages - the list of messages to display
* Description..: Displays messages one at a time
*/
function revealMessages(messages)
{
// Set static variable to remember what message number was last displayed
revealMessages.msg = (revealMessages.msg === undefined) ? 0 : revealMessages.msg;
if (revealMessages.msg < messages.length)
{
// Set AnimationEnd Event Listener, to load the next message when this one finishes
(messages[revealMessages.msg]).addEventListener('animationend', function(){
revealMessages(messages); // Reveal the next message
});
// Reveal the message if it is not already visible
if (!(messages[revealMessages.msg]).classList.contains('msg-visible'))
{
// Make sure there is a next message to reference
if (revealMessages.msg < (messages.length - 1))
{
// Remove the tail if this message is on the right, and the next message is on the right, OR if it a left message, and the next message is a left message
if ( ((messages[revealMessages.msg]).classList.contains('right-msg') && (messages[revealMessages.msg+1]).classList.contains('right-msg')) ||
(!(messages[revealMessages.msg]).classList.contains('right-msg') && !((messages[revealMessages.msg+1]).classList.contains('right-msg') || (messages[revealMessages.msg+1]).classList.contains('time')))
)
{
(messages[revealMessages.msg]).classList.add('no-tail'); // No tail on this message
}
}
// Show the message
(messages[revealMessages.msg]).classList.add('msg-visible');
} // End if
// Advance the message counter
revealMessages.msg++;
}
} // End revealMessages()
}());
Also see: Tab Triggers