CSS Portal

CSS <integer> Data Type

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

Description

The <integer> CSS data type represents a numeric value without a fractional component. It is used in situations where only whole numbers make sense, such as counting repetitions, defining grid rows, or specifying iterations for animations. Unlike the <number> type, which allows decimals, <integer> strictly forbids fractions, ensuring precise, whole-number behavior in CSS calculations and property values.

One of the most common uses of <integer> is with the animation-iteration-count property, where it defines how many times an animation should repeat. Using a non-integer value in this context would cause an invalid value error. Similarly, it is used in properties such as z-index to control stacking order, where fractional numbers do not make sense.

The <integer> type is also commonly encountered when defining the number of columns in a CSS grid using grid-template-columns. Here, each column can be counted as a whole unit, ensuring proper alignment and layout. It is important to distinguish <integer> from types like <number> or <length>, which allow fractional or measurement-based values.

Code examples:

/* Animation repeating 3 times using <integer> */
@keyframes blink {
  0% { opacity: 0; }
  50% { opacity: 1; }
  100% { opacity: 0; }
}

.element {
  animation-name: blink;
  animation-duration: 2s;
  animation-iteration-count: 3; /* <integer> value */
}

/* Using <integer> in z-index */
.modal {
  position: relative;
  z-index: 10; /* <integer> value */
}

/* Grid with <integer> columns */
.grid-container {
  display: grid;
  grid-template-columns: repeat(4, 1fr); /* 4 is an <integer> */
}

The <integer> type ensures consistency wherever whole numbers are expected, making it a reliable choice for properties that depend on discrete values.

Syntax

property: <integer>;

Values

  • <integer>Consists of one or several decimal digits, 0 through 9 inclusive, optionally preceded by a single + or - sign.

Example

<div class="demo">
<h2>CSS &lt;integer&gt; demo</h2>
<div class="examples">
<div class="box box-0"></div>
<div class="box box-3"></div>
<div class="box box-7"></div>
<div class="box box-hover"></div>
</div>
<p class="note">Hover the rightmost box to change the integer (animated).</p>
</div>
@property --count {
    syntax: "";
    inherits: false;
    initial-value: 1;
}

:root {
    --unit: 18px;
    --gap: 12px;
    --bg: #0ea5a4;
}

* {
    box-sizing: border-box;
}

.demo {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
    padding: 24px;
    color: #0f172a;
}

h2 {
    margin: 0 0 12px 0;
    font-size: 16px;
}

.examples {
    display: flex;
    gap: var(--gap);
    align-items: center;
    margin-bottom: 12px;
}

.box {
    --count: 1;
    width: calc(var(--count) * var(--unit));
    height: 48px;
    background: linear-gradient(90deg, var(--bg), #06b6d4);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
    transition: width 350ms ease;
    position: relative;
    min-width: 36px;
    padding: 0 8px;
}

.box::before {
    content: var(--count);
    position: relative;
    z-index: 1;
}

.box-0 {
    --count: 0;
    background: linear-gradient(90deg, #94a3b8, #64748b);
}

.box-3 {
    --count: 3;
}

.box-7 {
    --count: 7;
}

.box-hover {
    --count: 2;
    cursor: pointer;
}

.box-hover:hover {
    --count: 8;
}

.note {
    margin: 0;
    font-size: 13px;
    color: #475569;
}

Browser Support

The following information will show you the current browser support for the CSS integer data type. Hover over a browser icon to see the version that first introduced support for this CSS data type.

This data type is supported by all modern browsers.
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: 2nd January 2026

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