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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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.


        <link rel="stylesheet" href="style.css">
        <div class="calculator_container">
            <h1>Tip Calculator</h1>
            <div class="form_control">
                <label for="bill">Bill (in $)</label>
                <input type="number" id="bill_value" placeholder="100"/>
            <div class="form_control">
                <label for="tip">Tip %</label>
                <input type="number" id="tip_value" placeholder="10" />
            <button id="calculate-btn">CALCULATE</button>
             <div class="form_control">
                <label for="people">People sharing</label>
                <input type="number" id="people-value" placeholder="10"/>
           <button id="split-btn">Calculate split</button>
                <div class="result">
                    <span>Total:</span> <strong id="total">[$110]</strong>
                 <div class="result">
                    <span>Total per person:</span> <strong id="split-total-value">[$110]</strong>
        <script src="script.js"></script>


                body {
	background-color: #9370DB;
	color: #fff;
	margin: 0;
	display: flex;
	font-family: 'Poppins', sans-serif;
	justify-content: center;
	align-items: center;
	min-height: 100vh;

.calculator_container {
	background-color: rebeccapurple;
	border-radius: 4px;
	box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
	padding: 2rem 3rem;

h1 {
	margin: 0 0 1rem;
	text-align: center;

.form_control {
	margin: 0.75rem 0;

.form_control input {
	padding: 0.25rem;
	width: 100%;

.form_control label {
	display: block;

.calculator_container footer {
	margin-top: 2rem;

.result {
	display: flex;
	justify-content: space-between;
button {
  padding: 0.5em;
  text-transform: uppercase;
  border: 1px solid white;
  color: white;
  font-weight: bold;
  border-radius: 999px;
  background-color: rebeccapurple;
  cursor: pointer;
button:hover {
  background-color: white;
  color: rebeccapurple;
label {
  margin-top: 1em;
input {
  margin-top: 0.5em;


                const calcBtn = document.getElementById("calculate-btn");

calcBtn.addEventListener("click", calculateTotal);
window.addEventListener("keyup", function (e) {
  if (e.keyCode === 13) {
function calculateTotal() {
  const billValue = parseFloat(document.getElementById("bill_value").value);
  const tipValue = parseFloat(document.getElementById("tip_value").value);
  const totalTip = (billValue * tipValue) / 100;
  const billTotal = billValue + totalTip;

  const totalField = document.getElementById("total");

  totalField.innerText = billTotal.toLocaleString("en", {
    style: "currency",
    currency: "USD"

  return billTotal;

const splitBtn = document.getElementById("split-btn");
splitBtn.addEventListener("click", calculateSplitTotal);

function calculateSplitTotal() {
  const billTotal = calculateTotal();
  const peopleTotal = parseInt(document.getElementById("people-value").value);
  const splitTotalValue = document.getElementById("split-total-value");
  const splitTotal = billTotal / peopleTotal;
  splitTotalValue.innerText = splitTotal.toLocaleString("en", {
    style: "currency",
    currency: "USD"