A page’s own palette
This page brings its own colors and a narrower column, and puts its rules in a layer after the design kit’s, as a demo with a look of its own does.
The sheet this page adds, shown below, writes no rule over a kit class. Everything it changes, the strip and the footer too, it changes through the properties the kit reads. The colors and the column of this site’s other pages are the kit’s own. To see the other theme live, choose Light or Dark next to Theme, at the top of the page.
What this page sets
This is all the page adds to the kit beside the site’s own sheet, which every page of this site loads, and it loads after both of them.
/*
* The page's own palette and column, as a demo with a look of its own sets them. The kit's layer
* comes first and the page's after it, so the page's rules win over the kit's. Each color role
* holds its light and dark value in one light-dark(), and the column is set on the root, where the
* kit reads it.
*/
@layer dk, page;
@layer page {
:root {
--dk-accent: light-dark(#6a3fb5, #c3a8ff);
--dk-on-accent: light-dark(#ffffff, #121212);
--dk-highlight: light-dark(#efe9fb, #2d2448);
--dk-focus: light-dark(#0f62c9, #6fb0ff);
--dk-button-shadow: 0 2px 0 var(--dk-control);
--dk-button-press: 0 2px;
--dk-column: 64rem;
}
}Its palette
The page sets the accent, the text on it, the highlight and the focus ring, each as one light-dark() that holds both themes. Every piece reads its colors from those roles, so the markup is the same as on any other page. Press Tab to see the focus ring in the page’s own color.
The one action, a toggle that is on and an action
The code behind it:
class="dk-button dk-button-accent"withdk-actionsLightDark, preview only
The code, The one action, a toggle that is on and an action
Markup, The one action, a toggle that is on and an action<div class="dk-actions"> <button type="button" class="dk-button dk-button-accent">Save rule</button> <button type="button" class="dk-button" aria-pressed="true">Members only</button> <button type="button" class="dk-button">Filters</button> </div>React, The one action, a toggle that is on and an action<div className="dk-actions"> <Button accent>Save rule</Button> <Button pressed>Members only</Button> <Button>Filters</Button> </div>A field with an error, and something that went right
The code behind it:
aria-invalid="true"withdk-field dk-field-label dk-field-hint dk-field-error dk-visually-hidden dk-input dk-callout dk-callout-success dk-callout-body dk-callout-titleWhere the alert is sent
Error: Enter an email address.
Success: The rule was saved
It applies to the next search.
LightDark, preview only
Where the alert is sent
Error: Enter an email address.
Success: The rule was saved
It applies to the next search.
The code, A field with an error, and something that went right
Markup, A field with an error, and something that went right<div class="dk-field"> <label class="dk-field-label" for="alert-email" id="alert-email-label">Email for alerts</label> <p class="dk-field-hint" id="alert-email-hint">Where the alert is sent</p> <p class="dk-field-error" id="alert-email-error"> <span class="dk-visually-hidden">Error: </span> Enter an email address. </p> <input class="dk-input" id="alert-email" aria-describedby="alert-email-hint alert-email-error" aria-invalid="true" /> </div> <div class="dk-callout dk-callout-success"> <div class="dk-callout-body"> <p class="dk-callout-title"> <span class="dk-visually-hidden">Success: </span> The rule was saved </p> <p>It applies to the next search.</p> </div> </div>React, A field with an error, and something that went right<> <InputField id="alert-email" label="Email for alerts" hint="Where the alert is sent" error="Enter an email address." /> <Callout tone="success" title="The rule was saved"> <p>It applies to the next search.</p> </Callout> </>
A page that sets its own palette answers for its own contrast. These are the pairings the kit is meant for, measured in this page’s palette. In each theme’s grid the drawn color runs across the top and the ground it sits on down the side, and a dash marks a pairing the kit never makes.
Contrast of this page’s palette in the light theme, each ratio to 1, the least to spare first
| Ground | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- |
|---|---|---|---|---|---|---|---|---|---|
| Needs | 3.00 | 4.50 | 4.50 | 4.50 | 4.50 | 4.50 | 4.50 | 3.00 | 4.50 |
--dk- | 3.11 | Not a pairing | 5.64 | Not a pairing | Not a pairing | 5.92 | Not a pairing | Not a pairing | 14.68 |
--dk- | 3.28 | 4.78 | 5.95 | Not a pairing | Not a pairing | 6.25 | Not a pairing | Not a pairing | 15.50 |
--dk- | 3.21 | Not a pairing | 5.82 | 5.69 | Not a pairing | 6.11 | Not a pairing | Not a pairing | 15.16 |
--dk- | 3.35 | Not a pairing | 6.07 | Not a pairing | 5.74 | 6.37 | Not a pairing | Not a pairing | 15.80 |
--dk- | 3.38 | 4.93 | 6.13 | 5.99 | 5.80 | 6.43 | Not a pairing | 5.33 | 15.96 |
--dk- | 3.69 | 5.37 | 6.68 | 6.53 | 6.32 | 7.02 | Not a pairing | 5.81 | 17.40 |
--dk- | 3.69 | 5.37 | 6.68 | 6.53 | 6.32 | 7.02 | Not a pairing | 5.81 | 17.40 |
--dk- | Not a pairing | Not a pairing | Not a pairing | Not a pairing | Not a pairing | Not a pairing | 7.02 | Not a pairing | Not a pairing |
Contrast of this page’s palette in the dark theme, each ratio to 1, the least to spare first
| Ground | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- | --dk- |
|---|---|---|---|---|---|---|---|---|---|
| Needs | 3.00 | 4.50 | 4.50 | 4.50 | 4.50 | 4.50 | 4.50 | 3.00 | 4.50 |
--dk- | 3.50 | Not a pairing | 5.84 | Not a pairing | Not a pairing | 7.11 | Not a pairing | Not a pairing | 12.64 |
--dk- | 3.45 | 6.46 | 5.78 | Not a pairing | Not a pairing | 7.03 | Not a pairing | Not a pairing | 12.49 |
--dk- | 3.66 | Not a pairing | 6.11 | 6.60 | Not a pairing | 7.43 | Not a pairing | Not a pairing | 13.22 |
--dk- | 3.28 | Not a pairing | 5.48 | Not a pairing | 7.30 | 6.66 | Not a pairing | Not a pairing | 11.85 |
--dk- | 4.04 | 7.57 | 6.76 | 7.30 | 9.01 | 8.22 | Not a pairing | 7.40 | 14.62 |
--dk- | 3.48 | 6.51 | 5.82 | 6.28 | 7.76 | 7.08 | Not a pairing | 6.37 | 12.59 |
--dk- | 4.55 | 8.50 | 7.60 | 8.20 | 10.13 | 9.24 | Not a pairing | 8.32 | 16.43 |
--dk- | Not a pairing | Not a pairing | Not a pairing | Not a pairing | Not a pairing | Not a pairing | 9.24 | Not a pairing | Not a pairing |
Its column
The kit lines the strip, the header, the page and the footer up on one column, --dk-column, 72rem wide unless a page sets it. This page sets it to 64rem on its root, where the kit reads it, so on a wide screen everything here stands in further from the sides than on the other pages. A phone is narrower than either column, so it shows no change.
Its layers
The kit’s rules sit in a layer named dk. The page names its own layer after it, with @layer dk, page; before any rule of its own, so whatever it sets in page wins over the kit, however little its selector weighs. A rule outside any layer wins over both, as the site’s own sheet does.
The properties a page sets
Beyond the color roles, these are the properties the kit reads and leaves to a page, each unset until a page sets it, on its root or on a piece by a class of its own. This page sets --dk-focus, --dk-button-shadow and --dk-button-press, so its buttons sit on a shadow and move as they are pressed.
Every property a page sets
| Property | What it sets |
|---|---|
--dk-button-grid-least | The least width of a cell in a grid of buttons |
--dk-button-grid-columns | The columns a grid of buttons asks for, 3 unless set |
--dk-focus | The focus ring and a control’s edge under a pointer, the accent unless set |
--dk-button-shadow | A shadow under a button at rest, none unless set |
--dk-button-press | How a held button moves, as a whole translate such as 0 2px, and where a toggle that is on or a button whose panel is open rests |
--dk-field-measure | The widest a field, a row of fields or a callout in its form grows in a page, a band or a stack, the measure unless set |
--dk-fields-least | The width each field in a row of fields starts from, so two share a line only where both fit, 10rem unless set |
--dk-band-room | The room above and below a band, inside its ground |
--dk-band-hero-picture | The width of a hero’s picture beside its words |
--dk-sections-least | The least width of a section in a group of sections, 20rem unless set |
--dk-table-ground | The ground under a table’s pinned column |
--dk-table-pinned-size | The width of a table’s pinned column, 8rem unless set |
--dk-panel-shadow | The shadow under a raised panel, the resting shadow unless set |
--dk-row-picture-size | The width and height of a picture at a row’s start |
--dk-tile-ground | The ground under a tile, the card’s on a page and the page’s in a panel |
--dk-tile-shadow | A shadow under a tile, none unless set |
--dk-tile-least | The least width of a tile in columns, 15rem unless set |
--dk-stepper-digits | The figures a stepper’s field keeps room for, 2 unless set |