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.
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Box Shadow Generator</title>
<!-- Google Font -->
<link
href="https://fonts.googleapis.com/css2?family=Poppins&display=swap"
rel="stylesheet"
/>
<!-- Stylesheet -->
<link rel="stylesheet" href="style.css" />
</head>
<body>
<div class="container">
<div class="result">
<div id="element"></div>
</div>
<div class="sliders">
<div class="slider-wrapper">
<label for="h-shadow">Horizontal Shadow:</label>
<input type="range" id="h-shadow" max="100" min="-100" value="0" />
</div>
<div class="slider-wrapper">
<label for="v-shadow">Vertical Shadow:</label>
<input type="range" id="v-shadow" max="100" min="-100" value="0" />
</div>
<div class="slider-wrapper">
<label for="blur-radius">Blur Radius:</label>
<input type="range" id="blur-radius" max="100" min="0" value="0" />
</div>
<div class="slider-wrapper">
<label for="spread-radius">Spread Radius:</label>
<input type="range" id="spread-radius" max="50" min="-50" value="0" />
</div>
<div class="slider-wrapper">
<label for="shadow-color">Shadow Color:</label>
<input type="color" id="shadow-color" />
</div>
<div class="slider-wrapper">
<label for="shadow-color-opacity">Shadow Color Opacity:</label>
<input
type="range"
id="shadow-color-opacity"
max="1"
min="0"
step="0.1"
value="1"
/>
</div>
<div class="input-wrapper">
<label for="shadow-inset">Inset Shadow:</label>
<input type="checkbox" id="shadow-inset" />
</div>
</div>
<div class="code-wrapper">
<textarea rows="2" id="code"></textarea>
<button onclick="copyCode()">Copy</button>
</div>
</div>
<!-- Script -->
<script src="script.js"></script>
</body>
</html>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: "Poppins", sans-serif;
}
body {
background-color: #0075ff;
}
.container {
background-color: #ffffff;
padding: 30px;
position: absolute;
transform: translate(-50%, -50%);
left: 50%;
top: 50%;
width: 80vmin;
border-radius: 10px;
box-shadow: 0 20px 40px rgba(2, 42, 83, 0.2);
}
.result {
padding: 150px 0;
}
#element {
height: 50px;
width: 50px;
position: relative;
background-color: #0075ff;
margin: auto;
}
.sliders {
display: grid;
grid-template-columns: 6fr 6fr;
gap: 20px 15px;
}
.slider-wrapper {
display: flex;
flex-direction: column;
justify-content: space-between;
}
input[type="range"] {
width: 100%;
}
.code-wrapper {
display: grid;
grid-template-columns: 10fr 2fr;
gap: 5px;
margin-top: 20px;
}
textarea {
resize: none;
padding: 5px;
border: 1px solid black;
border-radius: 5px;
}
.code-wrapper button {
background-color: #0075ff;
border-radius: 5px;
border: none;
color: #ffffff;
}
let elem = document.getElementById("element");
let code = document.getElementById("code");
let inputs = document.querySelectorAll(".sliders input");
inputs.forEach((inp) => inp.addEventListener("input", generateShadow));
function generateShadow() {
let hShadow = document.getElementById("h-shadow").value;
let vShadow = document.getElementById("v-shadow").value;
let blurRadius = document.getElementById("blur-radius").value;
let spreadRadius = document.getElementById("spread-radius").value;
let shadowColor = document.getElementById("shadow-color").value;
let shadowColorOpacity = document.getElementById(
"shadow-color-opacity"
).value;
let shadowInset = document.getElementById("shadow-inset").checked;
//Using ternary operator to check if inset checkbox is checked or not.
//If checked we add the inset prefix
//Else no inset prefix is added
let boxShadow = shadowInset
? `inset ${hShadow}px ${vShadow}px ${blurRadius}px ${spreadRadius}px ${hexToRgba(
shadowColor,
shadowColorOpacity
)}`
: `${hShadow}px ${vShadow}px ${blurRadius}px ${spreadRadius}px ${hexToRgba(
shadowColor,
shadowColorOpacity
)}`;
elem.style.boxShadow = boxShadow;
code.textContent = `box-shadow: ${boxShadow};`;
}
//Converting Hex value to rgba
function hexToRgba(shadowColor, shadowColorOpacity) {
let r = parseInt(shadowColor.substr(1, 2), 16);
let g = parseInt(shadowColor.substr(3, 2), 16);
let b = parseInt(shadowColor.substr(5, 2), 16);
return `rgba(${r},${g},${b},${shadowColorOpacity})`;
}
//Copy the generated code to clipboard
function copyCode() {
code.select();
document.execCommand("copy");
alert("Code Copied To Clipboard");
}
//Call the generateShadow function on every page load
window.onload = generateShadow();
Also see: Tab Triggers