Menu
Bootstrap 5 Forms
Stacked Form
All textual <input> and <textarea> elements with class .form-control get proper form styling:
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>Stacked form</h2>
<form action=”/action_page.php”>
<div>
<label for=”email”>Email:</label>
<input type=”email” id=”email” placeholder=”Enter email” name=”email”>
</div>
<div>
<label for=”pwd”>Password:</label>
<input type=”password” id=”pwd” placeholder=”Enter password” name=”pswd”>
</div>
<div>
<label>
<input type=”checkbox” name=”remember”> Remember me
</label>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Textarea
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>Textarea</h2>
<p>Use the .form-control class to style textareas as well:</p>
<form action=”/action_page.php”>
<div>
<label for=”comment”>Comments:</label>
<textarea rows=”5″ id=”comment” name=”text”></textarea>
</div>
<button type=”submit”>Submit</button>
</form>
</div>
</body>
</html>
Form Row/Grid (Inline Forms)
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>Inline Forms</h2>
<p>If you want your form elements to appear side by side, use .row and .col:</p>
<form>
<div>
<div>
<input type=”text” placeholder=”Enter email” name=”email”>
</div>
<div>
<input type=”password” placeholder=”Enter password” name=”pswd”>
</div>
</div>
</form>
</div>
</body>
</html>
Form Control Size
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>Form Control Size</h2>
<p>You can change the size of .form-control inputs with .form-control-lg or .form-control-sm:</p>
<form>
<input type=”text” placeholder=”Large input”>
<input type=”text” placeholder=”Normal input”>
<input type=”text” placeholder=”Small input”>
</form>
</div>
</body>
</html>
Disabled and Readonly
Use the disabled and/or readonly attributes to disable 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>Disabled and Readonly</h2>
<p>Use the disabled and/or readonly attributes to disable the input field:</p>
<form>
<input type=”text” placeholder=”Normal input”>
<input type=”text” placeholder=”Disabled input” disabled>
<input type=”text” placeholder=”Readonly input” readonly>
</form>
</div>
</body>
</html>
Plain text Inputs
Use the .form-control-plaintext class to style an input field without borders, but keep proper marigins and padding:
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>Plaintext</h2>
<p>Use the .form-control-plaintext class to style an input field without borders, but with correct marigins and padding:</p>
<form>
<input type=”text” placeholder=”Plaintext input”>
<input type=”text” placeholder=”Normal input”>
</form>
</div>
</body>
</html>
Color Picker
To style an input with type=”color” properly, use the .form-control-color class:
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>Color Picker</h2>
<p>To style an input with type=”color” properly, use the .form-control-color class:</p>
<form>
<label for=”myColor”>Color picker</label>
<input type=”color” id=”myColor” value=”#CCCCCC” title=”Choose a color”>
</form>
</div>
</body>
</html>