Thanks to visit codestin.com
Credit goes to www.cssportal.com

CSS Portal

::checkmark CSS Pseudo Element

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!

Description

The ::checkmark pseudo-element is a specialized CSS construct primarily used in conjunction with custom checkboxes and radio buttons to style the visual indicator that signifies selection. It allows developers to separate the design of the check indicator from the actual input element of type checkbox or radio, giving complete control over the appearance without altering the underlying form functionality. Unlike standard pseudo-elements like ::before or ::after, ::checkmark is intended specifically for the interactive state of selectable form elements, making it a key tool in custom form UI design.

This pseudo-element is often paired with a container element, such as a label, that wraps the checkbox or radio input. Developers can apply styles to ::checkmark to change its size, shape, color, or transitions, reflecting states like hover, focus, or checked. For instance, background-color, border-radius, and box-shadow are commonly used to create appealing visual effects.

A typical example of ::checkmark usage is as follows:

<label class="custom-checkbox">
  Accept Terms
  <input type="checkbox">
  <span class="checkmark"></span>
</label>
.custom-checkbox {
  position: relative;
  padding-left: 25px;
  cursor: pointer;
  user-select: none;
}

.custom-checkbox input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
}

.custom-checkbox .checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 20px;
  width: 20px;
  background-color: #eee;
  border-radius: 4px;
}

.custom-checkbox input:checked ~ .checkmark {
  background-color: #2196F3;
}

.custom-checkbox .checkmark::checkmark {
  content: "";
  position: absolute;
  left: 6px;
  top: 2px;
  width: 6px;
  height: 12px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

In this example, ::checkmark is used to render the check symbol inside the styled checkbox. It provides a flexible way to control the appearance of selection without touching the actual input element. This pseudo-element is particularly useful when creating fully custom checkboxes and radio buttons that maintain accessibility while offering modern, interactive designs.

The ::checkmark pseudo-element also supports animation and transitions, allowing smooth appearance changes when a checkbox is toggled. Combined with transition or transform, it can produce professional, user-friendly effects that enhance the overall user experience.

Syntax

::checkmark {
  /* ... */
}

Example

<label>
Accept Terms
<input type="checkbox">
</label>
/* Basic input styling */
input[type="checkbox"] {
width: 20px;
height: 20px;
accent-color: #eee; /* base box color */
cursor: pointer;
vertical-align: middle;
}

/* Styling the checkmark using ::checkmark */
input[type="checkbox"]::checkmark {
background-color: #2196F3; /* checkmark background */
border-radius: 4px;
width: 16px;
height: 16px;
transform: scale(0); /* start hidden */
transition: transform 0.2s ease-in-out;
}

/* Show the checkmark when checked */
input[type="checkbox"]:checked::checkmark {
transform: scale(1);
}

/* Optional hover effect */
input[type="checkbox"]:hover::checkmark {
background-color: #1976D2;
}

Browser Support

The following information will show you the current browser support for the CSS ::checkmark pseudo element. Hover over a browser icon to see the version that first introduced support for this CSS psuedo element.

This psuedo element is supported in some modern browsers, but not all.
Desktop
Chrome
Edge
Firefox
Opera
Safari
Tablets & Mobile
Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-

Last updated by CSSPortal on: 31st December 2025

If this site has been useful, we’d love your support! Consider buying us a coffee to keep things going strong!