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.
<section class="qna" itemscope itemtype="https://schema.org/FAQPage">
<h2>Вопросы и ответы</h2>
<div class="qna__items">
<details class="qna__item" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
<summary class="qna__question" itemprop="name">Что такое HTML?</summary>
<div class="qna__answer" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
<div class="qna__text" itemprop="text">
<p>HTML расшифровывается как HyperText Markup Language (язык гипертекстовой разметки). Это язык разметки документов во Всемирной паутине (World Wide Web, WWW). HTML — это стандартизированный язык, позволяющий составлять форматированный текст. Браузер интерпретирует его и отображает на экране элементы веб-страниц.</p>
</div>
</div>
</details>
<details class="qna__item" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
<summary class="qna__question" itemprop="name">Зачем использовать списки в HTML?</summary>
<div class="qna__answer" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
<div class="qna__text" itemprop="text">
<p>Списки делают информацию более наглядной и удобной дляотображения элементов списка) тоже можно использовать различные теги. восприятия. Более того, внутри списков (точнее, для произвольного отображения элементов списка) тоже можно использовать различные теги.</p>
</div>
</div>
</details>
<details class="qna__item" itemscope itemprop="mainEntity" itemtype="https://schema.org/Question">
<summary class="qna__question" itemprop="name">Для чего нужны таблицы стилей (CSS)?</summary>
<div class="qna__answer" itemscope itemprop="acceptedAnswer" itemtype="https://schema.org/Answer">
<div class="qna__text" itemprop="text">
<p>Таблицы стилей позволяют задать чёткие правила, которые определяют внешний вид контента, тех или иных HTML-элементов и всей страницы в целом. Более того, одни и те же правила можно применять сразу к нескольким веб-страницам, что упрощает сохранение и, при необходимости, изменение единого стиля сайта.</p>
</div>
</div>
</details>
</div>
</section>
body {
font-family: sans-serif;
font-size: 16px;
}
p {
margin: 0;
}
.qna {
--animation-duration: 0.3s;
--border-color: #ccc;
width: clamp(300px, 50%, 800px);
margin: 50px auto;
&__item {
margin: -1px 0 0;
border: 1px solid var(--border-color);
transition: var(--animation-duration);
&:not(.js-details)[open],
&.is-open {
--border-color: #666;
position: relative;
}
}
&__question {
position: relative;
padding: 20px 50px 20px 20px;
list-style: none; /* убираем стандартный маркер Firefox */
cursor: pointer;
&::after {
content: '';
position: absolute;
top: calc(50% - 4px);
right: 20px;
width: 12px;
height: 8px;
background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 12 8'%3E%3Cpath stroke='%23999' stroke-width='2' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
transition: var(--animation-duration);
.qna__item:not(.js-details)[open] &,
.qna__item.is-open & {
transform: rotate(-180deg);
}
}
&::-webkit-details-marker {
display: none; /* убираем стандартный маркер Chrome */
}
}
&__answer {
.js-details & {
max-height: 0;
overflow: hidden;
animation: slideUp var(--animation-duration);
}
.js-details.is-open & {
max-height: none;
animation: slideDown var(--animation-duration);
}
.js-details.is-open.is-animating & {
max-height: var(--details-height);
}
}
&__text {
padding: 0 20px 20px;
}
}
@keyframes slideUp {
0% {
max-height: var(--details-height);
opacity: 1;
}
100% {
max-height: 0;
opacity: 0;
}
}
@keyframes slideDown {
0% {
max-height: 0;
opacity: 0;
}
100% {
max-height: var(--details-height);
opacity: 1;
}
}
document.querySelectorAll('.qna__item').forEach(item => {
const minimizeSiblings = true
const question = item.querySelector('.qna__question')
const answer = item.querySelector('.qna__answer')
const cssDuration = getComputedStyle(answer).getPropertyValue('--animation-duration')
const animationDuration = Number.parseInt(Number.parseFloat(cssDuration) * (/\ds$/.test(cssDuration) ? 1000 : 1))
const setHeight = () => answer.style.setProperty('--details-height', `${answer.scrollHeight}px`)
item.classList.add('js-details')
const onClick = event => {
setHeight()
let isAnimating = true
item.classList.toggle('is-open')
item.classList.add('is-animating')
setTimeout(() => {
item.classList.remove('is-animating')
}, animationDuration)
if (item.open) {
event.preventDefault()
if (isAnimating) return
setTimeout(() => {
item.open = false
isAnimating = false
}, animationDuration)
}
if (!minimizeSiblings) return
const siblings = [...item.parentNode.children]
.filter(el => el.classList.contains('js-details'))
.filter(el => el !== event.target.parentNode)
for (const el of siblings) {
el.classList.remove('is-open')
setTimeout(() => {
el.open = false
}, animationDuration)
}
}
question.addEventListener('click', onClick)
})
Also see: Tab Triggers