Markup built around data attributes

The demo lists streaming services (Netflix, Disney+, HBO Max, and so on), each with a student discount applied to its subscription price. The full price and the discount percentage live as data-* attributes on the element that renders the price:

<li>
  <!-- Service name, base price, and selection toggle -->
  <label>
    <span>Netflix</span>
    <!-- data-price and data-discount store base price and discount offered -->
    <div class="ott-price">$7.99</div>
    <!-- Checkbox to track if the user wants to add this service -->
    <input type="checkbox" class="is-ott-selected">
  </label>

  <!-- Toggle for the student discount -->
  <label>
    <span>Apply Student Discount <br> 20%</span>
    <input type="checkbox" class="is-ott-discounted">
  </label>
</li>

<!-- etc. -->

The discount only takes effect once "Apply Student Discount" is selected; after that, the post-discount price is what you see.

Deriving the sale price

The first visible change is striking through the original price:

/* When the discount toggle is checked inside the .ott container */
.ott:has(.is-ott-discounted:checked) {
  /* Strike through the original price */
  .ott-price {
    text-decoration: line-through;
  }
}

The new price then comes from combining the data-price and data-discount values:

.ott:has(.is-ott-discounted:checked) {
  .ott-price {
    text-decoration: line-through;
    /* 
        Calculate the new price from the data-* attributes:
        Original Price * (1 - Discount Applied)
    */
    --n: calc(attr(data-price number) * (1 - attr(data-discount number)));
  }
}

What makes this work is the two-argument form of attr(<name> <type>). The function was historically limited to the content property and always returned strings; it now applies to any CSS property and can parse the value into a data type. The first argument is the attribute to read, and the second tells CSS how to interpret it — as a color, a number, a length, and so on. Here both data-price and data-discount are parsed as numbers, which lets plain CSS math subtract the discount from the price. That upgraded attr() is not Baseline yet, so treat availability with caution.

Printing the result without JavaScript

.ott:has(.is-ott-discounted:checked) {
  .ott-price {
    text-decoration: line-through;
    --n: calc(attr(data-price number) * (1 - attr(data-discount number)));

    &::after {
      display: inline-block;
      /* Splits the variable --n into two counters: 
          'a' for the whole number (in dollars) and 'b' for the decimals (in cents) */
      counter-set: a calc(round(down, var(--n))) b calc((mod(var(--n), 1)) * 100);
      /* Output: two spaces (\2000), a dollar sign ($), the number, a dot, and the decimals */
      content: "\2000\2000$" counter(a) "." counter(b, decimal-leading-zero);
    }
  }
}

Getting a number out of CSS math and into visible text requires some care. The counter() function converts the numeric value of the --n variable into a content string, and because CSS counters cannot represent decimals — they round by default — the value is split into two counters that are then joined with a dot:

  1. calc(round(down, var(--n))) rounds --n down to the whole-dollar amount, stored as counter(a).
  2. calc((mod(var(--n), 1)) * 100) isolates the fractional part with mod() and scales it by 100 to produce the cents, stored as counter(b).
  3. The content property prepends a dollar sign and joins the two counters with a dot.

calc() is broadly supported, and mod() has newly reached Baseline status:

If decimals aren't needed, rounding the price is enough on its own:

counter-set: price calc(var(--n));
content: counter(price);

Takeaway

The pattern combines the upgraded attr(), CSS math functions such as mod() and round(), and custom counters to reproduce a common e-commerce calculation with no scripting at all. It depends on bleeding-edge features, but once data-type support in attr() ships everywhere, it becomes something usable in routine work — the same approach CSS can apply to other numeric readouts, such as the percentage of completed tasks in a to-do list, without script, server round-trip, latency, or extra browser resources.