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.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fireproof Example</title>
<script src="https://cdn.jsdelivr.net/npm/@fireproof/core@0.19.106/index.global.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fireproof/cloud@0.19.106/index.global.js"></script>
</head>
<body ondblclick="reset(event)">
<div class="container">
<form>
<input type="text" />
<button onclick="addItem(event)">Add Item</button>
</form>
<ul></ul>
<div id="info"><a target="_blank" href="https://fireproof.storage">Inspect data</a></div>
</div>
</body>
</html>
/* General styles for dark mode */
body {
background-color: #121212; /* Dark background */
color: #e0e0e0; /* Light text */
font-family: Arial, sans-serif; /* Change to your preferred font */
}
/* Container Styles */
.container {
display: flex; /* Use flexbox for alignment */
flex-direction: column; /* Stack form and list vertically */
align-items: center; /* Center items horizontally */
max-width: 600px; /* Limit the maximum width */
margin: 0 auto; /* Center the container horizontally */
}
#info {
display: flex;
width: 100%;
padding: 4px;
font-size: small;
}
#info a {
color: #d57729;
}
/* Unordered List Styles */
ul {
list-style-type: none; /* Remove default bullets */
padding: 0;
margin: 0;
width: 100%; /* Make the list take the full width of the container */
}
/* List Item Styles */
ul > li {
display: flex; /* Use flexbox for alignment */
align-items: center; /* Center items vertically */
background-color: #1e1e1e; /* Slightly lighter background for list items */
border: 1px solid #333; /* Border to separate items */
border-radius: 5px; /* Rounded corners */
padding: 10px; /* Spacing inside list items */
margin: 5px 0; /* Space between list items */
transition: background-color 0.3s; /* Smooth background change on hover */
}
/* Hover effect */
ul > li:hover {
background-color: #333; /* Darker background on hover */
cursor: pointer; /* Pointer cursor on hover */
}
/* Optional: Add a subtle shadow */
ul > li {
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); /* Subtle shadow */
}
/* Optional: Active or selected item */
ul > li.active {
background-color: #444; /* Different color for active/selected item */
border-color: #555; /* Slightly different border for active/selected item */
}
/* Checkbox Styles */
ul > li input[type="checkbox"] {
appearance: none; /* Remove default checkbox style */
background-color: #2a2a2a; /* Dark background */
border: 2px solid #444; /* Border color */
border-radius: 4px; /* Rounded corners */
width: 20px;
height: 20px;
cursor: pointer; /* Pointer cursor */
position: relative; /* Position relative for checkmark */
transition: background-color 0.3s, border-color 0.3s; /* Smooth transition */
margin-right: 10px; /* Space between checkbox and text */
}
ul > li input[type="checkbox"]:checked {
background-color: #f58709; /* Green background when checked */
border-color: #f58709; /* Green border when checked */
}
ul > li input[type="checkbox"]:checked::after {
content: "✔"; /* Checkmark */
color: #fff; /* White checkmark color */
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%); /* Center the checkmark */
}
ul > li input[type="checkbox"]:hover {
background-color: #3a3a3a; /* Slightly lighter background on hover */
border-color: #555; /* Slightly different border on hover */
}
/* Text Styles inside List Items */
ul > li span {
flex-grow: 1; /* Take up remaining space */
margin-left: 10px; /* Space between checkbox and text */
}
/* Form Styles */
form {
display: flex; /* Use flexbox for alignment */
align-items: center; /* Center items vertically */
margin-bottom: 14px; /* Space below the form */
margin-top: 10px;
width: 100%; /* Make the form take the full width of the container */
padding: 0 10px; /* Add padding to left and right */
box-sizing: border-box; /* Include padding in width calculation */
}
/* Input Styles */
form input[type="text"] {
background-color: #2a2a2a; /* Dark background */
color: #e0e0e0; /* Light text */
border: 1px solid #444; /* Border color */
border-radius: 4px; /* Rounded corners */
padding: 8px; /* Padding inside the input */
margin-right: 10px; /* Space between input and button */
flex-grow: 1; /* Take up remaining space */
box-sizing: border-box; /* Include padding in width calculation */
}
/* Button Styles */
form button {
background-color: #f58709; /* Green background */
color: #fff; /* White text */
font-weight: bold;
font-size: 0.8em;
border: none; /* Remove default border */
border-radius: 4px; /* Rounded corners */
padding: 8px 12px; /* Padding inside the button */
cursor: pointer; /* Pointer cursor */
transition: background-color 0.3s; /* Smooth background change on hover */
white-space: nowrap; /* Prevent text wrap */
box-sizing: border-box; /* Include padding in width calculation */
}
form button:hover {
background-color: #f16c12; /* Darker green on hover */
}
db = connect("fireproof");
function addItemDb(text) {
db.put({
text,
done: false,
created: Date.now()
});
}
function addItem(e) {
e.preventDefault();
const input = document.querySelector("form input");
if (!input.value) return;
addItemDb(input.value);
input.value = "";
}
window.addItem = addItem;
function toggleDone(doc) {
doc.done = !doc.done;
doc.updated = Date.now();
db.put(doc);
}
async function redraw() {
const result = await db.query("created", {
includeDocs: true,
descending: true,
limit: 10
});
document.querySelector("ul").innerHTML = "";
for (const row of result.rows) {
const textSpan = document.createElement("span");
textSpan.innerText = row.doc.text;
const checkbox = document.createElement("input");
checkbox.onchange = () => {
toggleDone(row.doc);
};
if (row.doc.done) {
checkbox.setAttribute("checked", true);
}
checkbox.setAttribute("type", "checkbox");
const deleteSpan = document.createElement("span");
deleteSpan.innerText = "x";
deleteSpan.style = "text-align:right; color:#999";
deleteSpan.onclick = function (e) {
e.preventDefault();
db.del(row.id);
if (result.rows.length <= 1) reset();
};
const li = document.createElement("li");
li.appendChild(checkbox);
li.appendChild(textSpan);
li.appendChild(deleteSpan);
document.querySelector("ul").appendChild(li);
}
}
const fixtures = [
"Merkle integrity",
"Runs in any cloud",
"End-to-end encryption",
"JSON documents",
"Open-source connectors",
"Commodity storage",
"Serverless architecture",
"Immutable history",
"Self-sovereign auth",
"Cloudless operation",
"Event-driven architecture",
"React state management"
];
function getRandomThree(arr) {
let result = ["Multi-writer CRDT"];
let clonedArray = [...arr];
for (let i = 1; i < 3; i++) {
let randomIndex = Math.floor(Math.random() * clonedArray.length);
result.push(clonedArray[randomIndex]);
clonedArray.splice(randomIndex, 1);
}
return result;
}
async function reset(e) {
if (e) e.preventDefault();
const allDocs = await db.allDocs();
for (const row of allDocs.rows) {
db.del(row.key);
}
const puts = getRandomThree(fixtures).map((text) => {
db.put({
created: Date.now(),
text,
done: true
});
});
await Promise.all(puts);
db.compact();
}
window.reset = reset;
window.onload = async function initialize() {
db.subscribe(redraw);
redraw();
const allDocs = await db.allDocs();
if (!allDocs.rows.length) {
reset();
}
};
function connect(name) {
const db = Fireproof.fireproof(name);
// placeholder until Fireproof Cloud ships
Connect.connect(db).then((cx) => {
const dashboardUrl = cx.dashboardUrl.toString();
document.querySelector("#info a").href = dashboardUrl;
});
return db;
}
// for another app that syncs live with the same dataset see
// https://replit.com/@jchris5/HTML-CSS-JS-Auto-Refresh#script.js
Also see: Tab Triggers