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.
Tweet!<h1>Labelling buttons</h1>
<h2>Text only</h2>
<p>
<button>Tweet!</button>
</p>
<h2>Text and Icon</h2>
<p>
<button>
<svg aria-hidden="true" width="28" height="28">
<use xlink:href="#twitter"></use>
</svg>
Tweet!
</button>
</p>
<h2>Icon-only using aria-label on the button</h2>
<p>
<button aria-label="Tweet!">
<svg aria-hidden="true" width="28" height="28">
<use xlink:href="#twitter"></use>
</svg>
</button>
</p>
<h2>Icon-only using aria-labelledby on the button</h2>
<h2 id="heading" role="presentation" style="font-size:1rem">Tweet!</h2>
<button aria-labelledby="heading">
<svg aria-hidden="true" width="28" height="28">
<use xlink:href="#twitter"></use>
</svg>
</button>
<h2>Icon-only using title inside the svg</h2>
<button>
<svg aria-labelledby="title_twitter_h72d" width="28" height="28">
<title id="title_twitter_h72d">Tweet!</title>
<use xlink:href="#twitter"></use>
</svg>
</button>
<h2>Icon-only using a sr-only class</h2>
<button>
<svg aria-hidden="true" width="28" height="28">
<use xlink:href="#twitter"></use>
</svg>
<span class="sr-only">Tweet!</span>
</button>
<h2>Icon-only using alt</h2>
<button>
<img src="https://assets.codepen.io/144736/twitter.png" alt="Tweet!" width="28" />
</button>
<h2>Icon-only using background-image</h2>
<button class="bg">
<span class="sr-only">Tweet!</span>
</button>
<div>
<svg>
<symbol id="twitter" fill="currentcolor" viewBox="0 0 512 512">
<path d="M512 97.248c-19.04 8.352-39.328 13.888-60.48 16.576 21.76-12.992 38.368-33.408 46.176-58.016-20.288 12.096-42.688 20.64-66.56 25.408C411.872 60.704 384.416 48 354.464 48c-58.112 0-104.896 47.168-104.896 104.992 0 8.32.704 16.32 2.432 23.936-87.264-4.256-164.48-46.08-216.352-109.792-9.056 15.712-14.368 33.696-14.368 53.056 0 36.352 18.72 68.576 46.624 87.232-16.864-.32-33.408-5.216-47.424-12.928v1.152c0 51.008 36.384 93.376 84.096 103.136-8.544 2.336-17.856 3.456-27.52 3.456-6.72 0-13.504-.384-19.872-1.792 13.6 41.568 52.192 72.128 98.08 73.12-35.712 27.936-81.056 44.768-130.144 44.768-8.608 0-16.864-.384-25.12-1.44C46.496 446.88 101.6 464 161.024 464c193.152 0 298.752-160 298.752-298.688 0-4.64-.16-9.12-.384-13.568 20.832-14.784 38.336-33.248 52.608-54.496z"></path>
</symbol>
</svg>
</div>
.sr-only {
border: 0;
clip: rect(0 0 0 0);
clip-path: inset(50%);
height: 1px;
left: 0;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
top: 0;
white-space: nowrap;
width: 1px;
}
.bg {
background: url(https://assets.codepen.io/144736/twitter.png);
width: 3.57rem;
height: 2.8rem;
background-size: 56%;
background-repeat: no-repeat;
background-position: center;
}
body {
margin: 0;
padding: 0.8rem 10px;
font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
max-width: 80ch;
line-height: 1.6;
font-size: 1.2rem;
margin-left: auto;
margin-right: auto;
}
button {
border: 2px solid #153a51;
background-color: #fff;
font-family: inherit;
font-size: 1.3rem;
padding: 0.3em 0.6em;
border-radius: 4px;
font-weight: bold;
display: flex;
gap: 0.5rem;
}
button:where(:hover, :focus) {
background-color: hsl(186, 56%, 48%);
color: #fff;
}
Also see: Tab Triggers