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.
<button class="btn" type="button">Button</button>
<!--
And when i'm done coding this...
--second structure--
(if javascript is off or the browser did not support css filter:blur)
<button class="btn-fallback btn-fluent">Text</button
(if javascript is on and browser did support css filter:blur)
<button class="btn-fluent">
<text/> z-index: 1;
<circle1/> width&height: height->btn-fluent + [num]em; z-index: 2;
<circle2/> width&height: height->btn-fluent + [num]em; z-index: 2;
</button>
-- easy to read & style and maybe can add the original light effect (which i like) and also colored background
-- might code it, might not.
-->
<a href="https://abubakersaeed.netlify.app/designs/d1-button-fluent-design" class="abs-site-link" rel="nofollow noreferrer" target="_blank">abs/designs/d1-button-fluent-design</a>
/*
Please Do Try:
#mouse-users: click&hold and move mouse
#keyboard-users: press and hold "SpaceBar" while focus
*/
* {
&,
&::after,
&::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
}
html {
& {
font-size: (10/16) * 100%;
}
}
body {
& {
width: 100vw;
height: 100vh;
background: hsl(0, 0%, 15%);
font-family: 'Segoe UI', Tahoma, sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
}
.btn {
& {
display: inline-block;
position: relative;
color: hsl(0, 0%, 94%);
background: transparent;
font-family: inherit;
padding: 2rem 7rem;
border: 0 solid transparent;
cursor: pointer;
text-transform: uppercase;
letter-spacing: .4rem;
outline: .2rem solid transparent;
outline-offset: .6rem;
overflow: hidden;
user-select: none;
}
// windows high contrast mode /start
// =================================
@media screen and (-ms-high-contrast: active) {
& {
color: buttonText;
border: 0;
outline-color: currentColor;
outline-offset: .2rem;
}
&:hover,
&:focus {
background: highlight;
}
&::before,
&>.span1,
&>.span2 {
display: none;
}
}
// ===============================
// windows high contrast mode /end
&::before {
content: " ";
display: inline-block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:
linear-gradient(to right, hsla(0, 0%, 94%, .6) 0px, transparent 2px, transparent 2px),
linear-gradient(to left, hsla(0, 0%, 94%, .6) 0px, transparent 2px, transparent 2px),
linear-gradient(to bottom, hsla(0, 0%, 94%, .6) 0px, transparent 2px, transparent 2px),
linear-gradient(to top, hsla(0, 0%, 94%, .6) 0px, transparent 2px, transparent 2px);
opacity: .1;
}
&>* {
display: inline-block;
position: absolute;
z-index: -1;
}
&>.span1 {
width: 110%;
height: 110%;
border-radius: 100%;
background: radial-gradient(circle at center, hsla(0, 0%, 94%, .6), transparent);
transform: translate(-50%, -50%);
filter: blur(4rem);
opacity: 0;
// windows high contrast mode /start
// =================================
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
display: none;
}
// windows high contrast mode /end
// ===============================
}
&>.span2 {
width: 0;
height: 0;
border-radius: 100%;
transform: translate(-50%, -50%);
//background: hsl(0, 0%, 94%); // uncomment this if you need background on .span2
box-shadow: 0 0 0 0 hsl(0, 0%, 94%), inset 0 0 1rem hsl(0, 0%, 94%);
opacity: .4;
}
// firefox dotted border on focus /start
// =====================================
&::-moz-focus-inner {
border: 0;
padding: 0;
}
// ===================================
// firefox dotted border on focus /end
&:active {
transform: scale(.98); // <- this, does not work, when using keyboard in Firefox
}
&:focus {
& {
border-width: .2rem; // does not needed, but for Windows High Contrast Mode.
outline-color: hsla(0, 0%, 94%, .2); // really bad idea to use alpha in outline-color
}
&>.span1 {
top: 90% !important;
left: 50% !important;
opacity: 1 !important;
}
}
}
// Border Issue -- Outside Of The Box And Not Giving The Result I Want (Little Light Effect)
/*
.btn {
& {
border: .4rem solid hsla(0, 0%, 94%, .1);
}
}
*/
// Colored Background --removes outline (z-index issue)
/*
.btn {
&::after {
content: " ";
display: block;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: linear-gradient(to right, hsl(220, 50%, 34%), hsl(320, 50%, 34%));
z-index: -2;
}
}
*/
// Original Light Effect -(hover over the button to see)
/*
.btn {
&::after {
content: "here";
position: absolute;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
&::before {
background: hsl(0, 0%, 15%);
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: calc(100% - 2px);
height: calc(100% - 2px);
opacity: 1;
}
}
*/
.abs-site-link {
position: fixed;
bottom: 20px;
left: 20px;
color: hsla(0, 0%, 100%, .6);
font-size: 1.6rem;
}
/* ?(Fluent Design)-> is by Microsoft, used in Windows 10 devices and platforms. */
// code might be messy
// ===================
var btn = document.querySelector(".btn");
function addSpans(btn) {
var span1 = document.createElement("span");
span1.className = "span1";
var span2 = document.createElement("span");
span2.className = "span2";
btn.appendChild(span1);
btn.appendChild(span2);
}
function mouseEnter(span) {
span.style.opacity = "1";
}
function mouseLeave(span) {
span.style.opacity = "0";
}
function mouseDown(span) {
span.style.transition = "box-shadow .6s";
span.style.boxShadow = "0 0 10rem 4rem hsl(0, 0%, 94%), inset 0 0 1rem hsl(0, 0%, 94%)";
span.style.width = "2rem";
span.style.height = "2rem";
}
function mouseUp(span) {
span.style.transition = "box-shadow 0s";
span.style.boxShadow = "0 0 0 0 hsl(0, 0%, 94%), inset 0 0 1rem hsl(0, 0%, 94%)";
span.style.width = "0";
span.style.height = "0";
}
function mouseMove(span, e) {
span.style.top = e.offsetY + "px";
span.style.left = e.offsetX + "px";
}
function keyDown(span) {
mouseDown(span);
span.style.top = "100%";
span.style.left = "50%";
}
window.addEventListener("load", addSpans(btn));
var span1 = btn.querySelector(".span1");
var span2 = btn.querySelector(".span2");
// mouse events
// ============
// edge issue
// not applying filter: blur() properly
if (window.navigator.userAgent.indexOf("Edge") > -1) {
span1.style.display = "none";
} else {
btn.addEventListener("mouseenter", function() { mouseEnter(span1) });
btn.addEventListener("mouseleave", function() { mouseLeave(span1) });
btn.addEventListener("mousemove", function(e) { mouseMove(span1, e) });
}
btn.addEventListener("mouseleave", function() { mouseUp(span2)} );
btn.addEventListener("mousemove", function(e) { mouseMove(span2, e) });
btn.addEventListener("mousedown", function() { mouseDown(span2) });
btn.addEventListener("mouseup", function() { mouseUp(span2) });
// keyboard events
// ===============
btn.addEventListener("keydown", function(e) {
if(e.key === " " && (e.code === "Space" || e.keyCode === 32) || e.key === "Spacebar" && e.keyCode === 32) {
keyDown(span2)
}
})
btn.addEventListener("keyup", function(e) {
if(e.key === " " && (e.code === "Space" || e.keyCode === 32) || e.key === "Spacebar" && e.keyCode === 32) {
mouseUp(span2)
}
})
// touch events
// ============
btn.addEventListener("touchstart", function() { keyDown(span2) });
btn.addEventListener("touchend", function() { mouseUp(span2) });
Also see: Tab Triggers