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 class="extern">
<h2>Analizador de contraste de colores</h2>
<p class="fx"><span>
<label>Color de fondo: </label>
<input type="text" class="c1" name="background" value="#152B39">
</span>
<span>
<label>Color del texto: </label>
<input type="text" class="c2" name="text" value="#abcdef">
</span></p>
<div class="el">
<h3 class="large"></h3>
<p class="normal"></p>
<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia
voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi
tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui
in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
</p>
<div class="output">8.8</div>
</div>
<h2>La normativa</h2>
<p>
El nivel AA: requiere un ratio de contraste de 4.5:1 para texto normal <em>( Esto equivale a un aprobado justo )</em></p>
<p>El nivel AAA: requiere un ratio de contraste de 7:1 para texto normal. <em>( Esto equivale a un aprobado con notable )</em></p>
<p>Definimos "texto grande" como texto de mínimum 14pt ( 18px ) y en negrita, o de mínimum 18pt ( 24px ).</p>
<p><em><a target="_blank" href="https://www.w3.org/TR/WCAG/#visual-audio-contrast">Web Content Accessibility Guidelines (WCAG) 2.0 <img class="data_image" width="12" height="12" alt="star" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAA/klEQVQoU3WQMZIBYRCFX48Jtgi4gZHZmkhAihsQErnBrhvsDRxhCIwQJyA2gRGokuEGEmqr7GrdGPUPNRP98/73/a9fE4zv0w++LeBHpKyp6/mfUN+0ynN6vSiOlk6K//qiVy9AlwlhijFLBJzxMpc+nWdEWK3blc7jge0TcP2AX1MAHqjZHS46APVAyMUAjZaLncXsgXj6NBN5zNhLWj4G6I91QU0KfR3TdiFzOjcg5nsHeyKdQvE0bqV1pIh2/UVf5qsSyDE3o9vT8m+AmhQCY64J0UOq6zJ2zdIhlmCWN5NN/Qa8b+mumAmRh4qjoJYE/H7YoY4RS0gyJ+lXBviSDaxQWVkAAAAASUVORK5CYII=" /></a></em></p>
</div>
html {
font-size: 100%;
margin: 0;
padding: 0;
font-family: Arial, Helvetica, sans-serif;
}
h2 {
color: #152B39;
margin: 1em 0;
border-bottom: 1px solid #d9d9d9;
/*font-family:Georgia, "Times New Roman", Times, serif;*/
}
em {
font-family: serif;
}
a {
text-decoration: none;
color: #2798ba;
}
a:hover {
text-decoration: underline;
}
.extern {
max-width: 55rem;
padding: 0 1rem;
margin: 4rem auto;
}
.el {
display: block;
border: 1px solid #d9d9d9;
max-width: 50rem;
min-width:20rem;
padding: 2em;
margin-right: 1.5em;
line-height: 150%;
position: relative;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
p.fx {
display: flex;
}
input {
margin-bottom: 2em;
padding: .5em;
background-color: white;
border: 1px solid #cccccc;
-webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
}
input:focus {
-webkit-box-shadow: 0 0 5px #999999;
-moz-box-shadow: 0 0 5px #999999;
box-shadow: 0 0 5px #999999;
border-color: #999999;
outline: none;
}
label {
margin-right: 1em;
}
p.fx span {
flex: 1 0 50%;
}
.large {
font-size: 1.8em;
font-weight: bold
}
.normal {
font-size: 1em;
}
.output {
font-size: 200%;
width: 3.5em;
height: 3.5em;
text-align: center;
line-height: 350%;
border-radius: 50%;
background-color: #6ab150;
color: white;
position: absolute;
top: -.7em;
left: calc(100% - 2.8em);
box-shadow: -.1em -.1em .5em rgba(0, 0, 0, .5) inset;
}
function cz_validateHex(hex) {
return /(^#?[0-9A-F]{6}$)|(^#?[0-9A-F]{3}$)/i.test(hex);
}
function cz_validateHsl(hsl) {
return /(^hsl[(]\s*0*(?:[12]?\d{1,2}|3(?:[0-5]\d|60))\s*(?:\s*,\s*0*(?:\d\d?(?:\.\d+)?\s*%|\.\d+\s*%|100(?:\.0*)?\s*%)){2}\s*[)]$)/i.test(hsl);
}
function cz_validateRgb(rgb) {
return /(^(?:(?:^|,\s*)([01]?\d\d?|2[0-4]\d|25[0-5])){3}$)/i.test(rgb);
}
function helper_hsl2hex(v1, v2, vh) { //to be used width hsl2hex();
if (vh < 0) {
vh += 1;
};
if (vh > 1) {
vh -= 1;
};
if ((6 * vh) < 1) {
return (v1 + (v2 - v1) * 6 * vh);
};
if ((2 * vh) < 1) {
return (v2);
};
if ((3 * vh) < 2) {
return (v1 + (v2 - v1) * ((2 / 3 - vh) * 6));
};
return v1;
}
function cz_getHslRy(hsl) {
hsl = hsl.slice(4);
hsl = hsl.split(")");
hslRy = hsl[0].split(",");
return hslRy.map(function(c) {
return c.replace("%", "");
})
}
function cz_hsl2rgb(hsl) { //hsl($h,$s%,$l%);
var hslRy = getHslRy(hsl);
h = hslRy[0] / 360;
s = hslRy[1] / 100;
l = hslRy[2] / 100;
if (s == 0) //gray
{
r = l * 255;
g = l * 255;
b = l * 255;
} else {
if (l < 0.5) //dark
{
v2 = l * (1 + s);
} else //light
{
v2 = (l + s) - (s * l);
};
v1 = 2 * l - v2;
r = 255 * helper_hsl2hex(v1, v2, h + (1 / 3));
g = 255 * helper_hsl2hex(v1, v2, h);
b = 255 * helper_hsl2hex(v1, v2, h - (1 / 3));
}
return [r, g, b];
/*OK*/
} //console.log(hsl2rgb("hsl(45,100%,50%)"))
function cz_hex2rgb(hexColor) {
hexColor = hexColor.replace("#", "");
if (hexColor.length == 6) {
var redhex = hexColor.substr(0, 2);
var greenhex = hexColor.substr(2, 2);
var bluehex = hexColor.substr(4, 2);
} else if (hexColor.length == 3) {
var redhex = hexColor.substr(0, 1) + hexColor.substr(0, 1);
var greenhex = hexColor.substr(1, 1) + hexColor.substr(1, 1);
var bluehex = hexColor.substr(2, 1) + hexColor.substr(2, 1);
}
console.log(redhex);
var rgbRy = [];
rgbRy[0] = parseInt(redhex, 16);
rgbRy[1] = parseInt(greenhex, 16);
rgbRy[2] = parseInt(bluehex, 16);
return rgbRy; /*OK*/
} //console.log(hex2rgb("ffbf00"))
function cz_rgb2rgb(rgb) {
rgb = rgb.slice(4);
rgb = rgb.split(")");
rgbRy = rgb[0].split(",");
return rgbRy.map(function(c) {
return parseInt(c);
});
} //console.log(rgb2rgb("rgb(255,191,0)"))
function cz_whatColor(str) {
if (cz_validateHsl(str)) {
return cz_hsl2rgb(str);
} else if (cz_validateRgb(str)) {
return cz_rgb2rgb(str);
} else if (cz_validateHex(str)) {
return cz_hex2rgb(str);
} else {
return ([255, 255, 255]);
}
}
/* LEA VEROU https://www.w3.org/TR/UNDERSTANDING-WCAG20/visual-audio-contrast-contrast.html*/
function cz_getRelativeLuminance(rgb) { //relative luminance
var rgb = rgb.map(function(c) {
c /= 255;
return c < .03928 ? c / 12.92 : Math.pow((c + .055) / 1.055, 2.4);
});
return (21.26 * rgb[0] + 71.52 * rgb[1] + 7.22 * rgb[2]) / 100
}
function cz_colorContrast(c1, c2) {
var l1 = cz_getRelativeLuminance(c1);
var l2 = cz_getRelativeLuminance(c2);
var ret = (l1 + .05) / (l2 + .05);
// 0.05 for not dividing with 0
return ret < 1 ? 1 / ret : ret;
}
var normal = document.querySelector(".normal");
var large = document.querySelector(".large");
var el = document.querySelector(".el");
var output = document.querySelector(".output");
var inputBackground = document.querySelector(".c1")
var inputText = document.querySelector(".c2")
var backgroundColor = inputBackground.value;
var textColor = inputText.value;
var c1 = cz_whatColor(backgroundColor);
var c2 = cz_whatColor(textColor);
function cz_getContrast() {
backgroundColor = inputBackground.value;
textColor = inputText.value;
c1 = cz_whatColor(backgroundColor);
c2 = cz_whatColor(textColor);
el.style.backgroundColor = "rgb(" + c1[0] + "," + c1[1] + "," + c1[2] + ")";
el.style.color = "rgb(" + c2[0] + "," + c2[1] + "," + c2[2] + ")";
large.innerHTML = "Para texto grande: ";
normal.innerHTML = "Para texto normal: ";
var cc = cz_colorContrast(c1, c2);
output.innerHTML = parseFloat(cc).toFixed(1);
if (cc >= 7) {
large.innerHTML += " aprobado AAA";
normal.innerHTML += " aprobado AAA";
output.style.backgroundColor = "#6ab150";
output.style.color = "#fff";
} else if (cc >= 4.5 && cc < 7) {
large.innerHTML += " aprobado AAA";
normal.innerHTML += " aprobado AA";
output.style.backgroundColor = "#ffff00";
output.style.color = "#222";
} else if (cc >= 3 && cc < 4.5) {
large.innerHTML += " aprobado AA";
normal.innerHTML += " falla";
output.style.backgroundColor = "#ff7b00";
output.style.color = "#fff";
} else {
large.innerHTML += " falla";
normal.innerHTML += " falla";
output.style.backgroundColor = "#dd0000";
output.style.color = "#fff";
}
}
window.addEventListener("load", cz_getContrast, false);
inputBackground.addEventListener("input", cz_getContrast, false);
inputText.addEventListener("input", cz_getContrast, false);
Also see: Tab Triggers