<div class="box initial__value">Initial Value</div>
<div class="box new__value">New Value</div>
<div class="box invalid__value">Invalid Value</div>
@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;
  font-family: "Exo", Arial, sans-serif;
  background-color: #222;
  color: #f36;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 1.5rem;
  gap: 10px;
  padding: 10px;
}

.box {
  border-radius: 5px;
  padding: 10px 20px;
  font-size: 2rem;
  display: inline-flex;
  justify-content: center;
  align-items: center;
}

@property --primary-color {
  syntax: "<color>";
  initial-value: #0055fe;
  inherits: false;
}

/* 使用 --primary-color初始值 */
.initial__value {
  border: 5px solid var(--primary-color);
}

/* 重置 --primary-color值 */
.new__value {
  --primary-color: #09f;
  border: 5px solid var(--primary-color);
}

/* 无效值,但会引用--primary-color初始值 */
.invalid__value {
  --primary-color: 5px;
  border: solid var(--primary-color);
  color: var(--primary-color);
}

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.