Pen Settings

HTML

CSS

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

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width" />
    <title>Facebook Dimensions</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:500|Open+Sans:400,600" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
    <style>
      body {font-family: 'Open Sans', 'Segoe UI'; padding-top: 75px;}
      .navbar-brand,
      h1, h2, h3, h4, h5, h6 {font-family: 'Montserrat'; font-weight: 500;}
      .dim-form .panel-body input,
      .dim-form .panel-body button {width: 50px; display: inline-block; vertical-align: middle;}
      .dim-form .panel-body button {width: auto; line-height: 1.5; position: relative; top: 1px; margin-left: 20px;}
      h2 {margin: 0 0 15px; font-size: 1.5em;}
    </style>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script>
      $(function () {
        // Hide the CSS hidden elements by JavaScript.
        $(".hidden").hide().removeClass("hidden");
        // Reset the layout to initial one.
        var resetLayout = function () {
          $(".dim-need, .dim-cons").fadeOut(function () {
            $(".dim-need .list-group, .dim-cons .list-group").empty();
            $(".dim-form").addClass("col-sm-offset-4");
          });
        };
        // Display the error message and reset the layout if found an error.
        var error = function (msg) {
          if (msg.length !== 0) {
            $(".alert-danger").text(msg).fadeIn();
            resetLayout();
          }
          else
            $(".alert-danger").fadeOut(function () {
              $(this).text("");
            });
        }
        // Calculate the proportions.
        var prop = function (dim) {
          if (!!dim.x) {
            var y = 630 / 1200 * dim.x;
            return (dim.x.toFixed(2) + " &times; " + y.toFixed(2));
          }
          if (!!dim.y) {
            var x = 1200 / 630 * dim.y;
            return (x.toFixed(2) + " &times; " + dim.y.toFixed(2));
          }
        }
        // Display the list of proportional dimensions.
        var display = function (x, y) {
          var need = [];
          var cons = [];
          need.push(prop({x: x}));
          need.push(prop({y: y}));
          need = need.filter(function (value, index, self) { 
            return self.indexOf(value) === index;
          }).filter(function (v) { return v !== undefined });
          $(".dim-need .list-group, .dim-cons .list-group").empty();
          need.forEach(function (v) {
            $(".dim-need .list-group").append('<li class="list-group-item">' + v + "</li>");
          });
          cons.push(prop({x: getRound(x, 1)}));
          cons.push(prop({y: getRound(y, 1)}));
          cons.push(prop({x: getRound(x, 2)}));
          cons.push(prop({y: getRound(y, 2)}));
          cons = cons.filter(function (value, index, self) { 
            return self.indexOf(value) === index && need.indexOf(value) === -1;
          }).filter(function (v) { return v !== undefined });
          if (cons.length)
            cons.forEach(function (v) {
              $(".dim-cons .list-group").append('<li class="list-group-item">' + v + "</li>");
            });
          else
            $(".dim-cons .list-group").append('<li class="list-group-item">Sorry, nothing here.</li>');
        }
        // Get the rounded value.
        var getRound = function (n, p) {
          if (!p)
            p = 1;
          var t = Math.pow(10, p);
          if (n % t === 0)
            return n;
          else
            return parseInt(n / t) * t;
        }
        // Calculate the proportion.
        var calculate = function () {
          var strX = $("#dim-x").val().trim();
          var strY = $("#dim-y").val().trim();
          var origX = parseInt(strX, 10);
          var origY = parseInt(strY, 10);
          if (strX === "" && strY === "") {
            error("You need to provide at least one value!");
            return false;
          }
          if ((strX !== "" && isNaN(origX)) || (strY !== "" && isNaN(origY))) {
            error("Given values should be integers!");
            return false;
          }
          var finX = isNaN(origX) ? null : origX;
          var finY = isNaN(origY) ? null : origY;
          error("");
          $(".dim-form").removeClass("col-sm-offset-4");
          display(finX, finY);
          $(".dim-need, .dim-cons").fadeIn();
          return false;
        };
        // Event listeners.
        $("#dim-x, #dim-y").keyup(function (e) {
          if (e.keyCode === 13)
            calculate();
        });
        $("#btn-c").click(calculate);
      });
    </script>
  </head>
  <body>
    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container-fluid">
        <div class="navbar-header">
          <a class="navbar-brand" href="#">Facebook Dimensions</a>
        </div>
      </div>
    </nav>
    <div class="container-fluid">
      <div class="row">
        <div class="col-sm-12">
          <h2>What is this tool about?</h2>
          <p>This is a quick helper tool for getting the right dimensions for your post's image. Facebook requires the previews to be in proportion of 1200 &times; 630 for a full size share. This tool helps you to set one of the dimension with the other not modified with respect to your image.</p>
          <div class="alert alert-danger text-center hidden"></div>
        </div>
        <div class="col-sm-4 dim-form col-sm-offset-4">
          <div class="panel panel-primary">
            <div class="panel-heading">
              <h3 class="panel-title">Original Image Dimensions</h3>
            </div>
            <div class="panel-body text-center">
              <input type="text" class="form-control input-sm text-center" id="dim-x" placeholder="X" /> &times;
              <input type="text" class="form-control input-sm text-center" id="dim-y" placeholder="Y" />
              <button type="button" class="btn btn-primary btn-sm" id="btn-c">Calculate</button>
            </div>
          </div>
        </div>
        <div class="col-sm-4 dim-need hidden">
          <div class="panel panel-primary">
            <div class="panel-heading">
              <h3 class="panel-title">Dimensions you Need</h3>
            </div>
            <ul class="list-group text-center"></ul>
          </div>
        </div>
        <div class="col-sm-4 dim-cons hidden">
          <div class="panel panel-primary">
            <div class="panel-heading">
              <h3 class="panel-title">Considerable Dimensions</h3>
            </div>
            <ul class="list-group text-center"></ul>
          </div>
        </div>
      </div>
    </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console