Jobnewse
HTML legend Tag Examples

HTML legend Tag Examples

HTML stands for Hypertext Markup Language and it is the standard markup language used for creating web pages. HTML is a cornerstone technology for the World Wide Web and it provides the structure and semantic meaning to the content of web pages. One of the HTML tags that play a significant role in organizing the content of web pages is the <legend> tag. HTML legend Tag Examples

The <legend> tag is used to create a caption or title for a fieldset element. The fieldset element is used to group related form controls together on a web page. The <legend> tag helps to describe the purpose or meaning of the fieldset and provides context for the form controls that are contained within it.

The syntax for the <legend> tag is as follows: HTML legend Tag Examples

<fieldset>
  <legend>Enter your personal details</legend>
  <label for="name">Name:</label>
  <input type="text" id="name" name="name"><br>
  <label for="email">Email:</label>
  <input type="email" id="email" name="email"><br>
</fieldset>

In the example above, the <legend> tag is used to create a caption for the fieldset element. The text “Enter your personal details” is displayed above the form controls that are contained within the fieldset.

It is important to note that the <legend> tag should be used with the <fieldset> tag and should not be used outside of a fieldset. The fieldset and legend elements provide valuable information to users of assistive technologies, such as screen readers, by providing a clear and organized structure to the form controls on a web page.

In summary, the <legend> tag is an important HTML element that provides context and structure to the form controls on a web page. It should be used with the <fieldset> tag to group related form controls together and provide a clear and organized structure to the content of web pages.

CSS Style Design

The <fieldset> tag in HTML is used to group related form controls together on a web page, and it can be styled with CSS to enhance its appearance and make it more visually appealing. Here are some examples of CSS properties that can be used to style an <fieldset> element:
  1. border: You can use the border property to add a border around the fieldset element. For example:
fieldset {
  border: 1px solid #ccc;
}
  1. padding: You can use the padding property to add space between the content of the fieldset and its border. For example:
fieldset {
  padding: 10px;
}
  1. margin: You can use the margin property to add space between the fieldset and other elements on the page. For example:
fieldset {
  margin-bottom: 20px;
}
  1. background-color: You can use the background-color property to add a background color to the fieldset. For example:
fieldset {
  background-color: #f8f8f8;
}
  1. font-size and font-weight: You can use the font-size and font-weight properties to change the size and weight of the text inside the fieldset. For example:
fieldset {
  font-size: 16px;
  font-weight: bold;
}
  1. box-shadow: You can use the box-shadow property to add a shadow effect to the fieldset. For example:
fieldset {
  box-shadow: 2px 2px 5px #ccc;
}

These are just a few examples of the CSS properties that can be used to style a <fieldset> element. By using these properties, you can customize the appearance of the fieldset to match the overall design of your web page.

2 thoughts on “HTML legend Tag Examples”

Leave a Comment

Your email address will not be published. Required fields are marked *

x
Scroll to Top
Enable Notifications    OK No thanks