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.
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@500&display=swap" rel="stylesheet">
<details class="c-accordion">
<summary class="c-accordion_ttl">Q. CSSのみでアコーディオンを作ることはできますか?</summary>
<p class="c-accordion_txt">
はい、detailsとsummary要素を使用していただくことで、HTMLのみでアコーディオンの挙動を作成することができます。<br>
また、CSSを付与することで、デザインもお好きに変更していただくことができます。
アコーディオンが開いているときのスタイルははsummary要素の[open]属性を使ってデザインしていきましょう。
</p>
</details>
<details class="c-accordion red">
<summary class="c-accordion_ttl">Q. CSSのみでアコーディオンを作ることはできますか?</summary>
<p class="c-accordion_txt">
はい、detailsとsummary要素を使用していただくことで、HTMLのみでアコーディオンの挙動を作成することができます。<br>
また、CSSを付与することで、デザインもお好きに変更していただくことができます。
アコーディオンが開いているときのスタイルははsummary要素の[open]属性を使ってデザインしていきましょう。
</p>
</details>
* {
font-family: "Noto Sans JP", sans-serif;
}
:root {
--main-bg-color: #4a90e2;
--sub-bg-color: #d32b75;
}
.c-accordion {
width: 100%;
max-width: 700px;
margin-left: auto;
margin-right: auto;
margin-top: 80px;
border-radius: 8px;
border-style: solid;
border-width: 4px;
border-color: var(--main-bg-color);
margin-bottom: 32px;
&_ttl {
background-image: url("data:image/svg+xml,%3Csvg width='28' height='29' viewBox='0 0 28 29' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 28.4248C21.732 28.4248 28 22.1568 28 14.4248C28 6.69282 21.732 0.424805 14 0.424805C6.26801 0.424805 0 6.69282 0 14.4248C0 22.1568 6.26801 28.4248 14 28.4248Z' fill='%234A90E2'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.5629 9.44141C13.8797 9.44141 14.1452 9.70697 14.156 10.0346L14.4282 18.3384C14.4389 18.666 14.1908 18.9316 13.8739 18.9316C13.5571 18.9316 13.2915 18.666 13.2808 18.3384L13.0086 10.0346C12.9979 9.70697 13.246 9.44141 13.5629 9.44141Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.12875 14.186C9.11801 13.8584 9.36616 13.5928 9.683 13.5928H17.7147C18.0315 13.5928 18.2971 13.8584 18.3078 14.186C18.3186 14.5136 18.0704 14.7791 17.7536 14.7791H9.72188C9.40504 14.7791 9.13948 14.5136 9.12875 14.186Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
background-position: right 24px center;
background-size: 28px;
background-repeat: no-repeat;
list-style: none;
padding: 32px;
cursor: pointer;
font-size: 18px;
color: var(--main-bg-color);
font-weight: bold;
}
&[open] &_ttl {
background-image: url("data:image/svg+xml,%3Csvg width='29' height='29' viewBox='0 0 29 29' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14.2339 28.4248C21.9659 28.4248 28.2339 22.1568 28.2339 14.4248C28.2339 6.69282 21.9659 0.424805 14.2339 0.424805C6.5019 0.424805 0.233887 6.69282 0.233887 14.4248C0.233887 22.1568 6.5019 28.4248 14.2339 28.4248Z' fill='%234A90E2'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.36264 14.186C9.35191 13.8584 9.60005 13.5928 9.9169 13.5928H17.9486C18.2654 13.5928 18.531 13.8584 18.5417 14.186C18.5524 14.5136 18.3043 14.7791 17.9874 14.7791H9.95578C9.63894 14.7791 9.37338 14.5136 9.36264 14.186Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
}
&_txt {
padding: 32px;
padding-top: 0;
margin-top: 0;
color: #222222;
}
// 色違いパターン
&.red {
border-color: var(--sub-bg-color);
.c-accordion_ttl {
color: var(--sub-bg-color);
background-image: url("data:image/svg+xml,%3Csvg width='28' height='29' viewBox='0 0 28 29' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14 28.4248C21.732 28.4248 28 22.1568 28 14.4248C28 6.69282 21.732 0.424805 14 0.424805C6.26801 0.424805 0 6.69282 0 14.4248C0 22.1568 6.26801 28.4248 14 28.4248Z' fill='%23d32b75'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M13.5629 9.44141C13.8797 9.44141 14.1452 9.70697 14.156 10.0346L14.4282 18.3384C14.4389 18.666 14.1908 18.9316 13.8739 18.9316C13.5571 18.9316 13.2915 18.666 13.2808 18.3384L13.0086 10.0346C12.9979 9.70697 13.246 9.44141 13.5629 9.44141Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.12875 14.186C9.11801 13.8584 9.36616 13.5928 9.683 13.5928H17.7147C18.0315 13.5928 18.2971 13.8584 18.3078 14.186C18.3186 14.5136 18.0704 14.7791 17.7536 14.7791H9.72188C9.40504 14.7791 9.13948 14.5136 9.12875 14.186Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
}
&[open] .c-accordion_ttl {
background-image: url("data:image/svg+xml,%3Csvg width='29' height='29' viewBox='0 0 29 29' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M14.2339 28.4248C21.9659 28.4248 28.2339 22.1568 28.2339 14.4248C28.2339 6.69282 21.9659 0.424805 14.2339 0.424805C6.5019 0.424805 0.233887 6.69282 0.233887 14.4248C0.233887 22.1568 6.5019 28.4248 14.2339 28.4248Z' fill='%23d32b75'/%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M9.36264 14.186C9.35191 13.8584 9.60005 13.5928 9.9169 13.5928H17.9486C18.2654 13.5928 18.531 13.8584 18.5417 14.186C18.5524 14.5136 18.3043 14.7791 17.9874 14.7791H9.95578C9.63894 14.7791 9.37338 14.5136 9.36264 14.186Z' fill='white' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A");
}
}
}
Also see: Tab Triggers