liveBook · Manning

Check box

As explained in Tiny CSS Projects

A checkbox is a form control that can be independently selected or cleared to represent a binary or multiple-choice setting.

A check box is a form control that a person can select or clear independently. In a contact form, it can offer a choice such as “Subscribe to our newsletter.” Its native square is useful, but it can be difficult to fit into a custom design because much of its appearance comes from the operating system. section 10.3 section 10.3.3

For a quick color change, target `input[type="checkbox"]` and set `accent-color: var(--accent)`. The control keeps its native appearance while using the chosen accent color. Changing the form’s font size, however, does not make the check box grow with the text. section 10.3.3

For more control over its size and shape, keep the HTML input but replace its native visuals with `appearance: none`. Set a background and remove the default margin, then give the control `width` and `height` of `1.75em`, a `1px solid currentcolor` border, and a `4px` border radius. The shared radio-button styles use `inline-grid` and `place-content: center`; the check box remains square-cornered rather than circular. These declarations style the unselected control—the supplied example does not show a custom selected-state design. section 10.3.3

Listing 10.9 Styled radio and checkbox inputs
input[type="radio"],
input[type="checkbox"] {
  appearance: none;
  background-color: var(--background);
  margin: 0;
  width: 1.75em;
  height: 1.75em;
  border: 1px solid currentcolor;      #1
  display: inline-grid;                #2
  place-content: center;               #2
}
 
input[type="radio"] { border-radius: 50% }
 
input[type="checkbox"] { border-radius: 4px }

Compare the shared radio-button and check-box rules with their separate border-radius declarations. section 10.3.3

How Tiny CSS Projects covers it

How deep it goes
Works through accent coloring and custom unselected visuals, but does not show a custom selected-state design.
Examples
Shows a newsletter choice and CSS listings for accent-colored, reset, and styled controls.
What it assumes
Starts with existing form HTML and supplied layout and theme CSS, then introduces control-specific declarations.
What you can do after
Operate/configure it with CSS to recolor a native check box or size and shape its unselected appearance.
How it connects
Links check boxes to radio buttons, native form controls, accent-color, appearance, and font-relative sizing.

Also explained in

Compare how 4 books explain check box →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Tiny CSS Projects. The section links point to the parts of the book it draws on.