<section>
  <div class="container">
    <h1 data-width="auto">CSS is Awesome</h1>
    <h1 data-width="min-content">CSS is Awesome</h1>
    <h1 data-width="max-content">CSS is Awesome</h1>
  </div>
  <form action="">
    <input type="range" min="0" max="100" value="100" />
  </form>
</section>
@import url("https://fonts.googleapis.com/css2?family=Exo:wght@600&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  width: 100vw;
  min-height: 100vh;

  display: flex;
  justify-content: center;
  flex-direction: column;
  gap: 20px;
  font-family: "Exo", Arial, sans-serif;
  background-color: #f7f7f7;

  padding: 20px;
}

section {
  width: 40vw;
  margin: 0 auto;

  display: flex;
  justify-content: center;
  /*   align-items: center; */
  flex-direction: column;

  gap: 10px;
  box-shadow: 0 0 0 6px rgb(0 0 0 / 13%);
  border-radius: 6px;
}

.container {
  border: 1px dashed #f36;
  border-radius: 1px;
}

h1 {
  background-color: #f7f7f7;
  place-self: center stretch;
  color: #444;
  padding: 5px 0;
  position: relative;
}

h1::before {
  content: "width:" attr(data-width);
  position: absolute;
  right: 100%;
  top: 50%;
  transform: translate(0, -50%);
  white-space: nowrap;
  font-size: 14px;
  color: #fff;
  background: rgb(0 0 0 / 0.8);
  padding: 3px 6px;
  border-radius: 2px;
}

h1:nth-child(1) {
  background-color: #f1c2c6;
}

h1:nth-child(2) {
  background-color: #dac2f1;
}

h1:nth-child(3) {
  background-color: #ccf1c2;
}

form {
  width: 100%;
}
input[type="range"] {
  width: 100%;
}
.container {
  --width: 100%;
  padding: 20px;
  width: var(--width);
}

h1[data-width="auto"] {
  width: auto;
}

h1[data-width="min-content"] {
  width: min-content;
}

h1[data-width="max-content"] {
  width: max-content;
}
const range = document.querySelector('input[type="range"]');
const container = document.querySelector(".container");

range.addEventListener("input", (etv) => {
  container.style.setProperty("--width", `${etv.target.value}%`);
});
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.