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.
<!-- betterembed element -->
<article class="betterembed js-betterembed">
<button type="button" class="betterembed__show-original-element js-betterembed-show-message"></button>
<div class="betterembed__item">
<header>
<h3 class="betterembed__network">Twitter</h3>
</header>
<div class="betterembed__body">
<div class="betterembed__msg">
<p>
With a click on the link below, the original content will be loaded. This can include remote content and you can possibly be tracked from the original provider.</p><p><strong>{{ Text should be adopted for your GDPR needs }}</strong></p>
<a href="javascript:;" class="betterembed__msg-button-primary js-betterembed-load-remote">show original content</a>
<a href="javascript:;" class="betterembed__msg-button-secondary js-betterembed-close">close</a>
</div>
<figure class="betterembed__media">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/310306/acolono-splashawards.jpg" alt="embed image">
</figure>
<h3 class="betterembed__title">acolono GmbH on Twitter</h3>
<div class="betterembed__text">
We love to splash! Part of our team attended the Austrian/German #splashawards yesterday at @burda_news in Munich. Nominated three times we won the award together with @getunik in the Non-Profit category for the @WWF_Schweiz guides project! YEAH!!
<a class="betterembed__read-more" href="https://twitter.com/acolono/status/1122073732565086208" target="_blank" rel="nofollow noopener">read more</a>
</div>
<footer class="betterembed__footer">
<span class="betterembed__author">
<a href="https://twitter.com/acolono" target="_blank" rel="nofollow noopener">acolono GmbH</a>
</span>
<span>x days ago</span>
</footer>
</div>
</div>
<div class="betterembed__embed"></div>
</article>
<p>for multiple elements, head over to <a href="https://codepen.io/Grienauer/pen/ewZBJo" target="_blank" rel="noopener">Codepen for Multiple BetterEmbed Elements</a></p>
<p>see the output of the post via API <a href="https://api.betterembed.com/api/v0/item?url=https%3A%2F%2Ftwitter.com%2Facolono%2Fstatus%2F1122073732565086208" target="_blank" rel="noopener">API Output</a></p>
// remove this. just needed for this demo
body {
padding: 3em 1em;
max-width: 1200px;
margin-left: auto;
margin-right: auto;
}
/* Social Feed */
$betterembed-content-margin: 15px;
$betterembed-color-primary: #4c5559;
$betterembedShowOriginalSize: 30px;
// set to "inherit" if it should adopt your base Font.
$betterembedFontFamily: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
/* breaks Words when they are too long and would burst the layout. */
@mixin word-wrap() {
/* Non standard for webkit */
word-break: break-word;
-webkit-hyphens: auto;
-moz-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}
@mixin ellipsis() {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
@mixin text-invisible() {
text-indent: -9999em;
}
// Hide elements visually, but keep them available for screen-readers.
//
// Used for information required for screen-reader users to understand and use
// the site where visual display is undesirable. Information provided in this
// manner should be kept concise, to avoid unnecessary burden on the user.
// "!important" is used to prevent unintentional overrides.
@mixin element-invisible() {
position: absolute !important;
left: 0;
top: 0;
clip: rect(1px 1px 1px 1px); /* IE6, IE7 */
clip: rect(1px, 1px, 1px, 1px);
overflow: hidden;
height: 1px;
}
.betterembed {
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-family: $betterembedFontFamily;
font-weight: 300;
box-sizing: border-box;
position: relative; //for iframe switcher
// we define a max width and align it centered as a default.
max-width: 550px;
margin-left: auto;
margin-right: auto;
&.is-betterembed-msg-visible {
.betterembed {
&__msg {
display: block;
}
&__show-original-element {
background-position: center right;
}
}
}
&.is-betterembed-remote-visible {
& .betterembed__embed {
display: block;
}
& .betterembed__item {
display: none;
}
}
&__show-original-element {
position: absolute;
top: 0;
right: 0;
z-index: 1;
cursor: pointer;
background-image: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/310306/betterembed-logo.png");
background-repeat: none;
background-position: center right;
background-size: 23px 23px;
background-repeat: no-repeat;
height: $betterembedShowOriginalSize;
//width: $betterembedShowOriginalSize;
padding-right: $betterembedShowOriginalSize;
display: block;
background-color: transparent;
border: none;
&:focus {
outline: none;
}
}
&__item {
overflow: hidden; // prevent overflowing if unexpected things happening
}
&__network {
@include word-wrap();
padding-right: $betterembedShowOriginalSize; //for show iframe element
margin: 0 0 10px 0;
flex-grow: 1;
text-transform: uppercase;
font-weight: bold;
color: $betterembed-color-primary;
}
&__media {
margin:0;
img {
width: 100%;
height: auto;
}
}
&__title {
clear: both;
padding: 0 $betterembed-content-margin;
margin: $betterembed-content-margin 0 0 0;
@include word-wrap;
font-size: 22px;
}
&__text {
clear: both;
padding: $betterembed-content-margin;
@include word-wrap;
font-size: 18px;
a {
color: #fff;
font-weight: inherit; /* could be removed */
text-decoration: underline;
}
}
&__read-more {
color: #fff;
font-size: 14px;
white-space: nowrap;
}
&__body {
background: $betterembed-color-primary;
color: #fff;
font-size: 20px;
position: relative;
}
&__msg {
display: none;
font-size: 16px;
position: absolute;
padding: 20px;
top: 15px;
left: 15px;
right: 15px;
background-color: rgba(0, 0, 0, 0.84);
color: white;
text-align: center;
p {
text-align: left;
margin: 0;
&:not(last-of-type) {
padding-bottom: 10px;
}
}
strong {
font-weight: 600;
}
&-button-primary {
display: inline-flex;
margin-top: 20px;
background-color: white;
padding: 10px 20px;
color: black;
}
&-button-secondary {
display: inline-flex;
margin-top: 20px;
padding: 10px 20px;
color: white;
}
}
&__footer {
margin: 0 $betterembed-content-margin;
padding: $betterembed-content-margin 0;
border-top: 1px solid #fff;
font-size: 16px;
overflow: auto;
}
&__author {
a {
color: #fff;
font-weight: bold;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
}
// the original embed or iframe content
&__embed {
//needed for e.g. Twitter Markup and that the show/hide icon is not inside of the component.
display: none;
padding-top: $betterembedShowOriginalSize;
> * {
//some adoptions to make iframes more responsive
//e.g. for twitter embed if it is under 250px
width: 100% !important;
overflow-x: none;
margin: 0;
padding: 0;
}
& * {
}
}
}
//hacks for making some embedded services responsive
//todo: check if it still works :)
.betterembed__embed {
//e.g. for facebook
> iframe {
width: 100%;
}
}
var betterembed_show = document.querySelectorAll('.js-betterembed-show-message,.js-betterembed-load-remote,.js-betterembed-close');
document.querySelectorAll('button.js-betterembed-show-message').forEach(function(button) {
button.innerHTML = 'show original';
});
var showhidebtn = document.getElementsByClassName('.js-betterembed-show-message')[0];
for (var i = 0; i < betterembed_show.length; i++) {
betterembed_show[i].addEventListener('click', function(e) {
var container = this.closest('.js-betterembed');
var showhidebtn = container.querySelector('button.js-betterembed-show-message');
if(e.currentTarget.classList.contains('js-betterembed-show-message')) {
container.classList.toggle('is-betterembed-msg-visible');
container.classList.remove('is-betterembed-remote-visible');
showhidebtn.innerHTML = 'show original';
}
if(e.currentTarget.classList.contains('js-betterembed-close')) {
container.classList.remove('is-betterembed-msg-visible');
}
if(e.currentTarget.classList.contains('js-betterembed-load-remote')) {
var embed_elem = container.lastElementChild;
//embed_elem.innerHTML = load_remote;
container.classList.toggle('is-betterembed-remote-visible');
//ajax stuff
var request = new XMLHttpRequest();
//Ajax URL. mocky.io only for the demo - simulating response which contains twitter post data
var ajax_url = 'https://www.mocky.io/v2/5e1454222d00007200166ef6';
request.open('GET', ajax_url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
var resp = request.responseText;
embed_elem.innerHTML = resp;
//search for script tags and make executing this
var scripts = Array.prototype.slice.call(embed_elem.getElementsByTagName("script"));
for (var i = 0; i < scripts.length; i++) {
if (scripts[i].src != "") {
var tag = document.createElement("script");
tag.src = scripts[i].src;
document.getElementsByTagName("head")[0].appendChild(tag);
} else {
eval(scripts[i].innerHTML);
}
}
}
};
request.send();
//end ajax stuff
showhidebtn.innerHTML = 'hide original';
}
e.preventDefault();
}, false);
}
Also see: Tab Triggers