Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ 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

Auto Save

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

              
                <div class="container">

  <!-- Блок для VH -->
  <div class="block">
    <h2>VH</h2>
    <div>
      <label for="elementWidth">Value of width</label>
      <input id="elementWidth" type="number" placeholder="">
      <span id="outputWidth"></span>
    </div>
    <div>
      <label for="elementHeight">Value of height</label>
      <input id="elementHeight" type="number" placeholder="">
      <span id="outputHeight"></span>
    </div>
    <div>
      <label for="screenWidth">Choose screen resolution</label>
      <select id="screenWidth">
        <option value="1080">1080</option>
        <option value="1920">1920</option>
        <option value="1024">1024</option>
        <option value="430">430</option>
        <option value="414">414</option>
      </select>
    </div>
  </div>

  <!-- Блок для VW -->
  <div class="block">
    <h2>VW</h2>
    <div>
      <label for="elementWidthVW">Value of width</label>
      <input id="elementWidthVW" type="number" placeholder="">
      <span id="outputWidthVW"></span>
    </div>
    <div>
      <label for="elementHeightVW">Value of height</label>
      <input id="elementHeightVW" type="number" placeholder="">
      <span id="outputHeightVW"></span>
    </div>
    <div>
      <label for="screenWidthVW">Choose screen resolution</label>
      <select id="screenWidthVW">
        <option value="414">414</option>
      </select>
    </div>
  </div>
    <div class="block">
<label for="hexInput">Enter Hex Color: </label>
    <input type="text" id="hexInput" placeholder="#ff5733" oninput="convertColor()">
    <label for="alphaInput">Alpha (0-1): </label>
    <input type="number" id="alphaInput" min="0" max="1" step="0.1" value="1" oninput="convertColor()">
    <p id="output" onclick="copyToClipboard()" style="cursor: pointer;">Click to copy</p>
      <div id="colorPreview">color</div>
  </div>
</div>
              
            
!

CSS

              
                body {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.container {
  display: flex;
  gap: 40px; /* Расстояние между блоками */
}

.block {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 20px;
  border: 2px solid green;
  border-radius: 10px;
}

h2 {
  text-align: center;
  font-size: 24px;
  color: green;
}

input, select {
  width: 120px;
  height: 30px;
  border: 2px solid green;
  border-radius: 10px;
  padding: 5px 10px;
  font-size: 18px;
}

label {
  font-size: 18px;
}

span {
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
}

span:hover {
  color: green;
}

              
            
!

JS

              
                function updateOutput() {
    const elementWidth = parseFloat(document.getElementById('elementWidth').value);
    const elementHeight = parseFloat(document.getElementById('elementHeight').value);
    const screenWidth = parseFloat(document.getElementById('screenWidth').value);

    const elementWidthVW = parseFloat(document.getElementById('elementWidthVW').value);
    const elementHeightVW = parseFloat(document.getElementById('elementHeightVW').value);
    const screenWidthVW = parseFloat(document.getElementById('screenWidthVW').value);

    // Вычисления для VH
    if (!isNaN(elementWidth) && !isNaN(screenWidth) && screenWidth !== 0) {
        let vhValueWidth = (elementWidth / screenWidth) * 100;
        let vhValueHeight = (!isNaN(elementHeight) && elementHeight !== 0) ? (elementHeight / screenWidth) * 100 : '';

        document.getElementById('outputWidth').textContent = `${vhValueWidth.toFixed(2)}vh`;
        document.getElementById('outputHeight').textContent = vhValueHeight === '' ? 'N/A' : `${vhValueHeight.toFixed(2)}vh`;
    } else {
        document.getElementById('outputWidth').textContent = "Invalid input";
        document.getElementById('outputHeight').textContent = "Invalid input";
    }

    // Вычисления для VW
    if (!isNaN(elementWidthVW) && !isNaN(screenWidthVW) && screenWidthVW !== 0) {
        let vwValueWidth = (elementWidthVW / screenWidthVW) * 100;
        let vwValueHeight = (!isNaN(elementHeightVW) && elementHeightVW !== 0) ? (elementHeightVW / screenWidthVW) * 100 : '';

        document.getElementById('outputWidthVW').textContent = `${vwValueWidth.toFixed(2)}vw`;
        document.getElementById('outputHeightVW').textContent = vwValueHeight === '' ? 'N/A' : `${vwValueHeight.toFixed(2)}vw`;
    } else {
        document.getElementById('outputWidthVW').textContent = "Invalid input";
        document.getElementById('outputHeightVW').textContent = "Invalid input";
    }
}

// Функция копирования размеров (vh/vw)
function copySizeToClipboard(event) {
    const value = event.target.textContent;
    if (value !== "Invalid input" && value !== "N/A") {
        navigator.clipboard.writeText(value).catch(err => console.error('Error copying text:', err));
    }
}

// Функция копирования цвета
function copyColorToClipboard() {
    const output = document.getElementById("output").textContent;
    if (output !== "Invalid Input") {
        navigator.clipboard.writeText(output).catch(err => {
            console.error("Error copying text: ", err);
        });
    }
}

// Добавляем обработчики клика для копирования размеров
['outputWidth', 'outputHeight', 'outputWidthVW', 'outputHeightVW'].forEach(id => {
    document.getElementById(id).addEventListener('click', copySizeToClipboard);
});

// Добавляем обработчик клика для копирования цвета
document.getElementById("output").addEventListener("click", copyColorToClipboard);

// Обновление значений при вводе
['elementWidth', 'elementHeight', 'screenWidth', 'elementWidthVW', 'elementHeightVW', 'screenWidthVW'].forEach(id => {
    document.getElementById(id).addEventListener('input', updateOutput);
});

// Функция конвертации HEX в RGBA
function hexToRgba(hex, alpha = 1) {
    hex = hex.replace(/^#/, '');
    let r, g, b;
    if (hex.length === 3) {
        r = parseInt(hex[0] + hex[0], 16);
        g = parseInt(hex[1] + hex[1], 16);
        b = parseInt(hex[2] + hex[2], 16);
    } else if (hex.length === 6) {
        r = parseInt(hex.substring(0, 2), 16);
        g = parseInt(hex.substring(2, 4), 16);
        b = parseInt(hex.substring(4, 6), 16);
    } else {
        document.getElementById("output").textContent = "Invalid Input";
        return;
    }
    return `rgba(${r}, ${g}, ${b}, ${alpha})`;
}

function convertColor() {
    const hex = document.getElementById("hexInput").value;
    const alpha = parseFloat(document.getElementById("alphaInput").value);
    const rgba = hexToRgba(hex, alpha);
    document.getElementById("output").textContent = rgba || "Invalid Input";
    if (rgba) {
        document.getElementById("colorPreview").style.backgroundColor = rgba;
    }
}

              
            
!
999px

Console