Align a checkbox with its label in CSS

To align a checkbox vertically with its label, make the enclosing label a Flexbox container and set align-items: center. To align with the first line of wrapped text, start with align-items: flex-start and offset the checkbox by half the difference between its height and the line height.

Choose the center or the first line

The browser draws the native checkbox, and label text is laid out in line boxes. Check the theme for input margins or fixed offsets before adding alignment rules. Centering suits a short label. Aligning with the first line helps readers find the start of a longer consent option. See cross-axis alignment in CSS Flexbox · align-items.

Try three alignments in one example

Save the example as checkbox-align.html and open it. It compares a centered single line, a centered multiline label, and a checkbox aligned with the first line. The last two labels use identical text. Narrow the window until they wrap. The centered checkbox follows the whole text block, while the first-line example stays aligned with its top line. No dependencies or JavaScript are required.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Checkbox and label alignment</title>
  <style>
    body { margin: 20px; font: 16px/1.6 system-ui, sans-serif; color: #203348; }
    * { box-sizing: border-box; }
    h1 { font-size: 24px; }
    h2 { font-size: 17px; margin: 18px 0 8px; }
    .examples { --box-size: 20px; --leading: 1.6; max-width: 420px; }
    .option { display: flex; gap: 10px; min-height: 44px; padding: 8px;
      border: 1px solid #91a9ba; background: #eff5f8; cursor: pointer; }
    .option input { flex: none; width: var(--box-size); height: var(--box-size);
      margin: 0; font: inherit; accent-color: #176b86; }
    .option span { min-width: 0; line-height: var(--leading); overflow-wrap: anywhere; }
    .center { align-items: center; }
    .first-line { align-items: flex-start; }
    .first-line input { margin-block-start: calc((var(--leading) * 1em - var(--box-size)) / 2); }
    input:focus-visible { outline: 3px solid #b95700; outline-offset: 2px; }
  </style>
</head>
<body>
<h1>Align checkboxes with their labels</h1>
<div class="examples">
  <h2>Single line: centered</h2>
  <label class="option center" for="one">
    <input type="checkbox" id="one"><span>Send me notifications.</span>
  </label>
  <h2>Multiple lines: centered</h2>
  <label class="option center" for="middle">
    <input type="checkbox" id="middle"><span>Send me new tutorials and practice material by email. I can change my preferences later.</span>
  </label>
  <h2>Multiple lines: first-line alignment</h2>
  <label class="option first-line" for="first">
    <input type="checkbox" id="first"><span>Send me new tutorials and practice material by email. I can change my preferences later.</span>
  </label>
</div>
</body>
</html>

On the input, flex: none prevents shrinking. On the text span, min-width: 0 allows it to use the available space, and overflow-wrap: anywhere lets a long word wrap when needed. Match the for on the HTML Standard · label to the input’s id. Keeping the native control and its focus outline lets readers tab to it and toggle it with Space.

Calculate the offset and test size changes

At a 16px font size, a line height of 1.6 results in a 25.6px line box. For a 20px checkbox, set margin-block-start to (25.6px - 20px) / 2, or 2.8px. The input inherits its font so that em in the calculation uses the label’s font size. See CSS Values and Units · calc().

Add font-size: 20px to .examples. The line height becomes 32px and the offset becomes 6px. Now set --box-size to 24px. Width, height, and the calculation all use the new value, giving a 4px offset. Revert both changes afterward. Large text or an image on the first line can make that line taller, so use this calculation for plain text with a consistent line height.

Adjust an existing inline layout

For an inline layout, consider vertical-align: middle. It aligns the element’s midpoint with the parent’s baseline plus half its x-height. The property has no effect on flex items. If an existing inline checkbox needs a small adjustment, use a dedicated class like the following. See CSS 2.2 · vertical-align.

.legacy-checkbox {
  position: relative;
  top: 1.5px;
}

A positive top moves the checkbox down and a negative value moves it up. Its original space in the layout is preserved, so recheck the offset when changing the font or zoom. For borders and check marks, see the checkbox styling example.