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.
<form>
<input type="text" class="input-text" placeholder="name">
<input type="email" class="input-email" name="" id="" placeholder="sample@gmail.com">
<label class="check-label"><input class="check-test" type="checkbox" name="check-name"><span class="check-label-span">チェック1</span></label>
<label class="check-label"><input class="check-test" type="checkbox" name="check-name"><span class="check-label-span">チェック2</span></label>
<label class="check-label"><input class="check-test" type="checkbox" name="check-name"><span class="check-label-span">チェック3</span></label>
<label class="radio-label"><input class="radio-test" type="radio" name="radio-name"><span
class="radio-label-span">ラジオ1</span></label>
<label class="radio-label"><input class="radio-test" type="radio" name="radio-name"><span
class="radio-label-span">ラジオ2</span></label>
<label class="radio-label"><input class="radio-test" type="radio" name="radio-name"><span
class="radio-label-span">ラジオ3</span></label>
<div class="custom-file-upload">
<input type="file" class="input-file" id="fileInput" aria-label="ファイルを選択">
<button type="button" id="fileLabel" onclick="triggerFileInput()">ファイルを選択</button>
<button type="button" onclick="clearFile()">クリア</button>
</div>
<div class="select-container">
<select class="select-box" name="都道府県を選んで下さい。" id="">
<option value="sample">サンプル1</option>
<option value="sample">サンプル2</option>
<option value="sample">サンプル3</option>
<option value="sample">サンプル4</option>
<option value="sample">サンプル5</option>
</select>
</div>
<textarea class="textarea-box" rows="5" cols="30"></textarea>
<input type="submit" class="input-submit" value="送信する">
</form>
.input-text, .input-email, .input-file, .input-submit {
padding: 0;
border: none;
border-radius: 0;
outline: none;
background: none;
box-shadow: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
/* リセットじゃない部分 */
border: 1px solid rgba(0, 0, 0, 0.16);
}
.input-text:focus,
.input-email:focus {
outline: 2px solid #3498db;
/* 自由な色に変更可能 */
outline-offset: 0;
}
.check-test {
position: absolute;
opacity: 0;
z-index: -1;
}
.check-label {
position: relative;
display: inline-block;
padding-left: 30px; /* カスタムチェックボックスにスペースを確保 */
margin-bottom: 5px;
cursor: pointer;
}
/* Custom Checkbox Design */
.check-label-span::before {
content: "";
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid #000; /* Border color */
border-radius: 4px; /* Optional: for rounded corners */
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}
/* Custom Checkbox Checked State */
.check-test:checked + .check-label-span::before {
border-color: #3498db; /* Border color when checked */
}
.check-test:checked + .check-label-span::after {
content: "";
display: block;
width: 5px;
height: 10px;
border: solid #000;
border-width: 0 2px 2px 0;
position: absolute;
top: 50%;
left: 8px; /* Adjusted position */
transform: translateY(-50%) rotate(45deg);
}
/* Focus State */
.check-test:focus + .check-label-span::before {
outline: 2px solid #3498db; /* Outline color when focused */
}
/* Hide default radio button */
.radio-test {
position: absolute;
opacity: 0;
z-index: -1;
}
/* Label positioning context */
.radio-label {
position: relative;
display: inline-block;
padding-left: 30px; /* Space for the custom radio button */
margin-bottom: 5px;
cursor: pointer;
}
/* Custom Radio Button Design */
.radio-label-span::before {
content: "";
display: inline-block;
width: 20px;
height: 20px;
border: 2px solid #000; /* Border color */
border-radius: 50%; /* Rounded corners for radio button */
position: absolute;
left: 0;
top: 50%;
transform: translateY(-50%);
}
/* Custom Radio Button Checked State */
.radio-test:checked + .radio-label-span::after {
content: "";
display: block;
width: 10px;
height: 10px;
background-color: #000; /* Fill color when checked */
border-radius: 50%; /* Rounded corners for checked state */
position: absolute;
top: 50%;
left: 7px; /* Centering the filled circle */
transform: translateY(-50%);
}
/* Focus State */
.radio-test:focus + .radio-label-span::before {
outline: 2px solid #3498db; /* Outline color when focused */
}
/* Style for the select box container */
.select-container {
position: relative;
display: inline-block;
width: 200px; /* Set a width */
margin-bottom: 20px;
}
/* Style for the select box */
.select-box {
padding: 10px;
border: 2px solid #000;
border-radius: 4px;
outline: none;
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
width: 100%; /* Make it fill the container */
font-size: 16px;
color: #000;
}
/* Arrow icon using a pseudo-element */
.select-container::after {
content: "";
position: absolute;
top: 50%;
right: 10px;
width: 0;
height: 0;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #000;
transform: translateY(-50%);
}
/* Focus State */
.select-box:focus {
border-color: #3498db; /* Border color when focused */
}
/* Style for the text area */
.textarea-box {
width: 100%; /* Set the width */
padding: 10px; /* Set padding */
border: 2px solid #000; /* Set border */
border-radius: 4px; /* Optional: for rounded corners */
font-size: 16px; /* Set font size */
resize: vertical; /* Allow vertical resize */
outline: none; /* Remove outline */
box-sizing: border-box; /* Include border and padding in the element's dimensions */
margin-bottom: 20px;
}
/* Style for the submit button */
.input-submit {
padding: 10px 20px; /* Set padding */
border: none; /* Remove border */
border-radius: 4px; /* Optional: for rounded corners */
background-color: #3498db; /* Set background color */
color: #fff; /* Set text color */
font-size: 16px; /* Set font size */
cursor: pointer; /* Set cursor to pointer */
transition: background-color 0.3s; /* Optional: for smooth color transition */
text-align: center;
}
/* Hover State */
.input-submit:hover {
background-color: #2980b9; /* Darken background color when hovered */
}
/* Active State */
.input-submit:active {
background-color: #1c598a; /* Darken background color when active */
}
/* Focus State */
.input-submit:focus {
outline: none; /* Remove outline */
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5); /* Add a soft outline */
}
.custom-file-upload {
position: relative;
display: inline-block;
}
.input-file {
display: none;
}
.custom-file-upload button {
padding: 10px;
border: 2px solid #000;
background-color: #f0f0f0;
border-radius: 4px;
cursor: pointer;
color: #000;
}
.custom-file-upload button:hover {
background-color: #d0d0d0;
}
.custom-file-upload button:focus {
border-color: #3498db; /* Border color when focused */
box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.5); /* Add a soft outline */
}
const fileInput = document.getElementById('fileInput');
const fileLabel = document.getElementById('fileLabel');
function triggerFileInput() {
fileInput.click();
}
fileInput.addEventListener('change', () => {
const fileName = fileInput.files[0] ? fileInput.files[0].name : 'ファイルを選択';
fileLabel.textContent = fileName;
});
function clearFile() {
fileInput.value = '';
fileLabel.textContent = 'ファイルを選択';
}
Also see: Tab Triggers