Nutrition table with adjustable portion in WordPress
The regulatory nutrition table per 100 g and per portion, with the reference intake percentage, an adjustable portion and allergens in bold in the ingredients.
Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.
This component also comes in
The code in WordPress
<!-- wp:html -->
<section class="tnu" data-tnu aria-labelledby="tnu-titre">
<p class="tnu-eyebrow">Granola noisettes et miel · sachet de 400 g</p>
<h2 class="tnu-title" id="tnu-titre">Informations nutritionnelles</h2>
<div class="tnu-field">
<label class="tnu-field-label" for="tnu-portion">Ma portion, en grammes</label>
<input class="tnu-input" id="tnu-portion" type="number" inputmode="numeric" min="10" max="200" step="5" value="45" data-tnu-portion aria-describedby="tnu-aide">
<p class="tnu-help" id="tnu-aide">Portion conseillée : 45 g, soit un bol avec du lait.</p>
</div>
<div class="tnu-scroll">
<table class="tnu-table">
<caption class="tnu-caption" data-tnu-caption>Valeurs moyennes pour 100 g et pour une portion de 45 g</caption>(() => {
if (!document.querySelector(".tnu")) return;
document.querySelectorAll("[data-tnu]").forEach((root) => {
const on = (el, type, fn) => el.addEventListener(type, fn);
const input = root.querySelector("[data-tnu-portion]");
const head = root.querySelector("[data-tnu-head]");
const caption = root.querySelector("[data-tnu-caption]");
const fmt = (v, d) => {
const f = 10 ** d;
return (Math.floor(v * f + 0.5) / f).toFixed(d).replace(".", ",");
};
:root {
--tnu-card: #ffffff;
--tnu-text: #1f1a14;
--tnu-muted: #574d40;
--tnu-line: #d8cfc2;
--tnu-accent: #8a4b08;
--demo-tableau-nutritionnel-bg: #f1ebe1;
--demo-tableau-nutritionnel-text: #1f1a14;
}
@media (prefers-color-scheme: dark) {
:root.forge-follows-system:not([data-theme="light"]) {<?php
/**
* Plugin Name: Forge, Tableau nutritionnel avec portion réglable
* Description: Le tableau nutritionnel réglementaire pour 100 g et par portion, avec le pourcentage des apports de référence, une portion réglable et les allergènes en gras dans les ingrédients. Ajoute la composition « Tableau nutritionnel avec portion réglable » à l'éditeur de blocs.
* Version: 1.0.0
* Requires at least: 6.6
* Requires PHP: 8.1
* Author: Forge
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: forge-tableau-nutritionnel
*Free component: copy it freely, including for commercial projects.
Other data tables components in WordPress
Data tables components in WordPress
A documentation table showing where a kit or component has been tested (static HTML, WordPress, Elementor, Webflow, v0…), with status, last test date and a remark, filterable by status.
- Tailwind
- React
- CSS
- WordPress

A table of the towns and postcodes a tradesperson covers, with response time and travel fee, filtered by search and by zone.
- Tailwind
- React
- CSS
- WordPress

A timetable table sorted by column and filtered with level and free-place chips, whose rows each become a card on phones.
- Tailwind
- React
- CSS
- WordPress

A filterable table whose visible rows export in one click to a CSV file that opens cleanly in Excel or LibreOffice.
- Tailwind
- React
- CSS
- WordPress

A price table by service: one package to pick, options to tick, and the total with the estimated time recalculated on every click.
- Tailwind
- React
- CSS
- WordPress

A product spec sheet as two-column tables in native collapsible sections, with a button to open or close them all.
- Tailwind
- React
- CSS
- WordPress