Skip to content

Floating label fields in WordPress

Fields whose label slides above the entry, in pure CSS.

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

Open in a new tab

The code in WordPress

champs-libelle-flottant.php
<?php
/**
 * Plugin Name: Forge, Champs à libellé flottant
 * Description: Des champs dont le libellé se loge au-dessus de la saisie, en CSS pur. Ajoute la composition « Champs à libellé flottant » à 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-champs-libelle-flottant
 *
pattern.html
<!-- wp:html -->
<form class="float-form" action="#envoi">
        <div class="float-field">
          <input id="float-name" type="text" name="name" placeholder=" " autocomplete="name">
          <label for="float-name">Nom complet</label>
        </div>
        <div class="float-field">
          <input id="float-email" type="email" name="email" placeholder=" " autocomplete="email">
          <label for="float-email">Adresse e-mail</label>
        </div>
        <div class="float-field">
          <input id="float-phone" type="tel" name="tel" placeholder=" " autocomplete="tel">
style.css
:root {
  --field-bg: #ffffff;
  --field-line: #94a3b8;
  --field-focus: #1d4ed8;
  --field-text: #0f172a;
  --field-label: #475569;
  --field-button: #1d4ed8;
  --field-button-text: #ffffff;
  --demo-champs-libelle-flottant-bg: #f1f5f9;
  --demo-champs-libelle-flottant-text: #0f172a;
}

Free component: copy it freely, including for commercial projects.

Forms and inputs components in WordPress
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component