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="card">
  <p>Convert RGB/RGBA/HEX to HEXA <span class="info">(Beta / by onigetoc)</span></p>

  <!-- COLOR PICKER -->
  <!-- <span class="color-picker">
  <label for="colorPicker">
    <input type="color" value="#1DB8CE" id="colorPicker">
  </label>
</span> -->

  <div class="item">
    <input type="color" id="colorPicker" value="#246DBC">
    <input type="" id="colorInput" class="rgb-input" type="text" value="" placeholder="rgba(36, 109, 188, 0.5) OR #246dbc">
    <!--   <button>Convert</button> -->
  </div>

  <div class="container" style="display:none">
    Opacity:
    <input type="range" id="my-slider" min="0" max="1" value="1" step="0.01" oninput="slider()">
    <div id="slider-value">1</div>
  </div>

  Hex: <span class="result"></span>
  <div></div>
  HexA: <span class="result2"></span>
  <div></div>
  Synthedit: <span class="result3"></span>
  <div></div>
  SE flip Hex: <span class="result4"> </span>
  <div></div>
</div>

<!-- hexA table here: https://codepen.io/chriscoyier/pen/XjbzrW -->
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Open+Sans:300,600);

body {
  font-family: "Open Sans", sans-serif;
  background-color: #246dbc;
}

.card {
  display: inline-block;
  padding: 20px;
  background-color: rgba(255, 255, 255, 0.5);
  p {
    margin: 0;
  }
  .info {
    font-size: 10px;
    padding: 1px 5px;
    background-color: yellow;
  }
}

.item {
  margin-bottom: 20px;
}

input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active {
    transition: background-color 5000000s ease-in-out 0s;
}

#colorInput {
  height: 40px;
  width: 270px;
  font-size: 16px;
  padding: 0;
  padding-left: 5px;
  margin-top: 5px;
  background-color: transparent;
  border: none;
  border-bottom: 2px solid;
  &:focus {
    outline: none;
  }
}

button {
  cursor: pointer;
  height: 43px;
  font-size: 14px;
}

.result,
.result2,
.result3,
.result4{
  font-size: 30px;
  text-transform: uppercase;
  //text-transform: lowercase;
}

.container {
  background-color: transparent;
  width: 320px !important;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0px;
  border-radius: 5px;
  margin-bottom: 25px;
}
input[type="range"] {
  position: relative;
  -webkit-appearance: none;
  -moz-appearance: none;
  display: block;
  width: 80%;
  height: 8px;
  background-color: #d5d5d5;
  border-radius: 8px;
  outline: none;
  
 background: linear-gradient(to right, rgb(50, 100, 254) 100%, rgb(213, 213, 213) 100%);
}
input[type="range"]::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  height: 8px;
}
input[type="range"]::-moz-track {
  -moz-appearance: none;
  height: 8px;
}
input[type="range"]::-ms-track {
  appearance: none;
  height: 8px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  background-color: #3264fe;
  border-radius: 50%;
  cursor: pointer;
  margin-top: -6px;
  border: none;
}
input[type="range"]::-moz-range-thumb {
  -webkit-appearance: none;
  height: 20px;
  width: 20px;
  background-color: #3264fe;
  border-radius: 50%;
  cursor: pointer;
  margin-top: -6px;
  border: none;
}
input[type="range"]::-ms-thumb {
  appearance: none;
  height: 20px;
  width: 20px;
  background-color: #3264fe;
  border-radius: 50%;
  cursor: pointer;
  margin-top: -6px;
  border: none;
}
input[type="range"]:active::-webkit-slider-thumb {
  background-color: #ffffff;
  border: 3px solid #3264fe;
}
#slider-value {
  width: 40px;
  position: relative;
  background-color: #3264fe;
  color: #ffffff;
  text-align: center;
  font-family: "Roboto Mono", monospace;
  padding: 2px 2px;
  border-radius: 5px;
}

// COLOR PICKER
code {
  padding: 5px 8px;
  border-radius: 10px;
  background-color: #f8f9f9;
  color: #cc0066;
}

[type="color"] {
  // -moz-appearance: none;
  // -webkit-appearance: none;
  // appearance: none;
  padding: 0;
  width: 35px;
  height: 35px;
  border: none;
  background-color: transparent;
  position: relative;
  top: 8px;
}

// [type='color']::-webkit-color-swatch-wrapper {
//   padding: 0;
// }

// [type='color']::-webkit-color-swatch {
//   border: none;
// }

// .color-picker {
//   padding: 10px 15px;
//   border-radius: 10px;
//   border: 1px solid #ccc;
//   background-color: #f8f9f9;
// }

              
            
!

JS

              
                //Function to convert hex format to a rgb color

var hexAlpha,
  hexAlphaSE,
  hex,
  gethex,
  opacity,
  opaslider = 1;

function rgb2hex(rgba) {
  var rgb = validDigits(rgba);

  rgb = rgb.match(/^[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?,[\s+]?(\d+)[\s+]?/i);
  return rgb && rgb.length === 4
    ? "#" +
        ("0" + parseInt(rgb[1], 10).toString(16)).slice(-2) +
        ("0" + parseInt(rgb[2], 10).toString(16)).slice(-2) +
        ("0" + parseInt(rgb[3], 10).toString(16)).slice(-2)
    : "";
}

// $('button').click(function(){
//   var hex = rgb2hex($('input').val());
//   $('.result').html(hex);
//   $('body').css('background-color', hex);
// });

$(".rgb-input").on("input", function () {
  getrgb2hex();
});

function getrgb2hex(opaslider) {
  //alert(opaslider);

  var hexvalue = trim($("#colorInput").val());
  var rgba = validDigits(hexvalue);
  opacityval = getOpacity(rgba);

  trim(hexvalue);

  if (hexvalue.indexOf("#") > -1) {
    $(".container").show();
    //     //opaslider
    //     newhexvalue = hexvalue.substr(0, hexvalue.lastIndexOf(","));
    // //alert(newhexvalue);

    hex = hexvalue;
    hex2 = addAlpha(hexvalue, opaslider);
    hex3 = addAlphaSE(hexvalue, opaslider);
    hex4 = addFlipSE(hexvalue);
  } else if (hexvalue.indexOf(",") > -1) {
    $(".container").hide();

    hex = rgb2hex(rgba);
    hex2 = addAlpha(hex, opacityval);
    hex3 = addAlphaSE(hex, opacityval);
    hex4 = addFlipSE(hex);
  } else {
    $(".container").show();
    hexvalue = "#" + hexvalue;
    hex = hexvalue;
    hex2 = addAlpha(hexvalue, opaslider);
    hex3 = addAlphaSE(hexvalue, opaslider);
    hex4 = addFlipSE(hexvalue);
  }

  //var hex = rgb2hex($("input").val());
  $("#colorPicker").val(hex);

  $(".result").html(hex);
  $(".result2").html(hex2);
  $(".result3").html(hex3);
  $(".result4").html(hex4);
  $("body").css("background-color", hex2);
}

function validDigits(n) {
  return n.replace(/[^\d,.]+/g, "");
}

function addAlpha(color, opacity) {
  var opacity;
  // coerce values so ti is between 0 and 1.
  const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
  return color + _opacity.toString(16).toUpperCase();
}

function addAlphaSE(color, opacity) {
  // coerce values so ti is between 0 and 1.
  color = color.substring(1);
  const _opacity = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
  return _opacity.toString(16).toUpperCase() + color;
}

function addFlipSE(colorcode){

colorcode = colorcode.slice(colorcode.length - 6);
const colorlasttwo = colorcode.slice(- 2);
const colorcenter = colorcode.slice(2,-2);
const colorfirsttwo = colorcode.slice(0,2);

return '#'+colorlasttwo+colorcenter+colorfirsttwo;
}

function getOpacity(colorcode) {
  var opacity = colorcode.split(",");
  // Accessing individual values

  return opacity[3];
}

function trim(str) {
  return str.replace(/^\s+|\s+$/gm, "");
}

const mySlider = document.getElementById("my-slider");
const sliderValue = document.getElementById("slider-value");

function slider() {
  valPercent = (mySlider.value / mySlider.max) * 100;

  var slideropacity = mySlider.value;

  getrgb2hex(slideropacity);

  mySlider.style.background = `linear-gradient(to right, #3264fe ${valPercent}%, #d5d5d5 ${valPercent}%)`;
  sliderValue.textContent = mySlider.value;
}
//slider();

///////////// COLOR PICKER

document.querySelectorAll("input[type=color]").forEach(function (picker) {
  picker.addEventListener("change", function () {
    let color_input = document.getElementById("colorInput");
    color_input.value = picker.value;
    getrgb2hex();
  });
});

              
            
!
999px

Console