Menu
Bootstrap 5 Form Floating Labels
Floating Labels / Animated Labels
By default, when using labels, they normally appear on top of the input field:
With floating labels, you can insert the label inside the input field, and make them float/animate when you click on the input field:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Floating Labels – Inputs</h2>
<p>Click inside the input field to see the floating label effect:</p>
<form action=”/action_page.php”>
<div>
<input type=”text” id=”email” placeholder=”Enter email” name=”email”>
<label for=”email”>Email</label>
</div>
<div>
<input type=”text” id=”pwd” placeholder=”Enter password” name=”pswd”>
<label for=”pwd”>Password</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Notes on floating labels: The <label> elements must come after the <input> element, and the placeholder attribute is required for each <input> element (even though it is not shown).
Textarea
It also works for textareas:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Floating Labels – Textarea</h2>
<p>Click inside the textarea to see the floating label effect:</p>
<form action=”/action_page.php”>
<div>
<textarea id=”comment” name=”text” placeholder=”Comment goes here”></textarea>
<label for=”comment”>Comments</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Select Menus
You can also use “floating-labels” on select menus. However, they will not float/get animated. The label will always appear in the top left corner, inside the select menu:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Floating Labels – Select</h2>
<p>You can also use “floating-labels” on select menus. However, they will not float/get animated. The label will always appear in the top left corner, inside the select menu:</p>
<form action=”/action_page.php”>
<div>
<select id=”sel1″ name=”sellist”>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<label for=”sel1″>Select list (select one):</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Notes on floating labels: The <label> elements must come after the <input> element, and the placeholder attribute is required for each <input> element (even though it is not shown).
Textarea
It also works for textareas:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Floating Labels – Textarea</h2>
<p>Click inside the textarea to see the floating label effect:</p>
<form action=”/action_page.php”>
<div>
<textarea id=”comment” name=”text” placeholder=”Comment goes here”></textarea>
<label for=”comment”>Comments</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Select Menus
You can also use “floating-labels” on select menus. However, they will not float/get animated. The label will always appear in the top left corner, inside the select menu:
Example
<!DOCTYPE html>
<html lang=”en”>
<head>
<title>Bootstrap Example</title>
<meta charset=”utf-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link href=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css” rel=”stylesheet”>
<script src=”https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js”></script>
</head>
<body>
<div>
<h2>Floating Labels – Select</h2>
<p>You can also use “floating-labels” on select menus. However, they will not float/get animated. The label will always appear in the top left corner, inside the select menu:</p>
<form action=”/action_page.php”>
<div>
<select id=”sel1″ name=”sellist”>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<label for=”sel1″>Select list (select one):</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>