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="row">
<h1>Callout Box <small>Generator tool</small></h1>
</div>
<div class="row">
<fieldset>
<legend>1. Select <b>the side</b> of the article the box will go on</legend>
<input type="radio" name="float" checked="checked" value="left" id="left"/>
<label for="left">Left</label>
<input type="radio" name="float" value="right" id="right"/>
<label for="right">Right</label>
</fieldset>
<label for="size">2. Select <b>the size</b> the callout box</label>
<select name="size" id="size">
<option value="full">Full</option>
<option value="wide">Wide</option>
<option value="narrow">Narrow</option>
</select>
<label for="headline">3. Enter <b>the headline</b> here</label>
<input type="text" name="hText" id="headline" placeholder="Your headline here" />
<label for="img">4. Select if there will be <b>an image</b></label>
<select name="img" id="img">
<option value="landscape">Landscape Image</option>
<option value="portrait">Portrait Image</option>
<option value="false">No Image</option>
</select>
<p>5. Enter <b>the caption</b> here. Highlight the text to get styling options (bold, italic, numbered list, and bullet point list).</p>
<div class="editable" id="caption"></div>
</div>
<div class="row">
<p>You're done! Now copy the HTML code below and paste it into your website. <b>If there is an image,</b> replace the URL in the image tag (where it says src="dummyimage.com/...") with your custom image url and alternative text where it says alt="".</p>
<textarea name="code" id="code" cols="30" rows="6"><div class='callout-left full'><h3>Add your headline</h3><img src='http://dummyimage.com/400x240/000/fff' height='400' width='240' alt=""><p>Add your caption</p></div></textarea>
</div>
<div class="row">
<h3>Callout Box Preview</h3>
<div id="preview"><div class='callout-left full'><h3>Add your headline</h3><img src='http://dummyimage.com/400x240/000/fff' height='400' width='240' alt=""><p>Add your caption</p></div></div>
<p>Lorem ipsum dolor sit amet, etiam tortor adipiscing qui metus, porttitor lectus tortor dui commodo sit nec. Lacus dui dictum ut eu sapien, ligula lacinia in nulla aliquam tincidunt, amet a amet donec donec, dolor eu dui nisl. Blandit wisi risus orci metus. Feugiat interdum nunc, proin erat tortor tincidunt nec vulputate. Ipsum mi nam leo. Id et. Mauris mi vivamus malesuada, ea vitae venenatis eu porttitor. Integer at erat, sed quam ante iaculis imperdiet duis volutpat, elit suscipit facilisis gravida. Integer at ipsum nunc libero dui explicabo, facilisis condimentum porttitor tempor tristique ac nibh, vel odio duis est vivamus suspendisse qui, eget quisque. Mauris magnis, eu lacus in tempor eget inceptos luctus, turpis mauris doloribus, cras libero inceptos quam, suscipit ultrices ea. Metus nulla lorem vitae, morbi eu maecenas eget felis, urna phasellus auctor ipsum eros volutpat, in congue tellus, auctor nibh ultrices wisi. Dignissim quisque mauris. Labore ipsum pellentesque, non aliquam massa, eget amet magna vitae, mauris sem, erat velit porta vulputate at sollicitudin at. Magna duis cras imperdiet eu cursus, vel ut nam donec ac arcu ut. Diam mauris magna in eget aliquam ultrices, urna aliquet ultricies cras, eros id tellus donec, tempus magna ligula inceptos, adipiscing donec sed. Cras suspendisse augue, nam mauris turpis libero rutrum condimentum elit. Etiam tellus luctus phasellus lacus tortor metus. In hymenaeos, pede erat vitae amet, vitae senectus sed, dui risus a, eros convallis. Sed ut nulla pretium, felis nec, eget nulla ante quis a nam. Risus dui, enim consectetuer scelerisque nulla amet pellentesque tellus.Vehicula tincidunt tellus ultrices ut etiam, turpis mollis sollicitudin, dui morbi tempus litora venenatis metus etiam. Nascetur imperdiet esse, donec et fusce nec ipsum sem integer, magna mauris dolor et ad pede pede, suspendisse orci amet.Vel pretium lacinia, sit magna sed. Ipsum praesent amet sed nulla, volutpat tortor condimentum sodales interdum vel. </p>
</div>
legend, label {
font-size: 1em;
line-height: 1.5;
margin: 0.75em 0;
font-weight: 400!important;
}
#caption {
width: 100%;
color: #8E8C87;
background-color: #FFFFFF;
border-style: solid;
border-width: 1px;
border-color: #cccccc;
margin: 0 0 1rem 0;
padding: 0.5em;
min-height: 8em;
outline: none;
}
#caption :first-child {
padding-top: 0;
margin-top: 0;
}
var html1 = "<div class='callout-left ";
var html2 = "full'>";
var html3 = "<h3>Add your headline</h3>";
var html4 = "<img src='https://dummyimage.com/400x240/000/fff' height='400' width='235'>";
var html5 = "<p>Add your caption</p>";
var editor = new MediumEditor('.editable', {
toolbar: {
buttons: [
'bold',
'italic',
'orderedlist',
'unorderedlist'
]
}
});
//Checks the value of the side radio and changes side
$('input:radio[name=float]').change(function() {
var side = "";
if(this.value == "left") side = "left ";
else if (this.value == "right") side = "right ";
html1 = "<div class='callout-" + side;
endHtml();
});
//Checks the value of the dropdown for size and changes the size
$('#size').val('selectedvalue').change(function() {
if(this.value == "full") html2 = "full'>";
else if(this.value == "wide") html2 = "wide'>";
else if(this.value == "narrow") html2 = "narrow'>";
endHtml();
});
//Checks the headline input and changes the headline
$('#headline').bind("keyup blur paste", function() {
var temp = $(this).val();
if (temp == '') temp = "Add your headline";
html3 = "<h3>" + temp + "</h3>";
endHtml();
});
//Checks the value of the img radio and adds/removes the img tag
$('#img').val('selectedvalue').change(function() {
if(this.value == "landscape") html4 = "<img src='http://dummyimage.com/400x235/000/fff' height='400' width='235'>";
else if(this.value == "portrait") html4 = "<img src='http://dummyimage.com/400x415/000/fff' height='400' width='415'>";
else if (this.value == "false") html4 = "";
endHtml();
});
//Checks the caption input and changes the caption
editor.subscribe('editableInput', function (event, editable) {
html5 = document.getElementById('caption').innerHTML;
endHtml();
});
//Puts all of the html together and updates the preview and result text
function endHtml() {
var result = html1 + html2 + html3 + html4 + html5 + "</div>";
$("#code").text(result);
$("#preview").html(result);
}
Also see: Tab Triggers