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 URL's 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 it's URL and the proper URL extention.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<title>pomodoro timer</title>
<body>
<p>
<h1 class="clock">POMODORO CLOCK</h1>
</p>
<div class="nav-strip">
<div class="timer-controls">
<button data-time="300" class="slide_timer__button slide_from_left">Quick 5 minutes Session</button>
<button data-time="600" class="slide_timer__button slide slide_from_left">Quick 10 minutes Session</button>
<button data-time="900" class="slide_timer__button slide slide_from_left">Quick 15 minutes Session</button>
<form name="customFormSession" id="custom">
<input type=number min=0.1 max=60 step=0.1 name="minutesSession" placeholder="SET SESSION MINUTES">
</form>
<form name="customFormBreak" id="custom">
<input type=number min=0.1 max=60 step=0.1 name="minutesBreak" placeholder="SET BREAK MINUTES">
</form>
</div>
<div class="controls">
<label for="spacing">Transparency:</label>
<input id="transparency" type="range" name="transparency" min="1" max="10" value="1" data-sizing="%">
<label for="blur">Size:</label>
<input id="size" type="range" name="size" min="0" max="25" value="10" data-sizing="px">
<label for="base">Base Color</label>
<input id="base" type="color" name="base" value="#161616">
</div>
<div class="display">
<div class="timer-wrap">
<div class="session">
<div class="tip-highlight-session">
<h3>Set session minutes</h3></div>
<h2 class="clock" id="session_header">Session</h2>
<h1 class="display__time-left_session"></h1>
</div>
<div class="break">
<div class="tip-highlight-break">
<h3>Set break minutes</h3></div>
<h2 class="clock" id="break_header">Break</h2>
<h1 class="display__time-left_break"></h1>
</div>
</div>
<div class="control-nav-bar">
<button id="pause-button" class="slide_timer__button slide_from_left">Pause</button>
<button id="start-button" class="slide_timer__button slide_from_left">Start</button>
<button id="reset-button" class="slide_timer__button slide_from_left">Reset</button>
</div>
</div>
</div>
</body>
:root {
--base: #161616;
--size: 12px;
--transparency: 10%;
--border-color: #E3F2FD;
}
html {
box-sizing: border-box;
font-size: 10px;
}
*,
*:before,
*:after {
box-sizing: inherit;
}
body {
margin: 0;
text-align: center;
font-family: 'Inconsolata', monospace;
background-color: var(--base);
background-image: repeating-linear-gradient(135deg, #333, #333 var(--transparency), transparent var(--transparency), transparent 50%), repeating-linear-gradient(-135deg, #333, #333 var(--transparency), transparent var(--transparency), transparent 50%);
background-size: var(--size) var(--size);
}
.display__time-left_session {
font-weight: 100;
font-size: 15rem;
margin: 0;
color: white;
text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.05);
}
.display__time-left_break {
font-weight: 100;
font-size: 5rem;
margin: 0;
color: white;
text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.05);
}
.nav-strip {
display: flex;
min-height: 100vh;
flex-direction: column;
}
.timer-controls {
display: flex;
}
.timer-controls > * {
flex: 1;
}
.controls {
margin-bottom: 50px;
margin-top: 50px;
color: white;
font-weight: 100;
font-size: 30px;
text-align: center;
}
input {
width: 100px;
}
.timer-controls form {
flex: 1;
display: flex;
}
.timer-controls input {
flex: 1;
border: 0;
padding: 2rem;
border-left: 1px solid rgba(0, 0, 0, 0.2);
}
/* .timer__button {
background: none;
border: 0;
cursor: pointer;
color: white;
font-size: 2rem;
text-transform: uppercase;
background: rgba(0, 0, 0, 0.1);
border-bottom: 3px solid rgba(0, 0, 0, 0.2);
border-right: 1px solid rgba(0, 0, 0, 0.2);
padding: 1rem;
font-family: 'Inconsolata', monospace;
} */
.timer__button:hover,
.timer__button:focus {
background: rgba(0, 0, 0, 0.2);
outline: 0;
}
.display {
flex: 1;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.timer-wrap {
border: 2px solid white;
min-width: 700px;
display: inline-flex;
margin: 0 auto;
flex-wrap: wrap;
}
.session {
position: relative;
width: 60%;
border-right: 2px solid white;
}
.break {
position: relative;
width: 40%;
}
.clock {
font-weight: 100;
font-size: 2rem;
margin: 0;
color: white;
transition: all 1s;
text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.05);
text-align: center;
}
.playing {
transform: scale(1.3);
color: #ffc600;
}
.control-nav-bar {
display: flex;
margin-top: 10px;
}
/* .control_button {
background: none;
border: 0;
cursor: pointer;
color: white;
font-size: 2rem;
text-transform: uppercase;
background: rgba(0, 0, 0, 0.1);
border-bottom: 3px solid rgba(0, 0, 0, 0.2);
border-right: 1px solid rgba(0, 0, 0, 0.2);
padding: 1rem;
font-family: 'Inconsolata', monospace;
} */
/* .control_button:hover,
.control_button:focus {
background: rgba(0, 0, 0, 0.2);
outline: 0;
} */
.tip-highlight-session,
.tip-highlight-break {
background-color: black;
position: absolute;
display: block;
width: 100%;
height: 100%;
opacity: 0.9;
background-color: var(--base);
font-weight: 800;
font-size: 24px;
line-height: 128px;
font-style: italic;
color: #E8EAF6;
font-family: "Open Sans";
text-align: center;
}
.slide_timer__button {
font-size: 2em;
background: var(--base);
color: #fff;
border: 0.25rem solid var(--border-color);
/* padding: 0.85em 0.75em; */
padding: 1rem;
margin: 1rem;
position: relative;
z-index: 1;
overflow: hidden;
}
button:hover {
color: var(--base);
}
button::after {
content: "";
background: #ecf0f1;
position: absolute;
z-index: -1;
padding: 0.85em 0.75em;
display: block;
}
button[class^="slide"]::after {
transition: all 0.35s;
}
button[class^="slide"]:hover::after {
left: 0;
right: 0;
top: 0;
bottom: 0;
transition: all 0.35s;
}
button.slide_from_left::after {
top: 0;
bottom: 0;
left: -100%;
right: 100%;
}
const cacheDisplayTimerSession = document.querySelector('.display__time-left_session');
const cacheDisplayTimerBreak = document.querySelector('.display__time-left_break');
const tipHighlightSession = document.querySelector('.tip-highlight-session');
const tipHighlightBreak = document.querySelector('.tip-highlight-break');
const buttons = document.querySelectorAll('[data-time]');
const pause = document.querySelector('#pause-button');
const start = document.querySelector('#start-button');
const reset = document.querySelector('#reset-button');
const sessionHeader = document.querySelector("#session_header");
const breakHeader = document.querySelector("#break_header");
const defaultTimerSession = document.querySelector('.display__time-left_session');
defaultTimerSession.textContent = "00:00";
const defaultTimerBreak = document.querySelector('.display__time-left_break');
defaultTimerBreak.textContent = "00:00";
let countdown;
let mins;
let seconds;
let sessionTimerisEnded = false;
let isPaused = false;
var breakSeconds;
var value_is_set = true;
var value_is_set_break = true;
//console.log(value_is_set + " global");
//*Session timer */
function sessionTimer(seconds) {
clearInterval(countdown);
const t = new Date();
const end = t.getTime() + seconds * 1000;
displayTimerLeftSession(seconds);
console.log({
t,
end
});
countdown = setInterval(() => {
if (!isPaused) {
const remainSeconds = Math.round((end - t.getTime()) / 1000);
if (remainSeconds < 0) {
clearInterval(countdown);
breakTimer(breakSeconds);
console.log(breakSeconds);
sessionHeader.classList.remove('playing');
breakHeader.classList.add('playing');
setTimeout(function() {
breakHeader.classList.remove('playing');
}, breakSeconds * 1000 + 3000);
return;
}
displayTimerLeftSession(remainSeconds);
t.setSeconds(t.getSeconds() + 1);
}
}, 1000);
t.setSeconds(t.getSeconds() + 1) - 1;
}
/*Break timer*/
function breakTimer(breakSeconds) {
clearInterval(countdown);
const t = new Date();
const end = t.getTime() + breakSeconds * 1000;
displayTimerLeftBreak(breakSeconds);
console.log({
t,
end
});
countdown = setInterval(() => {
if (!isPaused) {
const remainSeconds = Math.round((end - t.getTime()) / 1000);
if (remainSeconds < 0) {
clearInterval(countdown);
return;
}
displayTimerLeftBreak(remainSeconds);
t.setSeconds(t.getSeconds() + 1);
}
}, 1000);
t.setSeconds(t.getSeconds() + 1) - 1;
}
function displayTimerLeftSession(seconds) {
const minutes = Math.floor(seconds / 60);
const remainderSeconds = seconds % 60;
const display = `${minutes}:${remainderSeconds<10?'0':''}${remainderSeconds}`;
cacheDisplayTimerSession.textContent = display;
/* console.log({
remainderSeconds
}, {
minutes
}); */
}
function displayTimerLeftBreak(breakSeconds) {
const minutes = Math.floor(breakSeconds / 60);
const remainderSeconds = breakSeconds % 60;
const display = `${minutes}:${remainderSeconds<10?'0':''}${remainderSeconds}`;
cacheDisplayTimerBreak.textContent = display;
/* console.log({
remainderSeconds
}, {
minutes
}); */
}
var quickTime = function() {
tipHighlightSession.style.display = 'none';
sessionHeader.classList.add('playing');
breakHeader.classList.remove('playing');
seconds = parseInt(this.dataset.time);
sessionTimer(seconds);
}
buttons.forEach((button) => button.addEventListener('click', quickTime));
document.customFormSession.addEventListener('submit', function(e) {
e.preventDefault();
value_is_set = true;
validateForm();
//console.log(value_is_set + " customFormSession outside if");
if (value_is_set) {
value_is_set = true;
console.log(value_is_set + " customFormSession inside if");
tipHighlightSession.style.display = 'none';
sessionHeader.classList.add('playing');
breakHeader.classList.remove('playing');
seconds = this.minutesSession.value * 60;
displayTimerLeftSession(seconds);
sessionTimer(seconds);
this.reset();
} else {
value_is_set = false;
//console.log(value_is_set + " customFormSession inside else");
tipHighlightSession.style.display = 'block';
}
});
document.customFormBreak.addEventListener('submit', function(e) {
e.preventDefault();
value_is_set_break = true;
validateFormBreak();
if (value_is_set_break) {
tipHighlightBreak.style.display = 'none';
breakSeconds = this.minutesBreak.value * 60;
displayTimerLeftBreak(breakSeconds);
this.reset();
} else {
value_is_set_break = false;
//console.log(value_is_set + " customFormSession inside else");
tipHighlightBreak.style.display = 'block';
}
});
pause.addEventListener('click', function() {
isPaused = true;
//return;
});
start.addEventListener('click', function() {
isPaused = false;
});
reset.addEventListener('click', function() {
sessionTimer(seconds);
});
function validateForm() {
var x = document.forms["customFormSession"]["minutesSession"].value;
if (x == "") {
alert("Please set numbers");
value_is_set = false;
console.log(value_is_set + " " + "validateForm");
return false;
}
}
function validateFormBreak() {
var x = document.forms["customFormBreak"]["minutesBreak"].value;
if (x == "") {
alert("Please set numbers");
value_is_set_break = false;
console.log(value_is_set + " " + "validateForm");
return false;
}
}
const inputs = document.querySelectorAll('.controls input');
function handleUpdate() {
const suffix = this.dataset.sizing || '';
document.documentElement.style.setProperty(`--${this.name}`, this.value + suffix);
}
inputs.forEach(input => input.addEventListener('change', handleUpdate));
inputs.forEach(input => input.addEventListener('mousemove', handleUpdate));
Also see: Tab Triggers