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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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 id="accordion">
<div class="accordion__panel">
<h2 class="accordion__header">
<!-- Använd button-elementet för att rubrikerna ska bli interaktiva och kunna hanteras av tangentbord -->
<!-- Lägg till aria-controls för att berätta vilken komponenet som triggas vid klick -->
<!-- Aria-expanded indikerar huruvida innehållet nedanför är utfällt eller inte -->
<!-- Eftersom det finns flera paneler används aria-selected för att berätta vilken som är aktiv/öppen -->
<button class="accordion__button" id="accordion__header-1" aria-controls="accordion__inner_1" aria-expanded="false" aria-selected="false">
Varför är WAI-ARIA roller viktiga?
<!-- Ofta vill en använda ett plustecken eller en ikon för att indikera att det finns innehåll att fälla ut
då är det viktigt att göra teckent eller ikonen osynlig för skärmläsare så att den inte läser ut ".... plus"-->
<span aria-hidden="true">+</span>
</button>
</h2>
<!-- Använd aria-hidden för att göra skärmläsaren medveten om att sektionen är dold -->
<!-- Aria-labelledby fungerar som en referens till knappen som triggar innehållet -->
<div class="accordion__inner" id="accordion__inner_1" aria-labelledby="accordion__header-1" aria-hidden="true">
<p>
WAI-ARIA hjälper t.ex. skärmläsare att läsa av huruvida en länk eller knapp öppnar en dropdown-meny vid klick.
</p>
</div>
</div>
<div class="accordion__panel">
<h2 class="accordion__header">
<button class="accordion__button" aria-controls="accordion__inner_2" aria-expanded="false" aria-selected="false">
Varför är det viktigt att använda button elementet?
<span aria-hidden="true">+</span>
</button>
</h2>
<div class="accordion__inner" id="accordion__inner_2" aria-labelledby="accordion__header-2" aria-hidden="true">
<p>
Knappar och länkar kan nås via tangentbordet eftersom de har tab-index. En div har inte detta och är därför
olämplig att använda som en knapp.
</p>
</div>
</div>
<div class="accordion__panel">
<h2 class="accordion__header">
<button class="accordion__button" aria-controls="accordion__inner_3" aria-expanded="false" aria-selected="false">
Vad är WCAG en förkortning för?
<span aria-hidden="true">+</span>
</button>
</h2>
<div class="accordion__inner" id="accordion__inner_3" aria-labelledby="accordion__header-3" aria-hidden="true">
<!-- I det här scenariot ligger menyn på en svensk webbsida men just där här stycket är skrivet på engelska.
Om vi använder lang attributet kan en skärmläsare känna av språkförändringen och anpassa sig efter det nya språket. -->
<p lang="en">
Web Content Accessibility Guidelines.
</p>
</div>
</div>
</div>
* {
font-family: 'Helvetica';
}
#accordion {
width: 700px;
}
.accordion__panel {
margin: 0.5rem 0;
}
.accordion__header {
padding: 1rem;
margin: 0;
background-color: #C0D890;
width: 100%;
border: 1px solid transparent;
}
.accordion__inner {
display: none;
}
.accordion__button {
border: none;
font: inherit;
color: inherit;
background-color: transparent;
display: flex;
justify-content: space-between;
width: 100%;
}
.accordion__inner {
border: 1px solid #C0D890;
width: 100%;
padding: 0.5rem 1rem;
}
/*
* Hämta alla dragspelsrubriker och deras innehåll
*/
var accordionHeaders = $('#accordion').find('.accordion__header');
var accordionContents = $('#accordion').find('.accordion__inner');
accordionHeaders.click(function(){
var accordionContent = $(this).next();
var accordionButton = $(this).find('.accordion__button');
/*
* Stäng alla paneler och öppna bara den som användaren klickade på
*/
accordionContent.slideToggle(400);
accordionHeaders.not($(this)).next().slideUp(350);
/*
* Välj alla rubriker och sätt aria-expanded och aria-selected till false
* Välj sedan deras innehåll för att sätta aria-hidden till true.
* Skärmläsaren uppfattar detta som att ingen panel har blivit klickad på
* och att allt innehåll är ihopfällt
*/
accordionHeaders.not($(this)).find('.accordion__button').attr('aria-selected', 'false').attr('aria-expanded', 'false');
accordionContents.not(accordionContent).attr('aria-hidden', 'true');
/*
* Välj den panel som blev klickad på och berätta att denna har blivit vald
* och att innehållet nu är öppet och tillgängligt.
*/
var values = ['false', 'true'];
toggleAttributes(accordionButton, 'aria-selected', values);
toggleAttributes(accordionButton, 'aria-expanded', values);
toggleAttributes(accordionContent, 'aria-hidden', values);
});
/*
* Hjälpfunktion som skiftar värde på det attribut som skickas in
*/
function toggleAttributes(element, attribute, value){
if ($(element).attr(attribute) === value[0]){
$(element).attr(attribute, value[1]);
} else if ($(element).attr(attribute) === value[1]){
$(element).attr(attribute, value[0]);
}
};
Also see: Tab Triggers