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.
<link href='https://unpkg.com/boxicons@2.0.7/css/boxicons.min.css' rel='stylesheet'>
<body>
<div class="main">
<h1 class="title">TODO</h1>
<div class="input__section">
<div class="form__input_container">
<div class="input__container">
<input type="text" class="todo_input" autofocus="true" placeholder="watch movie, visit friends,..">
<i class="add__todo bx bx-plus"></i>
</div>
</div>
</div>
<ul class="todo__lists"></ul>
</div></script>
</body>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap');
*,
*::before,
*::after {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* --------- VARIABLES ---------- */
:root {
--primary-color: rgb();
--second-color: rgb();
--green-color: rgb(0, 199, 175);
--red-color: rgb(255, 98, 163);
--indigo-color: rgb(111, 101, 243);
--indigo-gray: rgb(171, 177, 200);
--indigo-gray-alt: rgb(162, 168, 195);
--dark-color: rgb(58, 57, 78);
--dark-gray: rgb(188, 187, 194);
--white-color: #FAFAFF;
--gray-color: rgb(230, 230, 230);
--blue-white-color: rgb(241, 239, 255);
}
/* ----------- GENERAL --------- */
body {
position: relative;
font-family: 'Poppins', sans-serif;
color: var(--dark-color);
background-color: rgb(78, 103, 216);
}
.bx {
cursor: pointer;
font-size: 1.5em;
}
li {
text-decoration: none;
}
/* ----------- MAIN ----------- */
.title {
color: var(--white-color);
font-weight: 400;
text-align: center;
margin: 1em 0;
}
.main {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, 0);
}
/* ------------ TODO INPUT FORM ------- */
.form__input_container {
display: flex;
align-items: center;
justify-content: center;
}
.input__container {
position: relative;
}
.todo_input {
background-color: var(--white-color);
color: var(--dark-color);
height: 2.5em;
width: 20em;
font-size: 18px;
font-family: 'Poppins', sans-serif;
padding: 0 .2em;
border: none;
outline: none;
border: thin solid rgba(46, 36, 190, 0.74);
border-radius: 2px;
}
.bx-plus {
position: absolute;
top: 50%;
left: 90%;
border-radius: 50%;
padding: .25em;
background-color: rgba(200, 198, 212, 0.37);
transform: translate(-50%, -50%);
transition: 200ms background-color;
}
.bx-plus:hover {
background-color: rgba(171, 165, 202, 0.37);
}
/*----------- TODO LISTS -----------*/
.todo__lists {
display: flex;
flex-direction: column;
justify-content: flex-start;
margin-top: 1em;
}
.todo__item {
display: flex;
align-items: center;
justify-content: space-between;
margin: .5em 0;
border: thin solid var(--white-color);
border-radius: 2px;
background-color: var(--white-color);
transition: 200ms transform, 200ms opacity;
}
.delete_todo_item_animation {
transform: translateX(-20rem);
opacity: 0;
}
.todo {
font-size: 18px;
font-weight: 400;
margin-left: .3em;
}
.complete_todo_item {
text-decoration: line-through;
opacity: .5;
}
.action__buttons {
display: flex;
align-items: center;
justify-content: center;
margin-left: .5em;
}
.action__btn {
cursor: pointer;
padding: .60em;
border-radius: 2px;
color: var(--white-color);
transition: 200ms background-color;
}
.bx-check,
.bx-trash {
pointer-events: none;
}
.complete {
background-color: var(--green-color);
}
.complete:hover {
background-color: rgb(8, 173, 154);
}
.delete {
background-color: var(--red-color);
}
.delete:hover {
background-color: rgb(235, 72, 139);
}
/* ---------- MEDIA QUERIES --------- */
@media screen and (max-width: 480px){
.todo_input {
height: 2.5em;
width: 15em;
}
}
@media screen and (min-width: 481px){
.todo_input {
height: 2.5em;
width: 25em;
}
.bx-plus {
left: 95%;
}
}
@media screen and (min-width: 768px){
.todo_input {
height: 2.5em;
width: 32em;
}
.bx-plus {
left: 96%;
transform: translate(-50%, -50%);
}
}
@media screen and (min-width: 1024px){
.todo_input {
height: 2.5em;
width: 40em;
}
.bx-plus {
left: 97%;
transform: translate(-50%, -50%);
}
}
const todoListItems = document.querySelector('.todo__lists');
const todoItem = document.querySelectorAll('.todo__item');
const newTodo = document.querySelector('.todo_input');
// Add Todo function
function addTodo() {
// Todo input
if(newTodo.value !== ''){
// Create a Todo Item Div
const todoItemDiv = document.createElement('li');
// Add classes to it
todoItemDiv.className = "todo__item";
// Create a Todo Div
const todoDiv = document.createElement('div');
// Add classes to it
todoDiv.className = "todo";
todoDiv.appendChild(document.createTextNode(newTodo.value));
// Add text node with todo input value
todoItemDiv.appendChild(todoDiv);
// ============== create action buttons container =============
const actionButtonsContainer = document.createElement('div');
// Add class to it
actionButtonsContainer.className = "action__buttons";
// ---------- COMPLETE BUTTON ------------
// Create complete and check icon button
const completeButton = document.createElement('div');
const bxCheckIcon = document.createElement('i');
// Add classes to complete and check button
completeButton.className = "action__btn complete";
bxCheckIcon.className = "bx bx-check";
// Append check icon to complete button.
completeButton.appendChild(bxCheckIcon);
actionButtonsContainer.appendChild(completeButton);
// ---------- DELETE BUTTON ------------
// Create complete and check icon button
const deleteButton = document.createElement('div');
const bxTrashIcon = document.createElement('i');
// Add classes to complete and check button
deleteButton.className = "action__btn delete";
bxTrashIcon.className = "bx bx-trash";
// Append check icon to complete button.
deleteButton.appendChild(bxTrashIcon);
actionButtonsContainer.appendChild(deleteButton);
// Append complete button to todo itemDiv
todoItemDiv.appendChild(actionButtonsContainer);
todoListItems.appendChild(todoItemDiv);
newTodo.value = '';
// Focus input
// ....
}else {
alert("The input is empty!");
}
}
// -------- ADD TODO -------
const addTodoButton = document.querySelector('.add__todo');
addTodoButton.addEventListener('click', (e) => {
// e.preventDefault(); // To prevent initial behavior.
addTodo()
console.log(todoItem);
})
// ---- COMPLETE TODO ----
todoListItems.addEventListener('click', (e) => {
if(e.target.classList.contains('complete') || e.target.classList.contains('bx-check')){
var completeButton = e.target.parentElement;
if(completeButton.parentElement.classList.contains('complete_todo_item')){
completeButton.parentElement.classList.remove('complete_todo_item');
}else {
completeButton.parentElement.classList.add('complete_todo_item');
}
}
})
// ---- DELETE TODO ----
todoListItems.addEventListener('click', (e) => {
if(e.target.classList.contains('delete') || e.target.classList.contains('bx-trash')){
var delButton = e.target.parentElement;
delButton.parentElement.classList.add('delete_todo_item_animation');
delButton.parentElement.addEventListener('transitionend', () => {
delButton.parentElement.remove();
})
}
})
// Add todo to local storage
function storeTodoInLocalStorage(todoItemToBeStolen){
if(typeof(Storage) !== "undefined"){
localStorage.setItem("todos_stored", todoItemToBeStolen)
}else {
}
}
Also see: Tab Triggers