Token Counter
A copy-paste ai / chat ui component in pure HTML & CSS. Zero dependencies, framework-agnostic, MIT-licensed.
AI / Chat UIHTMLCSSany framework
Context8,420 / 16k
Copy into your project
HTML
<!-- Token Counter -->
<div class="nuda-tokens">
<div class="nuda-tokens__head">
<span class="nuda-tokens__label">Context</span>
<span class="nuda-tokens__num">8,420 <i>/ 16k</i></span>
</div>
<div class="nuda-tokens__bar"><span class="nuda-tokens__fill"></span></div>
</div>CSS
/* Token Counter
Context window meter; gradient warns as it nears the limit.
Customize: --tk-target (current %) */
.nuda-tokens {
--tk-target: 52%;
width: 100%;
max-width: 240px;
padding: 10px;
display: flex;
flex-direction: column;
gap: 6px;
}
.nuda-tokens__head {
display: flex;
justify-content: space-between;
align-items: baseline;
}
.nuda-tokens__label {
font: 600 0.625rem ui-sans-serif, system-ui, sans-serif;
color: #a1a1aa;
text-transform: uppercase;
letter-spacing: 0.08em;
}
.nuda-tokens__num {
font: 700 0.875rem ui-sans-serif, system-ui, sans-serif;
color: #fafafa;
font-variant-numeric: tabular-nums;
}
.nuda-tokens__num i {
font-size: 0.7rem;
font-style: normal;
color: #63636e;
font-weight: 500;
margin-left: 2px;
}
.nuda-tokens__bar {
height: 5px;
background: rgba(255, 255, 255, 0.06);
border-radius: 3px;
overflow: hidden;
position: relative;
}
.nuda-tokens__fill {
position: absolute;
left: 0;
top: 0;
height: 100%;
width: 0;
background: linear-gradient(
90deg,
#e4ff54 0%,
rgba(228, 255, 84, 0.7) 70%,
#ffae54 100%
);
border-radius: 3px;
box-shadow: 0 0 4px rgba(228, 255, 84, 0.3);
animation: nuda-tk-fill 1.6s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}
@keyframes nuda-tk-fill { to { width: var(--tk-target); } }
@media (prefers-reduced-motion: reduce) {
.nuda-tokens__fill { width: var(--tk-target); animation: none; }
}How to use Token Counter
Paste the HTML where you need it and the CSS into a global stylesheet (or a <style> tag). Every class is prefixed nuda- so it never collides with Tailwind or your own styles. Tweak the CSS custom properties to match your design system.
Works in React, Vue, Svelte, Astro, Next.js, Nuxt, Laravel Blade, Django, Rails — or a single .html file. No npm install, no build step.