An open API service indexing awesome lists of open source software.

https://github.com/anyblades/float-label-css

Bulletproof classless CSS-only implementation of Float Label pattern with automatic fallback for ANY non-supporting browser 🥷
https://github.com/anyblades/float-label-css

blades classless css float-label float-labels floating-label floating-labels pico-css picocss

Last synced: about 14 hours ago
JSON representation

Bulletproof classless CSS-only implementation of Float Label pattern with automatic fallback for ANY non-supporting browser 🥷

Awesome Lists containing this project

README

          

# 🥷 Pure CSS Float Label. Finally classless.

Bulletproof classless CSS-only implementation of Float Label pattern with automatic fallback for ANY non-supporting browser.

![](https://img.shields.io/github/v/release/anyblades/float-label-css?label=&color=darkslategray&style=for-the-badge&include_prereleases)
[![](https://img.shields.io/badge/Code-gainsboro?logo=github&logoColor=black&style=for-the-badge)](https://github.com/anyblades/float-label-css)
[![](https://img.shields.io/github/stars/anyblades/float-label-css?label=Star&labelColor=gainsboro&color=silver&style=for-the-badge)](https://github.com/anyblades/float-label-css)

## [Demo ↗](https://blades.ninja/css/float-label/#demo)

[](https://blades.ninja/css/float-label/#demo)

Examples:

- [**Pico + *Bl*ades** with Float Label CSS v2 included](https://blades.ninja/css/float-label/#demo)
- [**Tailwind v4** + Float Label CSS v2](https://codepen.io/tonystar/pen/ALaZrV)
- [**Float Label CSS v2 only**](https://codepen.io/tonystar/pen/JRLaKw) (no CSS frameworks)

---

## Killer features

- No JS — pure CSS
- No hacks with `required` and `:valid`
↳ HTML5 validation support
- Compatible with `` and `` fields
- No need to define `for="..."` attribute on ``
- NEW in **v2:** Finally, the text label can be placed BEFORE the input field!
- NEW in **v2:** Class-less!

---

## [Install ↗](https://blades.ninja/css/standalone/)

---

## Usage

Simply place `` inside `` to enable float label:

```html

Email

```

**NOTE:** W3C [allows this](http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL)!


Alternatively wrap `` and `` inside `.has-float-label`:

```html


Email


```

**NOTE**: `for="..."` attribute is required on `` in this case

---

## Credits

- [Matt D. Smith](https://x.com/mds) for [original pattern](https://dribbble.com/shots/1254439--GIF-Float-Label-Form-Interaction)
- Emil Björklund for [`:placeholder-shown`](https://thatemil.com/blog/2016/01/23/floating-label-no-js-pure-css/)
- [Anton Staroverov](https://x.com/AntonStarovero_) for [`:has(*:placeholder-shown:not(:focus)) label`](https://blades.ninja/css/float-label/#how)
- to finally support labels before input fields
- instead of [`input:focus + label`](https://css-tricks.com/float-labels-css/) used previously

---

## Browser support

Any browser with https://caniuse.com/css-placeholder-shown, https://caniuse.com/css-has and https://caniuse.com/css-nesting.

All non-supporting browsers should gracefully fall-back to the default layout.

=> Can be used in ANY browser _as is_!

---

Featured by:

- https://github.com/dbohdan/classless-css
- https://github.com/pryley/float-labels.js
- https://github.com/uptonking/note4yaoo/blob/main/toc/toc-lib-css-only.md#css-tools
- https://github.com/bcgov/moh-fpcare `package.json`

---

## PS: [How it works?](https://blades.ninja/css/float-label/#how)