Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource


Add Packages

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.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <h1>Dos Equis Guy Meme Generator</h1>
<div id="wrapper">
<div id="canvas"><canvas id="c" width="400" height="500"></canvas></div>
<div id="textinput">
  <span>Top Line</span><br>
  <input class="highlight" id="toptext" type="text" value="I don't always create memes"><br><br>
  <span>Bottom Line</span><br>
  <input class="highlight" id="bottomtext" type="text" value="but when I do the length of them always overflows the height of the image."><br>
  <button id="submit">Generate!</button>


                body {
  font: 24px Arial;

#wrapper {
  text-align: center;
  width: 90%;

#canvas {
  display: inline-block;

#textinput {
  text-align: left;
  display: inline-block;
  vertical-align: top;
  margin-left: 25px;

h1 {
  font-size: 36px;
  text-align: center;

#toptext, #bottomtext {
  padding: 5px;
  width: 180px;
  border-radius: 5px;
  border: 2px solid green;


                var c = document.querySelector('#c');
var ctx = c.getContext('2d');
var maxWidth = 400;
var lineHeight = 50;
var image = new Image();

image.src = ""

image.onload=function() {
  ctx.drawImage(image, 0, 0, c.width, c.height);
document.getElementById('submit').onclick = redrawMeme;

function redrawMeme() {
  var topText = document.getElementById('toptext').value;
  var bottomText = document.getElementById('bottomtext').value;
  ctx.drawImage(image, 0, 0, c.width, c.height);
  ctx.font = "36pt Impact";
  ctx.textAlign = "center"; ctx.fillStyle="white";

  wrapText(ctx, topText, c.width/2, 50, maxWidth, lineHeight);
  ctx.font = "28pt Impact";
  wrapText(ctx, bottomText, c.width/2, 400, maxWidth, lineHeight);

function wrapText(context, text, x, y, maxWidth, lineHeight) {
        var words = text.split(' ');
        var line = '';

        for(var n = 0; n < words.length; n++) {
          var testLine = line + words[n] + ' ';
          var metrics = context.measureText(testLine);
          var testWidth = metrics.width;
          if (testWidth > maxWidth && n > 0) {
            context.fillText(line, x, y);
            context.strokeText(line, x, y);
            line = words[n] + ' ';
            y += lineHeight;
          else {
            line = testLine;
        context.fillText(line, x, y);
        context.strokeText(line, x, y);

var textbox = document.querySelectorAll('.highlight'); 

textbox[0].addEventListener('click', function() {;
textbox[1].addEventListener('click', function() {;