<h1>Complementary Colors Using Relative Color Syntax</h1>
<div class="container">
<div class="box box01">Base Color</div>
<div class="box box02">Complementary</div>
</div>
* {
box-sizing: border-box;
}
:root {
/* font settings */
font-family: system-ui, sans-serif;
font-size: 1.2rem;
/* Base Color Settings */
--base-color: #663399;
--complementary: oklch(from var(--base-color) l c calc(h + 180));
}
body {
display: flex;
flex-direction: column;
place-items: center;
}
.container {
display: flex;
flex-direction: row;
gap: 1rem;
}
.box {
inline-size: 200px;
block-size: 200px;
border: 1px solid black;
/* optional */
display: flex;
place-content: center;
align-items: center;
}
.box01 {
background: var(--base-color);
color: color-contrast(var(--base-color) vs white, black);
}
.box02 {
background: var(--complementary);
color: color-contrast(var(--complementary) vs white, black);
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.