<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr" -->

---
title: A Valentine's Day special: A web component to show...
description: A step-by-step tutorial builds a fun, useless web component called 'for-love' that displays animated floating hearts, published as a yearly Valentine's Day...
canonical: https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: A Valentine's Day special: A web component to show hearts on your website | daily.dev
og:description: A step-by-step tutorial builds a fun, useless web component called 'for-love' that displays animated floating hearts, published as a yearly Valentine's Day...
og:url: https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr
og:image: https://api.daily.dev/og/posts/wmh2cPjQr.png
og:image:alt: A Valentine's Day special: A web component to show hearts on your website
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# A Valentine's Day special: A web component to show hearts on your website

**[utilitybend](https://daily.dev/sources/utilitybend)** · 11 min read · 0 upvotes · 0 comments

## Summary

A step-by-step tutorial builds a fun, useless web component called 'for-love' that displays animated floating hearts, published as a yearly Valentine's Day tradition. It covers setting up a project with Vite, Lit, and TypeScript, creating a custom element with a bounded numeric property (getter/setter pattern with a max value), styling hearts with CSS custom properties and keyframe animations, randomizing heart position and animation delay, and respecting prefers-reduced-motion for accessibility. Links to the GitHub repo and npm package are included.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://utilitybend.com/blog/a-valentines-day-special-a-web-component-to-show-hearts-on-your-website>

## Questions this post answers

### How do I restrict the maximum value of a Lit @property in a web component?

Use a private backing field with a custom getter and setter instead of a plain @property declaration. Define a private maximum value, then in the setter parse the incoming value (number or string), validate it with isNaN, clamp it using Math.min against the maximum, and call this.requestUpdate('amount') to notify Lit of the change so the UI reflects the accepted value.

_daily.dev surfaces practical Lit patterns like this for developers building custom elements._

### How do I randomly position elements across the screen using CSS custom properties?

Generate a random number for each element in JavaScript, such as Math.floor(Math.random() * 101) for a percentage between 0 and 100, then set it as an inline CSS custom property like style="--left: 42%;". The CSS then references it with left: var(--left, 0), giving each element a unique horizontal position with a fallback value.

_Developers refining CSS animation tricks can find more examples like this on daily.dev._

### How do I disable CSS animations for users who prefer reduced motion?

Wrap the animation-disabling styles in an @media (prefers-reduced-motion) query and set display: none and animation: none on the animated elements. This respects users who have configured their system to avoid unintentional or disturbing on-screen motion, improving accessibility of animated components.

_Accessibility-minded developers track motion-sensitivity techniques like this on daily.dev._

## Similar posts on daily.dev

- [How I Write Custom Elements with lit-html – Frontend Masters Blog](https://daily.dev/posts/how-i-write-custom-elements-with-lit-html-frontend-masters-blog-5wo9pzi23) · Frontend Masters · 3 upvotes · 0 comments
- [Building a Web Component: : A Step-by-Step Guide](https://daily.dev/posts/building-a-web-component-a-step-by-step-guide-ks6l2hqlq) · Medium · 1 upvotes · 0 comments

---

Tags: [#css](https://daily.dev/tags/css), [#typescript](https://daily.dev/tags/typescript), [#vite](https://daily.dev/tags/vite), [#web-components](https://daily.dev/tags/web-components)

[View this post on daily.dev](https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"A Valentine's Day special: A web component to show hearts on your website","url":"https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr"},"datePublished":"2026-09-20T07:43:33.734Z","dateModified":"2026-09-20T07:46:53.409Z","description":"A step-by-step tutorial builds a fun, useless web component called 'for-love' that displays animated floating hearts, published as a yearly Valentine's Day...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2905645507bf603b569774f931dd66b0?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/2905645507bf603b569774f931dd66b0?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"utilitybend","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"utilitybend","logo":"https://media.daily.dev/image/upload/s--hONVFSz4--/f_auto,q_auto/v1789890196/logos/utilitybend?_a=BAMAMicg0","url":"https://daily.dev/sources/utilitybend"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"css,typescript,vite,web-components","timeRequired":"PT11M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"utilitybend","item":"https://daily.dev/sources/utilitybend"},{"@type":"ListItem","position":3,"name":"A Valentine's Day special: A web component to show hearts on your website"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/a-valentine-s-day-special-a-web-component-to-show-hearts-on-your-website-wmh2cpjqr#faq","mainEntity":[{"@type":"Question","name":"How do I restrict the maximum value of a Lit @property in a web component?","acceptedAnswer":{"@type":"Answer","text":"Use a private backing field with a custom getter and setter instead of a plain @property declaration. Define a private maximum value, then in the setter parse the incoming value (number or string), validate it with isNaN, clamp it using Math.min against the maximum, and call this.requestUpdate('amount') to notify Lit of the change so the UI reflects the accepted value. daily.dev surfaces practical Lit patterns like this for developers building custom elements."}},{"@type":"Question","name":"How do I randomly position elements across the screen using CSS custom properties?","acceptedAnswer":{"@type":"Answer","text":"Generate a random number for each element in JavaScript, such as Math.floor(Math.random() * 101) for a percentage between 0 and 100, then set it as an inline CSS custom property like style=\"--left: 42%;\". The CSS then references it with left: var(--left, 0), giving each element a unique horizontal position with a fallback value. Developers refining CSS animation tricks can find more examples like this on daily.dev."}},{"@type":"Question","name":"How do I disable CSS animations for users who prefer reduced motion?","acceptedAnswer":{"@type":"Answer","text":"Wrap the animation-disabling styles in an @media (prefers-reduced-motion) query and set display: none and animation: none on the animated elements. This respects users who have configured their system to avoid unintentional or disturbing on-screen motion, improving accessibility of animated components. Accessibility-minded developers track motion-sensitivity techniques like this on daily.dev."}}]}
```

