Buttons · Checkboxes · Lists · Message Boxes — Write code & see it live!
Buttons allow users to trigger actions. HTML provides two ways to create buttons.
The most versatile way to create a button. Can contain text, icons, or even images.
<button type="button">Click Me</button> <button type="submit">Submit Form</button> <button type="reset">Reset Form</button>
type="button" — generic clickable button (no form action)type="submit" — submits the form datatype="reset" — resets all form fields to defaultAn alternative using the <input> element with type set to button,
submit, or reset.
<input type="button" value="Click Me"> <input type="submit" value="Submit"> <input type="reset" value="Reset">
Buttons can be styled with background-color, color,
border-radius, padding, and cursor: pointer.
button {
background-color: #6c63ff;
color: white;
padding: 10px 24px;
border: none;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #5a52d5;
}
Checkboxes allow users to select one or more options from a set.
<input type="checkbox" id="agree" name="agree"> <label for="agree">I agree to the terms</label>
type="checkbox" — creates the tick boxid — links to the <label> via forname — identifies the field in form submissionsvalue — the value sent when checkedchecked — pre-selects the checkboxMultiple checkboxes can share the same name to form a group. Each should have a unique
value.
<label><input type="checkbox" name="hobby" value="reading"> Reading</label> <label><input type="checkbox" name="hobby" value="gaming"> Gaming</label> <label><input type="checkbox" name="hobby" value="cooking"> Cooking</label>
Wrapping a checkbox with a <label> or using the for attribute
improves
accessibility and makes the text clickable too.
Lists organize content into structured groups. HTML supports three types.
Creates a numbered list. Each item uses <li>.
<ol>
<li>First step</li>
<li>Second step</li>
<li>Third step</li>
</ol>
Creates a bulleted list.
<ul>
<li>Apple</li>
<li>Banana</li>
<li>Cherry</li>
</ul>
Used for term-definition pairs with <dt> (term) and <dd>
(definition).
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Lists can be nested inside other lists to create hierarchical structures.
Message boxes are styled containers that display informational, success, warning, or error messages to users.
<div class="message success">
✅ Operation completed successfully!
</div>
<div class="message error">
❌ Something went wrong. Please try again.
</div>
.message {
padding: 14px 20px;
border-radius: 8px;
margin: 10px 0;
font-weight: 600;
}
.message.success {
background-color: #d4edda;
color: #155724;
border: 1px solid #c3e6cb;
}
.message.error {
background-color: #f8d7da;
color: #721c24;
border: 1px solid #f5c6cb;
}
.message.warning {
background-color: #fff3cd;
color: #856404;
border: 1px solid #ffeaa7;
}
.message.info {
background-color: #d1ecf1;
color: #0c5460;
border: 1px solid #bee5eb;
}
JavaScript provides built-in dialog boxes:
alert("message") — shows a message with OK buttonconfirm("question") — shows OK/Cancel, returns true/falseprompt("question") — shows a text input, returns the entered valueReal-world forms combine buttons, checkboxes, lists, and feedback messages together.
Wraps all form controls together for submission.
<form action="/submit" method="POST">
<!-- form fields go here -->
<button type="submit">Submit</button>
</form>
<label> for each input for accessibility<fieldset> and <legend>:hover and :active pseudo-classes for interactive buttonsBuild real HTML form elements — buttons, checkboxes, lists, and message boxes!
Edit code in the editor, click Run Code to see the output, then reveal the solution.