Copied successfully!
Introduction to <fieldset>
tag
The <fieldset>tag in HTML is a versatile and useful element designed to group related elements within a form. It is primarily used to organize form elements such as input fields, checkboxes, radio buttons, and other interactive components to enhance the user experience and make forms more accessible and easy to navigate.
Purpose of the <fieldset>
Tag
Grouping Related Elements: The <fieldset>tag is used to group related form elements, making it clear to users which inputs are related. This is particularly useful in forms with many fields, as it helps break the form into manageable sections.
Improving Accessibility: When used correctly, the <fieldset>tag enhances the accessibility of forms for screen readers and other assistive technologies. Screen readers will announce the content of the <legend>tag (a child of <fieldset>) as the title of the group, providing context to visually impaired users.
Styling and Layout: The <fieldset>tag can also be styled using CSS to create visual groupings within a form. This can include borders, padding, and other stylistic elements that help differentiate one group of fields from another.
Copy to clipboard
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>title of <fieldset> tag</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<header>
<h1>Compact Ultra-Modern Fieldset</h1>
</header>
<div class="container">
<form>
<fieldset class="fieldset-container">
<legend>Personal Information</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name" placeholder="Enter your name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter your email" required>
<label for="phone">Phone:</label>
<input type="tel" id="phone" name="phone" placeholder="Enter your phone number">
</fieldset>
<fieldset class="fieldset-container">
<legend>Address Details</legend>
<label for="address">Address:</label>
<input type="text" id="address" name="address" placeholder="Enter your address">
<label for="city">City:</label>
<input type="text" id="city" name="city" placeholder="Enter your city">
<label for="state">State:</label>
<select id="state" name="state">
<option value="CA">California</option>
<option value="TX">Texas</option>
<option value="NY">New York</option>
<!-- Add more options as needed -->
</select>
<label for="zip">Zip Code:</label>
<input type="text" id="zip" name="zip" placeholder="Enter your zip code">
</fieldset>
<button type="submit">Submit</button>
</form>
</div>
</body>
</html>
Copy to clipboard
body {
font-family: 'Roboto', sans-serif;
background: linear-gradient(135deg, #d1dfff, #d2d5ff);
color: #333;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
flex-direction: column;
}
header {
background-color: #ffffff;
color: #007bff;
text-align: center;
padding: 20px;
width: 100%;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
position: fixed;
top: 0;
left: 0;
z-index: 1000;
border-bottom: 3px solid #007bff;
}
.container {
padding: 20px;
max-width: 500px; /* Smaller container width */
width: 100%;
background: #ffffff;
border-radius: 12px;
box-shadow: 0 16px 32px rgba(0, 0, 0, 0.3);
margin-top: 80px; /* Offset for fixed header */
position: relative;
z-index: 1;
}
h1 {
font-size: 2.4rem; /* Adjusted font size */
margin: 0;
font-weight: 800;
color: #333;
}
.fieldset-container {
border: 3px solid #007bff;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
background: #f0f4f8;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
transition: all 0.3s ease;
}
.fieldset-container:hover {
background: #e9eff6;
border-color: #0056b3;
}
legend {
font-size: 1.6rem; /* Adjusted font size */
color: #007bff;
padding: 0 12px;
background: #ffffff;
border-radius: 10px;
border: 3px solid #007bff;
display: inline-block;
margin-bottom: 15px;
}
label {
display: block;
margin-bottom: 12px;
font-weight: 600;
color: #495057;
}
input, select, textarea {
width: calc(100% - 24px);
padding: 10px;
margin-bottom: 12px;
border: 2px solid #ced4da;
border-radius: 8px;
font-size: 1rem;
transition: all 0.3s ease;
background: #ffffff;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
input:focus, select:focus, textarea:focus {
border-color: #007bff;
box-shadow: 0 0 8px rgba(0, 123, 255, 0.3);
outline: none;
}
button {
background: linear-gradient(135deg, #ff2b9f, #4164ff);
color: #ffffff;
border: none;
padding: 10px 20px;
border-radius: 10px;
cursor: pointer;
font-size: 1.1rem;
transition: background 0.3s, transform 0.3s;
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}
button:hover {
background: linear-gradient(135deg, #d82085, #2d4cd6);
transform: scale(1.05);
}
Global Attributes
Attributes | Description |
---|---|
accesskey | Specifies a shortcut key to activate or focus an element. |
autocapitalize | Controls whether and how text input is automatically capitalized. |
class | Specifies one or more class names for the element, allowing CSS styling and JavaScript manipulation. |
contenteditable | Specifies whether the content of an element is editable or not. |
contextmenu | Specifies a context menu for the element. |
dir | Defines the text direction. Possible values are "ltr" (left-to-right), "rtl" (right-to-left), and "auto". |
draggable | Specifies whether an element is draggable. Possible values are "true" or "false". |
enterkeyhint | Specifies the action label or icon to be shown for the enter key on virtual keyboards. |
hidden | Indicates that the element is not yet, or is no longer, relevant. The browser does not display elements that have the `hidden` attribute set. |
id | Specifies a unique identifier for the element. |
inputmode | Provides a hint to browsers for which virtual keyboard configuration to use when editing this element or its descendants. |
is | Allows you to specify the type of custom element. |
lang | Specifies the language of the element's content. |
nonce | A cryptographic nonce ("number used once") that can be used by Content Security Policy (CSP) to determine whether or not a given fetch will be allowed to proceed. |
part | Specifies the element’s part in the shadow DOM. |
slot | Assigns a slot in a shadow DOM shadow tree. |
spellcheck | Indicates whether the element is subject to spell checking. |
style | Provides inline CSS styling for the element. |
tabindex | Specifies the tab order of the element. |
title | Adds extra information about the element, displayed as a tooltip when hovering over the element. |
translate | Specifies whether the content of the element should be translated. Possible values are "yes" or "no". |
HTML Attributes | Global Attributes | Event Attributes |
---|---|---|
To view the full list | To view the full list | To view the full list |
elements | |||||
---|---|---|---|---|---|
<fieldset> | Yes | Yes | Yes | Yes | Yes |
Improve Our Platform
Did you find what you were looking for?
Learn how to contribute.Last updated on by our contributors.
View this page on GitHub• Report an issue with this content