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.
<div class="wrapper">
<div class="wrapper-inner container">
<div class="progress">
<div class="determinate" id="progress-bar"></div>
</div> <!-- progress bar -->
<div class="pomodoro">
<div class="pomodoro__top">
<div class="pomodoro__top_curent_state">
<span class="pomodoro__top_current_state__title">CURRENT STATE</span> <!-- current state title -->
<span class="pomodoro__top_current_state__text" id="current-state">WORK</span>
</div> <!-- pomodoro current state -->
<div class="pomodoro__top_buttons row">
<div class="pomodoro__top_buttons_left col s12 m6">
<div class="pomodoro__top-buttons_left__title">
BREAK
</div>
<i class="material-icons" id="sub-break">remove</i>
<span id="break-time">5m</span>
<i class="material-icons" id="add-break">add</i>
</div> <!-- pomodoro button left -->
<div class="pomodoro__top_buttons_right col s12 m6">
<div class="pomodoro__top-buttons_left__title">
SESSION
</div>
<i class="material-icons" id="sub-session">remove</i>
<span id="session-time">25m</span>
<i class="material-icons" id="add-session">add</i>
</div> <!-- pomodoro button right -->
</div> <!-- pomodoro top buttons -->
</div> <!-- pomodoro top-->
<div class="pomodoro__middle">
<div class="pomodoro__middle_wrapper" id="border-wrapper">
<div class="pomodoro__middle_wrapper__inner" id="clock">
<span>25m</span>
</div>
</div>
</div> <!-- pomodoro middle-->
<div class="pomodoro__bottom">
<div class="pomodoro__bottom-button">
<a class="waves-effect waves-light btn-large" id="start-stop">START</a>
</div> <!-- pomodoro bottom button -->
</div> <!-- pomodoro bottom row-->
</div> <!-- pomodoro -->
</div> <!-- wrapper-inner container -->
</div> <!-- wrapper -->
//variables and mixins
$primary-color: #432F74;
$secondary-color: #8778AD;
$accent-color: #B5AACF;
body{
width: 100%;
height: 100%;
background: #635091;
}
.wrapper {
height: 100%;
&-inner{
height: 100%;
}
}
.progress{
margin-top: 20px;
}
.pomodoro{
text-align: center;
color: white;
//top
&__top{
//state
&_current_state{
//title
&__title{
display: block;
font-size: 1em;
color: $accent-color;
}
//text
&__text{
font-size: 2em;
}
}
//buttons
&_buttons{
margin-top: 50px;
//left and right
&_left, &_right{
//titles
&__title{
}
//the icons
i{
cursor: pointer;
&:hover{
color: $secondary-color;
}
&:active{
color: $accent-color;
}
}
//the spans
span{
padding: 0 10px;
font-size: 2em;
}
}
//add margin top to the session span below 600px
&_right{
@media only screen and (max-width: 601px){
margin-top: 20px;
}
}
}
}
//middle
&__middle{
margin-top: 50px;
//wrapper
&_wrapper{
display: inline-block;
border-radius: 50%;
border: 3px solid $primary-color;
height: 200px;
width: 200px;
//inner flex container
&__inner{
display: flex;
height: 100%;
flex-flow: row nowrap;
align-items: center;
justify-content: center;
//the timer spans
span{
padding: 0 3px;
font-size: 2em;
}
}
}
}
//bottom
&__bottom{
margin: 50px 0 20px 0;
}
}
//variables colors. Constants
const primaryColor = "#26a69a";
const secondaryColor = "#ffeb3b";
const stopColor = "#e53935";
//variables times
let sessionTime = 25;
let breakTime = 5;
let currentTime = 25;
//clock state
var clockState = "off";
//session and break functions
var runSession, runBreak;
//timer interval
var timer;
//let's begin
$(function(){
//first capture the buttons and spans
//progress bar
let pBar = $("#progress-bar");
let pBarParent = pBar.parent();
//current state
let currentState = $("#current-state");
//break
let subBreak = $("#sub-break");
let breakValue = $("#break-time");
let addBreak = $("#add-break");
//session
let subSession = $("#sub-session");
let sessionValue = $("#session-time");
let addSession = $("#add-session");
//clock
let clock = $("#clock");
let borderWrapper = $("#border-wrapper");
//start/stop
let startStop = $("#start-stop");
//functions to execute break actions
let subtractBreak = function(){
if(breakTime > 1){
breakTime--;
updateDisplay(breakTime, "break");
}
else{
toast("Can't have a break shorter than a minute.", 3000);
}
};
let addToBreak = function(){
breakTime++;
updateDisplay(breakTime, "break");
};
//subtract from break
subBreak.click(subtractBreak);
//add to break
addBreak.click(addToBreak);
//functions to execute session actions
let subtractSession = function(){
if(sessionTime > 5){
sessionTime--;
updateDisplay(sessionTime, "session");
}
else{
toast("Less than 5 minutes, seriously? Nah.", 4000);
}
};
let addToSession = function(){
sessionTime++;
updateDisplay(sessionTime, "session");
};
//subtract from session
subSession.click(subtractSession);
addSession.click(addToSession);
//run session function
runSession = function(){
currentState.text("WORK");
//change colors to break
pBarParent.css("background-color", "#acece6");
pBar.css("background-color", primaryColor);
borderWrapper.css("border-color", primaryColor);
let _sessionTime = sessionTime;
let hours = Math.floor(_sessionTime/60);
let minutes = (_sessionTime % 60);
let seconds = 00;
updateClock(clock, hours, minutes, seconds);
//countdown function
countDown(clock, hours, minutes);
//progressBar
runPBar(_sessionTime*60);
};
//run break function
runBreak = function(){
currentState.text("BREAK");
//change colors to break
pBarParent.css("background-color", "#fffde7");
pBar.css("background-color", secondaryColor);
borderWrapper.css("border-color", secondaryColor);
let _breakTime = breakTime;
let hours = Math.floor(_breakTime/60);
let minutes = (_breakTime % 60);
let seconds = 00;
updateClock(clock, hours, minutes, seconds);
//countdown function
countDown(clock, hours, minutes);
//progressBar
runPBar(_breakTime*60);
}
//the start stop functions
startStop.click(function(){
let button = $(this);
if(clockState === "off"){
//start
button.css("background-color", stopColor);
button.text("STOP");
runSession();
clockState = "session";
}
else{
//stop it
clockState = "off";
button.css("background-color", primaryColor);
button.text("START");
pBar.finish();
}
});
//progress bar function
var runPBar = function(seconds){
const initialSeconds = seconds*1000;
pBar.animate({width: "100%"}, initialSeconds, "linear", function(){
pBar.width(0);
});
}
});
//toast function
function toast(message, duration){
var duration = duration;
if(arguments.length === 1){
duration = 2000;
}
Materialize.toast(message, duration);
}
//update break and session spans
function updateDisplay(withWhat, whichOne){
if(whichOne === "break"){
$("#break-time").html(withWhat + "m");
}
else if(whichOne === "session"){
$("#session-time").html(withWhat + "m");
}
}
//function to update clock
function updateClock(clock, hours, minutes, seconds){
let html;
if (hours > 0){
html = `<span>${hours}h</span>
<span>${minutes}m</span>
<span>${seconds}s</span>`;
}
else if(minutes > 0){
html = `<span>${minutes}m</span>
<span>${seconds}s</span>`;
}
else{
html = `<span>${seconds}s</span>`;
}
clock.html(html);
}
//function to countdown
function countDown(clock, hours, minutes){
let seconds = 60;
//sorting out that weird bug at 60 minutes
if(minutes === 0 && hours > 0){
var hours = hours - 1;
minutes = 59;
}
else{
var minutes = minutes -1;
}
var timer = setInterval(function(){
if(clockState != "off"){
if(hours > 0 || minutes > 0 || seconds > 0){
if(seconds > 0){
seconds--;
updateClock(clock, hours, minutes, seconds);
}
else{
if(minutes > 0){
minutes--;
updateClock(clock, hours, minutes, seconds);
seconds = 59;
}
else{
hours--;
updateClock(clock, hours, minutes, seconds);
minutes = 59;
}
}
}
else{
clearInterval(timer);
if(clockState === "session"){
runBreak();
clockState = "break";
}
else if(clockState === "break"){
runSession();
clockState = "session";
}
}
}
else{
clearInterval(timer);
}
}, 1000);
}
Also see: Tab Triggers