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.
<body id="background">
<div>
<div class="card">
<div id="header">
<input type="text" id="header-title" value="The Metamorphosis"
style="font-weight: bold;color: #ffffff;">
</div>
<div id="content0">
<textarea id="content0-title"
rows="4">One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin. He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections.</textarea>
</div>
<div id="content1" style="flex-direction: column;">
<div>
Target:
<label><input onchange="onTarget(this)" type="radio" name="target" id="target-background"
checked="checked">background</label>
<label><input onchange="onTarget(this)" type="radio" name="target" id="target-header">header</label>
<label><input onchange="onTarget(this)" type="radio" name="target"
id="target-content0">content0</label>
<label><input onchange="onTarget(this)" type="radio" name="target"
id="target-content1">content1</label>
<label><input onchange="onTarget(this)" type="radio" name="target" id="target-footer">footer</label>
</div>
<div id="setprop" style="align-items: center;">
<div>
BG Color:
<input id="background-color" type="color" onchange="onChange(this)">
</div>
<div>
BG Pattern:
<select id="background-image" onchange="onChange(this)">
<option value="none">none</option>
<option value="pattern_a">A</option>
<option value="pattern_b">B</option>
<option value="pattern_c">C</option>
<option value="pattern_d">D</option>
<option value="stripe_1">stripe -</option>
<option value="stripe_2">stripe |</option>
<option value="stripe_3">stripe \</option>
<option value="stripe_4">stripe /</option>
</select>
</div>
<div>
Text Color:
<input id="color" type="color" onchange="onChange(this)">
</div>
<div>
Size(rem):
<input id="font-size" type="number" onchange="onChange(this)" step="0.1" style="width:45px;">
</div>
<div>
Bold:
<input id="font-weight" type="checkbox" onchange="onChange(this)">
</div>
</div>
<pre id="content1-title"></pre>
<button onclick="onDown()">BG Pattern Download</button>
</div>
<div id="footer">
<input type="text" id="footer-title" value="Franz Kafka 1915">
</div>
</div>
The bedding was hardly able to cover it and seemed ready to slide off any moment.
</div>
</body>
</html>
body {
background-color: #000000;
}
pre {
white-space: pre-wrap;
word-break: break-all;
}
.card {
margin: 20px;
filter: drop-shadow(0px 0px 2px #222222);
}
.card>div {
display: flex;
align-items: center;
padding: 5px 5px 5px 10px;
}
.card>div:nth-child(1) {
flex: 1;
}
.card>div:nth-child(1)>input,
.card>div:nth-last-child(1)>input {
background-color: rgba(0, 0, 0, 0);
border: none;
width: 100%;
}
.card>div:nth-child(2)>textarea,
.card>div:nth-child(3)>textarea {
background-color: rgba(0, 0, 0, 0);
border: none;
width: 100%;
border-radius: 3px;
vertical-align: top;
font-family: 'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', 'メイリオ', Meiryo, 'MS Pゴシック', sans-serif;
}
.card>div:nth-child(1) {
border-radius: 5px 5px 0px 0px;
}
.card>div:nth-last-child(1) {
border-radius: 0px 0px 5px 5px;
}
#footer-title {
text-align: right;
padding: 0px 10px 0px 0px;
}
#setprop {
display: flex;
}
#setprop>div {
margin-right: 10px;
}
var target = 'background';
var cssobj = {
'background': {
'background-color': '#333333',
'background-image': 'pattern_d',
'color': '#999999',
'font-size': '0.9rem',
'font-weight': 'normal'
},
'header': {
'background-color': '#222222',
'background-image': 'pattern_c',
'color': '#FFFFFF',
'font-size': '1rem',
'font-weight': 'bold'
},
'content0': {
'background-color': '#EEEEEE',
'background-image': 'none',
'color': '#000000',
'font-size': '0.9rem',
'font-weight': 'normal'
},
'content1': {
'background-color': '#444444',
'background-image': 'pattern_a',
'color': '#EEEEEE',
'font-size': '0.8rem',
'font-weight': 'normal'
},
'footer': {
'background-color': '#777777',
'background-image': 'stripe_4',
'color': '#333333',
'font-size': '0.8rem',
'font-weight': 'normal'
}
};
function initCSS() {
var keys = Object.keys(cssobj);
keys.map((key, index) => {
setProp(key, 'background-color', cssobj[key]['background-color']);
setProp(key, 'background-image', cssobj[key]['background-image']);
setProp(key, 'color', cssobj[key]['color']);
setProp(key, 'font-size', cssobj[key]['font-size']);
setProp(key, 'font-weight', cssobj[key]['font-weight']);
});
setTarget();
};
function onDown() {
var patternName = cssobj[target]['background-image'];
if (patternName == 'none') {
return;
}
// https://ja.javascript.info/blob
let link = document.createElement('a');
link.download = patternName + '.png';
link.href = getPatternData(patternName);
link.click();
URL.revokeObjectURL(link.href);
}
function onTarget(self) {
target = self.id.substr('target-'.length);
setTarget();
setCSS();
}
function setTarget() {
var style = document.getElementById(target).style;
document.getElementById('background-color').value = rgb2hex(style.backgroundColor);
document.getElementById('background-image').value = cssobj[target]['background-image'];
document.getElementById('color').value = rgb2hex(style.color);
document.getElementById('font-size').value = style['font-size'].replace(/[^0-9.]/g, '');
document.getElementById('font-weight').checked = style['font-weight'] == 'bold';
}
function setCSS() {
var html = '';
html += '#' + target + ' {<br>';
Object.keys(cssobj[target]).forEach((key) => {
if (key == 'background-image' && cssobj[target][key] != 'none') {
var data = getPatternData(cssobj[target][key]);
html += ' ' + key + ': url("' + data + '");<br>';
} else {
html += ' ' + key + ': ' + cssobj[target][key] + ';<br>';
}
});
html += '}';
document.getElementById('content1-title').innerHTML = html;
}
function rgb2hex(rgb) {
var list = rgb.replace(/[^0-9,]/g, '').split(',');
let hex = 0;
list.forEach((n, index) => {
hex += parseInt(n) * Math.pow(256, 2 - index);
})
var str = '000000' + hex.toString(16).toUpperCase();
return '#' + str.substr(str.length - 6);
}
function onChange(self) {
var declaration = self.id;
if (declaration == 'background-color') {
cssobj[target][declaration] = self.value;
setProp(target, declaration, self.value);
} else if (declaration == 'background-image') {
cssobj[target][declaration] = self.value;
setProp(target, declaration, cssobj[target][declaration]);
} else if (declaration == 'color') {
cssobj[target][declaration] = self.value;
setProp(target, declaration, self.value);
} else if (declaration == 'font-size') {
cssobj[target][declaration] = self.value + 'rem';
setProp(target, declaration, self.value + 'rem');
} else if (declaration == 'font-weight') {
cssobj[target][declaration] = self.checked ? 'bold' : 'normal';
setProp(target, declaration, self.checked ? 'bold' : 'normal');
}
}
function setProp(target, declaration, value) {
if (declaration == 'background-color') {
document.getElementById(target).style.backgroundColor = value;
} else if (declaration == 'background-image') {
if (value == 'none') {
document.getElementById(target).style.backgroundImage = 'none';
} else {
var data = getPatternData(value);
document.getElementById(target).style.backgroundImage = 'url("' + data + '")';
}
} else if (declaration == 'color') {
document.getElementById(target).style.color = value;
if (document.getElementById(target + '-title')) {
document.getElementById(target + '-title').style.color = value;
}
} else if (declaration == 'font-size') {
document.getElementById(target).style['font-size'] = value;
if (document.getElementById(target + '-title')) {
document.getElementById(target + '-title').style['font-size'] = value;
}
} else if (declaration == 'font-weight') {
document.getElementById(target).style['font-weight'] = value;
if (document.getElementById(target + '-title')) {
document.getElementById(target + '-title').style['font-weight'] = value;
}
}
setCSS();
}
function getPatternData(name) {
return pngHeader + this[name];
}
var pngHeader = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNi1jMTQ1IDc5LjE2MzQ5OSwgMjAxOC8wOC8xMy0xNjo0MDoyMiAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaH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