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.
<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">Credit Card Payment</h3>
</div>
<form class="panel-body" id="checkout-form" action="#">
<div class="row">
<div class="form-group col-md-12">
<label for="cardholder-name">Cardholder Name</label>
<input type="text" class="form-control" id="cardholder-name">
<span class="helper-text"></span>
</div>
<!--Hosted Payment Field for CC number-->
<div class="form-group col-xs-9">
<label for="card-number">Card Number</label>
<div class="input-group">
<div class="form-control" id="card-number" data-bluesnap="ccn"></div>
<div id="card-logo" class="input-group-addon"><img src="https://files.readme.io/d1a25b4-generic-card.png" height="20px"></div>
</div>
<span class="helper-text" id="ccn-help"></span>
</div>
<!--Hosted Payment Field for CC CVV-->
<div class="form-group col-xs-3">
<label for="cvv">CVV</label>
<div class="form-control" id="cvv" data-bluesnap="cvv"></div>
<span class="helper-text" id="cvv-help"></span>
</div>
<!--Hosted Payment Field for CC EXP-->
<div class="form-group col-xs-6">
<label for="exp-date">Exp. (MM/YY)</label>
<div class="form-control" id="exp-date" data-bluesnap="exp"></div>
<span class="helper-text" id="exp-help"></span>
</div>
<div class="form-group col-xs-6">
<label for="cardholder-name">Postal Code</label>
<input type="text" class="form-control" id="cardholder-name">
<span class="helper-text"></span>
</div>
</div>
<button class="btn btn-raised btn-info btn-lg col-md-4" type="button" id="submit-button" onclick="do_when_clicking_submit_button()">Pay Now</button>
</form>
</div>
<!--BlueSnap Hosted Payment Fields JavaScript file-->
<script type="text/javascript" src="https://sandpay.bluesnap.com/web-sdk/5/bluesnap.js"></script>
/* Uses bootstrap-material-design - https://fezvrasta.github.io/bootstrap-material-design */
.panel {
width: 80%;
margin: 2em auto;
}
.panel-body {
width: 90%;
margin: 2em auto;
}
body {
font-size: 15px;
}
label {
font-weight: 400;
}
.helper-text {
color: #E91E63;
font-size: 12px;
margin-top: 5px;
height: 12px;
display: block;
}
.helper-text-green {
color: green;
}
/* Hosted Payment Fields styles*/
.hosted-field-focus {
outline: none;
background-image: linear-gradient(#009688, #009688), linear-gradient(#d2d2d2, #d2d2d2);
animation: input-highlight 0.5s forwards;
box-shadow: none;
background-size: 0 2px, 100% 1px;
}
/* Defining helper functions/objects */
// changeImpactedElement: function that removes the provided class(es) and adds the provided class(es) to Hosted Payment Fields element
function changeImpactedElement(tagId, removeClass, addClass) {
removeClass = removeClass || "";
addClass = addClass || "";
$("[data-bluesnap=" + tagId + "]")
.removeClass(removeClass)
.addClass(addClass);
}
// cardUrl: object that stores card type code (received from BlueSnap) and associated card image URL
var cardUrl = {
"AMEX": "https://files.readme.io/97e7acc-Amex.png",
"DINERS": "https://files.readme.io/8c73810-Diners_Club.png",
"DISCOVER": "https://files.readme.io/caea86d-Discover.png",
"JCB": "https://files.readme.io/e076aed-JCB.png",
"MASTERCARD": "https://files.readme.io/5b7b3de-Mastercard.png",
"VISA": "https://files.readme.io/9018c4f-Visa.png"
};
/* Defining bsObj: object that stores Hosted Payment Fields
event handlers, styling, placeholder text, etc. */
var bsObj = {
//insert your Hosted Payment Fields token
token: "b44b553f82290ad50eaec4a9ab333c810b57eb2e00075eb061282694ce77d74f_",
onFieldEventHandler: {
onFocus: function(tagId) {
// Handle focus
changeImpactedElement(tagId, "", "hosted-field-focus");
},
onBlur: function(tagId) {
// Handle blur
changeImpactedElement(tagId, "hosted-field-focus");
},
onError: function(tagId, errorCode, errorDescription, eventOrigin) {
// Handle a change in validation by displaying help text
$("#" + tagId + "-help").removeClass('helper-text-green').text(errorCode + " - " + errorDescription + " - " + eventOrigin);
},
onType: function(tagId, cardType, cardData) {
// get card type from cardType and display card image
$("#card-logo > img").attr("src", cardUrl[cardType]);
if (null != cardData) {
$("#" + tagId + "-help").addClass('helper-text-green').text(JSON.stringify(cardData));
}
},
onValid: function(tagId) {
// Handle a change in validation by removing any help text
$("#" + tagId + "-help").text("");
}
},
style: {
// Styling all inputs
"input": {
"font-size": "14px",
"font-family":
"RobotoDraft,Roboto,Helvetica Neue,Helvetica,Arial,sans-serif",
"line-height": "1.42857143",
"color": "#555"
},
// Styling input state
":focus": {
"color": "#555"
}
},
ccnPlaceHolder: "1234 5678 9012 3456",
cvvPlaceHolder: "123",
expPlaceHolder: "MM / YY"
}
/* After DOM is loaded, calling bluesnap.hostedPaymentFieldsCreation: function that takes token and bsObj as inputs and initiates Hosted Payment Fields */
$(document).ready(function() {
bluesnap.hostedPaymentFieldsCreate(bsObj);
});
/* Calling bluesnap.submitCredentials: function that submits card data to
BlueSnap and calls input function with card data object if submission was successful */
function do_when_clicking_submit_button() {
bluesnap.hostedPaymentFieldsSubmitData(
function(callback) {
if (null != callback.error) {
var errorArray = callback.error;
for (i in errorArray) {
$("#" + errorArray[i].tagId + "-help").text(errorArray[i].errorCode + " - " + errorArray[i].errorDescription);
}
} else {
var cardData = callback.cardData;
alert(
"Card Type: " +
cardData.ccType +
" Last 4 Digits: " +
cardData.last4Digits +
" Issuing Country: " +
cardData.issuingCountry +
" Is Regulated Card: " +
cardData.isRegulatedCard +
" Card Sub Type: " +
cardData.cardSubType +
" Bin Category: " +
cardData.binCategory +
" Exp: " +
cardData.exp +
" after that I can call final submit"
);
// This is where you would perform final submission to your server
}
}
);
}
Also see: Tab Triggers