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 id="bg">
<div id="meter">
<h1 id="current-aqi">---</h1>
<p>
<!--PM (Particle Matter) SVG-->
<svg height="15px" viewBox="0 0 315 359" fill="none" xmlns="http://www.w3.org/2000/svg">
<g id="PM">
<circle id="Ellipse 1" cx="158" cy="27" r="27" />
<circle id="Ellipse 2" cx="222" cy="68" r="27" />
<circle id="Ellipse 3" cx="288" cy="109" r="27" />
<circle id="Ellipse 4" cx="92" cy="67" r="27" />
<circle id="Ellipse 5" cx="27" cy="109" r="27" />
<circle id="Ellipse 6" cx="92.5" cy="141.5" r="26.5" />
<circle id="Ellipse 7" cx="157" cy="101" r="27" />
<circle id="Ellipse 8" cx="157.5" cy="174.5" r="26.5" />
<circle id="Ellipse 9" cx="223" cy="142" r="26" />
<circle id="Ellipse 10" cx="27" cy="178" r="21" />
<circle id="Ellipse 11" cx="92" cy="210" r="21" />
<circle id="Ellipse 12" cx="157" cy="243" r="21" />
<circle id="Ellipse 13" cx="223" cy="210" r="21" />
<circle id="Ellipse 14" cx="288" cy="178" r="21" />
<circle id="Ellipse 15" cx="288" cy="236" r="16" />
<circle id="Ellipse 16" cx="223" cy="268" r="16" />
<circle id="Ellipse 17" cx="157" cy="301" r="16" />
<circle id="Ellipse 18" cx="92" cy="268" r="16" />
<circle id="Ellipse 19" cx="27" cy="236" r="16" />
<circle id="Ellipse 20" cx="27.5" cy="282.5" r="10.5" />
<circle id="Ellipse 21" cx="92.5" cy="315.5" r="10.5" />
<circle id="Ellipse 22" cx="157.5" cy="348.5" r="10.5" />
<circle id="Ellipse 23" cx="222.5" cy="315.5" r="10.5" />
<circle id="Ellipse 24" cx="288.5" cy="282.5" r="10.5" />
</g>
</svg> AQI</p>
<div id="indicator"></div>
</div>
</div>
:root {
--primary-bg:#070807;
--primary-color:whitesmoke;
--meter-bg-colors:conic-gradient(
from 0deg,
rgba(0, 222, 114, 1),
rgba(255, 226, 28, 1),
rgba(255, 141, 6, 1),
rgba(251, 42, 63, 1),
rgba(178, 1, 238, 1),
rgba(109, 9, 25, 1)
);
}
/*Custom Font Import*/
@font-face {
font-family: "clockDigital";
src: url("https://assets.codepen.io/1179484/digital-7.woff2") format("woff2"),
url("https://assets.codepen.io/1179484/digital-7.woff") format("woff");
}
/*CSS RESET*/
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: "clockDigital";
}
/*Background properties*/
#bg {
height: 100vh;
background-color: var(--primary-bg);
display: grid;
place-items: center;
}
/*U.S.AQI meter using (EPA)category colors*/
#meter {
position: relative;
height: 200px;
aspect-ratio: 1/1;
border-radius: 100%;
background:var(--meter-bg-colors);
display: grid;
place-items: center;
}
/*Inner body of meter*/
#meter:before {
position: absolute;
content: " ";
padding: 90px;
padding: 90px;
border-radius: 100%;
background: var(--primary-bg);
}
/*
the container for the indicator/dot to position it properly
and add a slight transition for the calculation formula in JS
*/
#indicator {
position: absolute;
height: 205px;
aspect-ratio: 1/1;
transition:.2s;
display: flex;
justify-content: center;
rotate: 5deg;
/*animation:spin 5s linear alternate infinite;*/
}
/*The dot on the meter to indicate meters AQI level*/
#indicator:before {
position: absolute;
content: " ";
padding: 5px;
background: var(--primary-color);
top: 0;
border-radius: 100%;
border: 3px solid var(--primary-bg);
}
/*AQI number*/
#current-aqi {
position: absolute;
letter-spacing: 1px;
font-size: 70px;
color: var(--primary-color);
text-align: center;
line-height: 20px;
}
/*SVG and AQI text*/
p {
font-size: 20px;
color: #999;
position: absolute;
top: 130px;
display: flex;
align-items: center;
gap: 5px;
}
/*Particle matter SVG */
#PM {
fill: #999;
}
/* for testing roation on the #indicator*/
@keyframes spin {
from {
rotate:5deg;
}
to {
rotate:355deg;
}
}
/*If user system = lightmode*/
@media (prefers-color-scheme: light) {
/*use these settings instead*/
:root {
--primary-bg: #dbdbdb;
--primary-color: rgb(61, 61, 61);
}
#meter::before {
border: 1px solid black;
}
#indicator {
border-radius: 100%;
height: 200px;
border: 1px solid black;
aspect-ratio: 1/1;
}
#indicator::before {
top: -3px;
padding: 4px;
border: 3px solid var(--primary-bg);
}
}
/*
Details:
Current U.S AQI EPA(Environmental Protection Agency) format, PM(Particle Matter) 2.5, Live Data, Nearest Station based off Geolocation. Made using Vanilla HTML,CSS & JS. PM SVG(Scalable Vector Graphic) made using Figma and a Degree Calculation Formula for AQI Animation The AQI values range from 0 to 500, and since the indicator's animation is circular. The formula takes an AQI value, divides it by 500, and then scales the result to fit within a range of 5 to 355 degrees (which corresponds to the circular indicator's correct position relative to the current AQI ).Open to Suggestion,Questions,Feedback. Thanks.
API info:
Free API key can be found at:
https://www.iqair.com/commercial-air-quality-monitors/api
The free option alllows 10,000 calls/monthy.
*/
/*EXAMPLE START:
AQI and DEG Stat Calculations Shown in Console as they increment for further analysis on how the two main variables of the Degree Calculation Formula for AQI Animation work.
*/
const currentAqi = document.getElementById("current-aqi");
const indicator = document.getElementById("indicator");
function calculateValue(aqi) {
return (aqi / 500) * 350 + 5;
}
let aqi = 0;
let deg = calculateValue(aqi);
let intervalId;
function updateValues() {
aqi++;
deg = calculateValue(aqi);
console.log(`AQI: ${aqi}, DEG: ${deg.toFixed(2)}`);
currentAqi.innerText= aqi;
indicator.style.rotate =`${deg}deg`;
//current AQI simulation number 250
if (aqi === 250) {
clearInterval(intervalId);
}
}
intervalId = setInterval(updateValues, 30);
/*EXAMPLE END*/
/*
Below is the method for hooking up realtime aqi data from iqair.com
which reaches out to 80,000 sensors worldwide City level data
Overall AQI (US & China)
Real-time weather data
// DOM elements
const currentAqi = document.getElementById("current-aqi");
const indicator = document.getElementById("indicator");
// API key
const key = "YOUR API KEY HERE";
// Geolocation coordinates
let latitude;
let longitude;
// Function to update geolocation
function updateGeolocation(position) {
latitude = position.coords.latitude;
longitude = position.coords.longitude;
}
// Check if geolocation is available
function checkGeolocation() {
if ("geolocation" in navigator) {
// Get the current geolocation
navigator.geolocation.getCurrentPosition(updateGeolocation);
} else {
console.log("Geolocation is not available.");
}
}
// Fetch data from the API
function fetchData() {
const apiUrl = `https://api.airvisual.com/v2/nearest_city?lat=${latitude}&lon=${longitude}&key=${key}`;
// Fetch data from the API
fetch(apiUrl).then(handleResponse).then(processData).catch(handleError);
}
// Handle response from API
function handleResponse(response) {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json(); // Parse the response as JSON
}
// Process data and update values
function processData(data) {
const calculateValue = (aqi) => (aqi / 500) * 350 + 5;
let aqi = 0;
let result = calculateValue(aqi);
let intervalId;
// Update AQI values and rotation
function updateValues() {
console.log(`AQI: ${aqi}, DEG: ${result}`);
// Update the AQI display using SVG code
currentAqi.innerHTML = `${aqi}<br>`;
// Update the rotation of the indicator
indicator.style.rotate = `${result}deg`;
// Increment AQI and calculate corresponding rotation
aqi += 1;
result = calculateValue(aqi);
// Check if the target AQI has been reached
if (aqi > data.data.current.pollution.aqius) {
clearInterval(intervalId);
}
}
// Set interval for updating values
intervalId = setInterval(updateValues, 100);
}
// Handle errors during data fetching
function handleError(error) {
console.error("Fetch error:", error);
}
// Initiate data retrieval and updates
function initializeApp() {
checkGeolocation();
fetchData();
}
// Call the initializeApp function
initializeApp();
*/
Also see: Tab Triggers