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. You can use the CSS from another Pen by using it's URL and the proper URL extention.
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 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 class="wrapper">
<form class="searchbox">
<input type="search" placeholder="Search" id="search" autocomplete="off">
<div id="search-autocomplete" class="search-autocomplete">
<ul>
<li class="load-more"><a href="#">Load more</a></li>
<li class="no-results">No results.</li>
<li class="error">%err%</li>
</ul>
<div class="loader">
<div class="spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</div>
</div>
</form>
</div>
<p class="description">
Start by typing in the search box to search Google
</p>
@import url(https://fonts.googleapis.com/css?family=Open+Sans:400,300,600);
$padding: 7px 10px;
body {
background: #efefef;
padding: 20px;
font-family: 'Open Sans', sans-serif;
}
.description {
text-align: center;
font-size: 0.8em;
color: #bbb;
text-shadow: 0 2px 1px #fff;
}
b, strong {
font-weight: 600;
}
.wrapper {
margin: 0 auto;
display: block;
background: #fff;
width: 400px;
padding: 10px;
box-shadow: 0 0 5px rgba(10, 10, 10, 0.4);
}
.searchbox {
width: 100%;
position: relative;
input[type=search] {
width: 100%;
border: 1px solid #eee;
padding: $padding;
-webkit-appearance: none;
}
.search-autocomplete {
display: none;
position: absolute;
top: 0;
left: 0;
right: 0;
font-size: 0.9em;
border: 1px solid #eee;
border-top: none;
background: #fff;
box-shadow: 0 4px 4px rgba(10, 10, 10, 0.1);
max-height: 300px;
overflow-y: auto;
ul {
list-style: none;
margin: 0;
padding: 0;
}
li, a {
display: block;
}
li {
border-bottom: 1px solid #eee;
color: #0074D9;
}
li:last-of-type {
border-bottom: none;
}
li:hover, li:active {
background: #fafafa;
color: #FF4136;
}
a {
padding: $padding;
color: inherit;
text-decoration: none;
}
.search-description {
font-size: 0.8em;
color: #999;
font-weight: 300;
display: block;
}
.loader, .load-more, .no-results, .error {
padding: $padding;
text-align: center;
}
.load-more {
font-size: 0.8em;
color: #0074D9;
}
.error, .error:hover, .error:active {
color: #FF4136;
}
.no-results, .no-results:hover, .no-results:active {
color: #999;
}
}
}
/* SpinKit by Tobias Ahlit
/* https://github.com/tobiasahlin/SpinKit
/**********************************************************/
.spinner {
margin: auto;
width: 70px;
text-align: center;
}
.spinner > div {
width: 14px;
height: 14px;
background-color: #0074D9;
border-radius: 100%;
display: inline-block;
-webkit-animation: bouncedelay 1.4s infinite ease-in-out;
animation: bouncedelay 1.4s infinite ease-in-out;
/* Prevent first frame from flickering when animation starts */
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.spinner .bounce1 {
-webkit-animation-delay: -0.32s;
animation-delay: -0.32s;
}
.spinner .bounce2 {
-webkit-animation-delay: -0.16s;
animation-delay: -0.16s;
}
@-webkit-keyframes bouncedelay {
0%, 80%, 100% { -webkit-transform: scale(0.0) }
40% { -webkit-transform: scale(1.0) }
}
@keyframes bouncedelay {
0%, 80%, 100% {
transform: scale(0.0);
-webkit-transform: scale(0.0);
} 40% {
transform: scale(1.0);
-webkit-transform: scale(1.0);
}
}
(function() {
var searchbox = $('#search'),
autocomplete = $('#search-autocomplete'),
loadMoreButton = $('.load-more', autocomplete),
spinner = $('.loader', autocomplete),
noResults = $('.no-results', autocomplete),
error = $('.error', autocomplete);
var currentOffset = 0,
// some random URL to load because we don't use the result anyway, just so the request will succeed :P
searchUrl = 'https://raw.githubusercontent.com/ghosh/uiGradients/master/gradients.json', //'https://www.crossorigin.me/https://ajax.googleapis.com/ajax/services/search/web',
lastSearch = '',
searchTimeout = 0.5, //seconds
searchTimer;
function loadData() {
noResults.hide();
error.hide();
loadMoreButton.hide();
spinner.show();
if(searchbox.val() !== lastSearch) {
$('.search-result', autocomplete).remove();
currentOffset = 0;
}
lastSearch = searchbox.val();
$.ajax({
type: 'GET',
url: searchUrl,
dataType: 'text',
data: {
'v': '1.0',
'q': lastSearch,
'start': currentOffset
},
success: function(data) {
// Since the web search API is dead we have to fake it for the demo
// Can't be bothered to actually remove the AJAX request so it stays ;)
data = '{"responseData": {"results" : [{"url": "https://www.google.com","titleNoFormatting": "Quibusdam minus","content": "Quibusdam minus saepe incididunt tincidunt congue repellendus malesuada pretium veniam explicabo molestiae cupiditate natoque praesentium nascetur, vitae anim risus soluta quisque aliquip harum modi? Maecenas esse culpa mattis! Natus voluptatum."},{"url": "https://www.google.com","titleNoFormatting": "Possimus! Quia, atque illo","content": "Possimus! Quia, atque illo imperdiet quam, lacus penatibus bibendum cupiditate? Nihil pellentesque velit voluptatem sodales lacus tellus torquent. Deserunt eum incidunt et."},{"url": "https://www.google.com","titleNoFormatting": "Cubilia amet eos proident","content": "Cubilia amet eos proident blandit irure nobis diam! Dignissim sed officiis aut, arcu, nulla necessitatibus fermentum officia fermentum."},{"url": "https://www.google.com","titleNoFormatting": "Wisi, rhoncus consectetuer","content": "Dictum iure blandit cupidatat, laborum potenti cupidatat magnam nostrum nibh! Wisi, rhoncus consectetuer netus! Enim vitae mollis ullamcorper fames eiusmod?"},{"url": "https://www.google.com","titleNoFormatting": "Cras tempore inventore","content": "Debitis cum auctor, nibh, etiam! Cras tempore inventore, nascetur possimus."}]}}';
var json = $.parseJSON(data);
if(json &&
json.responseData &&
json.responseData.results &&
json.responseData.results.length > 0) {
for(var i = 0; i < json.responseData.results.length; ++i) {
$('<li class="search-result">' +
'<a href="'+ json.responseData.results[i].url +'" target="_blank">' +
json.responseData.results[i].titleNoFormatting +
'<span class="search-description">' +
json.responseData.results[i].content +
'</span>' +
'</a>' +
'</li>').insertBefore(loadMoreButton);
}
noResults.hide();
loadMoreButton.show();
error.hide();
} else {
noResults.show();
loadMoreButton.hide();
error.hide();
}
if(json &&
!json.responseData &&
json.responseDetails) {
noResults.hide();
loadMoreButton.hide();
error.text(json.responseDetails).show();
console.error(json.responseDetails);
}
spinner.hide();
currentOffset += json.responseData.results.length;
},
error: function(jqXHR, textStatus, errorThrown) {
console.error(errorThrown);
error.text(textStatus + ': ' + errorThrown).show();
loadMoreButton.hide();
noResults.hide();
spinner.hide();
}
});
}
searchbox.on('focus', function() {
if($(this).val().length > 0) {
autocomplete.slideDown('fast');
}
})
.on('input propertychange paste', function() {
//this will handle pasting text and clearing text with browser built in clear button
$(this).trigger('keyup');
})
.on('keydown', function() {
clearTimeout(searchTimer);
})
.on('keyup', function() {
if($(this).val().length > 0) {
clearTimeout(searchTimer);
searchTimer = setTimeout(loadData, searchTimeout * 1000);
autocomplete.slideDown('fast');
} else {
clearTimeout(searchTimer);
autocomplete.slideUp('fast');
}
});
$(document).on('click', function(e) {
//click anywhere outside searchbox to close
if(!$(e.target).closest('.searchbox').length) {
if(autocomplete.is(':visible')) {
autocomplete.slideUp('fast');
clearTimeout(searchTimer);
}
}
});
autocomplete.css('top', (searchbox.outerHeight()) + 'px');
loadMoreButton.on('click', loadData)
.hide();
noResults.hide();
error.hide();
}());
Also see: Tab Triggers