element supports many global attributes that support the additional attributes mentioned below.
1. disabled
The ‘disabled’ attribute uses ‘disabled’ as its value. When this attribute is used, it indicates that the group of elements for which this attribute is used is to be disabled.
Below is an example code excerpt using the fieldset element with one of its attributes, ‘disabled’.
Code:
<fieldset style="background:#e1eff2;" disabled="disabled">
<legend>Personal Information:</legend>
<div><label>Name:</label><input type="text"></div>
<div><label>Email:</label><input type="text"></div>
<div><label>DOB:</label><input type="text"></div>
<div><label>Place:</label><input type="text"></div>
</fieldset>
Output:
Observe that since we set the attribute’s value for ‘disabled’ as ‘disabled’, all the child elements are disabled that is, not editable.
2. form
The ‘form’ attribute is used to include one or more identifiers of different forms. It defines these identifiers to which our group of related elements will belong or belongs to. The ‘form’ attribute uses form IDs to define the forms. If there is more than one form identifier, they are all included and separated by spaces.
In other words, this is an attribute that takes its value from the ‘id’ attribute of form/forms elements to make the fieldset their parts, even when the fieldset is defined outside the form.
The form attribute is only supported in Opera 12 and earlier versions.
3. name
The ‘name’ attribute defines a name for the grouped items or joined a group of elements. This attribute uses ‘text’ as its value. This ‘name’ does not get displayed in the browser; its usage is limited to the work of scripts.
Below is an example of a fieldset with a ‘name’ attribute.
Code:
<form>
<fieldset style="background:#e1eff2;" name="PersonalInformation" >
<legend>Personal Information:</legend>
<div><label>Name:</label><input type="text"></div>
<div><label>Email:</label><input type="text"></div>
<div><label>DOB:</label><input type="text"></div>
<div><label>Place:</label><input type="text"></div>
</fieldset>
<br />
<button type = "button" onclick="form.PersonalInformation.style.backgroundColor='LIGHTSALMON'"> Change background color of fieldset</button>
</form>
Output:
Observe, while we gave our fieldset an attribute, ‘name’ and value as ‘Personal Information; It does not get displayed in the browser. But we used the name attribute of the
element at the background for script work.
When we click the button saying “Change background color of fieldset”, the form responds as follows:
HTML Fieldset Tag in CSS Styling
Like any other HTML element,
element can also be altered for visual effects. The HTML tags or elements can contain one or more properties. These added attributes or properties provide the browsers with more data or information about the elements’ effects. The attributes generally consist of a property name and its assigned value, for example;
<strong>style="color:black";</strong>
The properties that can be used to alter the look and feel of the
include font styles, font families, size, weight, among others.
Below is another example using the above-mentioned properties. CSS can do wonders. Observe the before and after-effects.
Without CSS
Code:
<form>
<fieldset style="background:#e1eff2"; name="PersonalInformation" >
<legend>Personal Information:</legend>
<div><label>Name:</label><input type="text"></div>
<div><label>Email:</label><input type="text"></div>
<div><label>DOB:</label><input type="text"></div>
<div><label>Place:</label><input type="text"></div>
</fieldset>
<br />
<button type = "button" onclick="form.PersonalInformation.style.backgroundColor='LIGHTSALMON'"> Change background color of fieldset</button>
</form>
Output:
With CSS
Code:
<form>
<fieldset style="background:#e1eff2"; name="PersonalInformation" >
<legend>Personal Information:</legend>
<div><label>Name:</label><input type="text"></div>
<div><label>Email:</label><input type="text"></div>
<div><label>DOB:</label><input type="text"></div>
<div><label>Place:</label><input type="text"></div>
</fieldset>
<br />
<button type = "button" onclick="form.PersonalInformation.style.backgroundColor='LIGHTSALMON'"> Change background color of fieldset</button>
</form>
Output:
Conclusion
The and tags are the most underused tags while creating web forms. The tag allows every radio or checkbox or text box grouped together to be labeled as a whole while also being separately labeled. The and elements are helpful when assisting technology like JAWS is being used. It’s known that many screen readers read legend text first and then the label texts.
The above is the detailed content of Fieldset Tag in HTML. For more information, please follow other related articles on the PHP Chinese website!