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="container">
<!-- <h3>Pomodoro Clock</h3> -->
<div class="circle total-progress">
<div class="seconds progress">
<div class="middle">
<div id="time-status">
<div id="timer-type"></div>
<span class="hidden" id="hours-left"></span>
<span id="min-left"></span>
<span id="sec-left"></span>
</div>
</div>
</div>
</div>
<div class="settings">
<div class="session-settings">
<span class="settings-headers">session time</span>
<span id="session-time"></span>
<button class="settings-btn-plus" id="session-plus" type="button">+</button>
<button class="settings-btn-minus" id="session-minus" type="button">-</button>
</div>
<div class="break-settings">
<span class="settings-headers">break time</span>
<span id="break-time"></span>
<button class="settings-btn-plus" id="break-plus" type="button">+</button>
<button class="settings-btn-minus" id="break-minus" type="button">-</button>
</div>
<div class="operations">
<button type="button" class="operation-btn" id="start">start</button>
<!-- <button type="button" class="operation-btn" id="pause">pause</button> -->
<button type="button" class="operation-btn" id="stop">stop</button>
</div>
</div>
<div class="footer">©julsmorozova</div>
</div>
* {
box-sizing: border-box;
}
body {
height: 100vh;
width: 100%;
margin: 0;
display: flex;
justify-content: center;
font-family: Tahoma, Verdana, sans-serif;
color: #777;
background-color: #0E1826;
}
button {
outline: none;
border: none;
min-width: 2rem;
min-height: 2rem;
background: none;
color: #777;
font-size: 1.7rem;
margin: 0.3rem;
&:hover {
color: #64D7DB;
}
}
.hidden {
display: none;
}
.container {
padding: 0;
width: 100%;
height: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
align-items: center;
}
.circle {
width: 15rem;
height: 15rem;
min-height: 15rem;
background-color: #64D7DB;
border: 0.125rem solid #b0b0b0;
border-radius: 50%;
margin: 2rem 0 1rem;
color: #4097B2;
font-size: 3rem;
display: flex;
position: relative;
justify-content: center;
align-items: center;
&.total-progress {
background-image:
linear-gradient(90deg, transparent 50%, #0E1826 50%),
linear-gradient(90deg, #0E1826 50%, transparent 50%);
}
.seconds {
border-radius: 50%;
background-color: #BFD7EA;
width: 90%;
height: 90%;
display: flex;
justify-content: center;
align-items: center;
&.progress {
background-image:
linear-gradient(90deg, transparent 50%, #0E1826 50%),
linear-gradient(90deg, #0E1826 50%, transparent 50%);
}
}
}
.middle {
border-radius: 50%;
background-color: #0E1826;
width: 90%;
height: 90%;
display: flex;
justify-content: center;
align-items: center;
}
#time-status {
width: 100%;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
#timer-type{
width: 100%;
text-align: center;
margin: -1.3rem 0 0.5rem;
font-size: 1.3rem;
color: #777;
}
}
.settings {
width: 60%;
margin: 1rem;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
.session-settings, .break-settings {
width: 45%;
display: flex;
flex-wrap: wrap;
justify-content: center;
.settings-headers, #session-time, #break-time {
width: 100%;
text-align: center;
margin: 0.5rem;
}
#session-time, #break-time {
font-size: 1.6rem;
color: #4097B2;
}
}
}
.operations {
margin: 1rem;
width: 100%;
display: flex;
justify-content: center;
button {
margin: 0.5rem;
width: 4rem;
height: 2rem;
line-height: 1.8rem;
font-size: 0.9rem;
color: #BFD7EA;
background-color: #777;
&:hover {
opacity: 0.5;
}
}
}
.footer {
height: 2rem;
line-height: 2rem;
width: 100%;
display: flex;
justify-content: flex-start;
padding: 0 1.5rem;
margin: 1rem 0 0;
}
var increaseButtons = document.querySelectorAll('.settings-btn-plus');
var decreaseButtons = document.querySelectorAll('.settings-btn-minus');
var startBtn = document.querySelector("#start");
var stopBtn = document.querySelector("#stop");
var sessionTimeBlock = document.querySelector("#session-time");
var breakTimeBlock = document.querySelector("#break-time");
var timeStatusBlock = document.querySelector("#time-status");
var hoursSpan = document.querySelector("#hours-left");
var minSpan = document.querySelector("#min-left");
var secSpan = document.querySelector("#sec-left");
var timerTypeName = document.querySelector("#timer-type");
var totalProgress = document.querySelector(".total-progress");
var secondsProgress = document.querySelector(".progress");
var timer = '';//below used for setInterval/clearInterval
var timerActive = false;
var timerType = 'session';//is then changed to break
var startTime = 1500; //start of the session: session time by default
var sessionTime = 1500;//default session time stored in seconds
var breakTime = 300; //default break time stored in seconds;
var currentTime = 1500; //time displayed on timer in seconds
function displayDefaultTime() {
sessionTimeBlock.innerHTML = displayMinutes(sessionTime) + ' min';
breakTimeBlock.innerHTML = displayMinutes(breakTime) + ' min';
displayCurrentTime();
}
function handleTotalProgress(startTime, currentTime) {
var progressColor = '';
if (timerType === 'session') {
progressColor = '#64D7DB';
totalProgress.style.backgroundColor = '#64D7DB';
}
else {
progressColor = '#A75ACE';
totalProgress.style.backgroundColor = '#A75ACE';
}
var timePassed = startTime - currentTime;
var deg;
if (timePassed < (startTime / 2)) {
deg = 90 + (360 * timePassed / startTime)
totalProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, #0E1826 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
}
else if (timePassed >= (startTime / 2)) {
deg = -90 + (360 * timePassed / startTime);
totalProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, '+progressColor+' 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
}
}
function handleSecondsProgress(currentTime) {
var progressBarColor = '';
if (timerType === 'session') {
progressBarColor = '#BFD7EA';
secondsProgress.style.backgroundColor = '#BFD7EA';
}
else {
progressBarColor = '#F9EDF9';
secondsProgress.style.backgroundColor = '#F9EDF9';
}
var secondsPassed = 60 - convertFromSec(currentTime).seconds;
var deg;
if (secondsPassed < (60 / 2)) {
deg = 90 + (360 * secondsPassed / 60)
secondsProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, #0E1826 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
}
else if (secondsPassed >= (60 / 2)) {
deg = -90 + (360 * secondsPassed / 60);
secondsProgress.style.backgroundImage = 'linear-gradient('+deg+'deg, transparent 50%, '+progressBarColor+' 50%),linear-gradient(90deg, #0E1826 50%, transparent 50%)';
}
}
function displayCurrentTime() {
if (convertFromSec(currentTime).hours) {
hoursSpan.classList.remove('hidden');
hoursSpan.innerHTML = convertFromSec(currentTime).hours + ': ';
}
else {
hoursSpan.innerHTML = '';
}
minSpan.innerHTML = convertFromSec(currentTime).minutes + ': ';
secSpan.innerHTML = convertFromSec(currentTime).seconds;
}
function addLeadingZero(time) {
return time < 10? '0' + time : time;
}
function displayMinutes(timeInSec) {
return parseInt(timeInSec / 60);
}
function convertFromSec(timeInSec) {
var result = { hours: 0, minutes: 0, seconds: 0 };
var seconds = timeInSec % 60;
var minutes = parseInt(timeInSec / 60) % 60;
var hours = parseInt(timeInSec / 3600);
if (hours > 0) {
result.hours = hours;
}
result.minutes = addLeadingZero(minutes);
result.seconds = addLeadingZero(seconds);
return result;
}
function countDown() {
timerTypeName.innerHTML = timerType;
if (currentTime > 0) {
currentTime --;
displayCurrentTime();
handleTotalProgress(startTime, currentTime);
handleSecondsProgress(currentTime);
if (currentTime === 0) {
if (timerType === 'session') {
currentTime = breakTime;
startTime = breakTime;
timerType = 'break';
timerTypeName.innerHTML = timerType;
}
else {
currentTime = sessionTime;
startTime = sessionTime;
timerType = 'session';
timerTypeName.innerHTML = timerType;
}
}
}
}
function toggleTimer() {
if (timerActive) {
clearInterval(timer);
startBtn.innerHTML = 'start';
timerActive = false;
}
else {
startBtn.innerHTML = 'pause';
timer = setInterval(countDown, 1000);
timerActive = true;
}
}
function stopTimer() {
timerActive = false;
startBtn.innerHTML = 'start';
clearInterval(timer);
timerType = 'session';
currentTime = sessionTime;
handleTotalProgress(startTime, currentTime);
handleSecondsProgress(currentTime);
displayDefaultTime();
}
function displayChangedTime(e, time) {
if (e.target.id === 'session-plus' || e.target.id === 'session-minus') {
sessionTimeBlock.innerHTML = displayMinutes(sessionTime) + ' min';
}
else if (e.target.id === 'break-plus' || e.target.id === 'break-minus') {
breakTimeBlock.innerHTML = displayMinutes(breakTime) + ' min';
}
}
startBtn.addEventListener('click', toggleTimer);
stopBtn.addEventListener('click', stopTimer);
for (var i = 0; i < increaseButtons.length; i++) {
increaseButtons[i].addEventListener('click', function(e) {
if (!timerActive) {
if (e.target.id === 'session-plus') {
sessionTime += 60;
currentTime = sessionTime;
startTime = sessionTime;
displayChangedTime(e, sessionTime);
displayCurrentTime();
}
else if (e.target.id === 'break-plus') {
breakTime += 60;
displayChangedTime(e, breakTime);
displayCurrentTime();
}
}
});
}
for (var i = 0; i < decreaseButtons.length; i++) {
decreaseButtons[i].addEventListener('click', function(e) {
if (!timerActive) {
if (e.target.id === 'session-minus') {
if (sessionTime > 60) {
sessionTime -= 60;
currentTime = sessionTime;
startTime = sessionTime;
displayChangedTime(e, sessionTime);
displayCurrentTime();
}
}
else if (e.target.id === 'break-minus') {
if (breakTime > 60) {
breakTime -= 60;
displayChangedTime(e, breakTime);
displayCurrentTime();
}
}
}
});
}
document.addEventListener('DOMContentLoaded', displayDefaultTime);
Also see: Tab Triggers