html

Can I Apply a CSS Style to an Element Name?

In HTML, the name attribute is used for specifying a name for an element in HTML, such as age, date, and many more. It is also utilized in the form of reference when the data in a form is submitted. Furthermore, the user can style the element “name” by accessing it with the help of a selector and then, apply CSS properties, including “height”, “color”, “background-color”, “font-size” and many more according to your choice.

This post will demonstrate about applying the CSS style to an element name.

How Can I Apply a CSS Style to an Element Name?

Yes, the user can style the element name with the help of various CSS properties by applying them. To do so, try out the given step-by-step procedure.

Step 1: Create a div Container

Initially, utilize the “<div>” tag to create a div container. Then, add a class attribute and assign a name to the class according to your preferences. In this scenario, the “div-main” is set as the class name.

Step 2: Add Heading

Next, insert the heading with the help of “<h1>” and embed text in between the heading opening and closing tag.

Step 3: Create a Form

To create a form, follow this procedure:

  • First, add a “<form>” element that is used for creating a form.
  • Next, utilize the “<label>” element for embedding the label, and then, the “<input>” element is used for allocating the form fields.
  • The type of the input is set as “text” which specifies the text field in the form.
  • The “placeholder” allocates a short hint that defines the value to show on the input field.
  • name” attribute defines an expected reference when the form is submitted.
  • The “min” specifies the minimum value for an “<input>” element.
  • The input type “submit” is utilized to add a button to the form:
<div class="div-main">
 <h1>CSS Style to an Element Name</h1>
 <form>
  <label>Your Name</label>
  <input type="text" placeholder="Enter Your Name"><br><br><br>
  <label >Your Gender</label>
  <input type="text" placeholder="Enter Your Gender"><br><br><br>
  <label > Your Age</label>
  <input type="number" name="age" min="10" placeholder="Enter Your Age"><br><br><br>
  <input type="Button" value="submit">
 </form>
</div>

It can be noticed that the form has been created successfully:

Step 4: Access Class

Now, access the class by utilizing the class selector with the class name. For instance, “.div-main” is used for accessing the main class.

Step 5: Apply CSS Properties

After accessing the class, apply the CSS properties for styling:

.div-main{
 border-style: dashed;
 margin: 20px 70px;
 padding: 20px;
 background-color: rgb(177, 245, 222);
}

Here:

  • border-style” property is utilized for adding a style to the element border.
  • margin” defines a space outside the defined border around the element, where the first value is “20px” and adds space at the top and bottom, and the second value, “70px”, sets the space on the left and right sides.
  • padding” defines a space inside of the boundary.
  • background-color” is utilized for specifying the color at the backside of the element.

Output

Step 6: Access Element “name”

Now, access the “<input>” element “name”. For instance, we will access the input field with the name “age”.

Step 7: Apply CSS Style on Element “name”

Next, apply CSS styles on the element “name” by utilizing the listed properties:

input[name="age"] {
 height: 40px;
 color: rgb(243, 242, 242);
 background-color: rgb(241, 34, 7);
 font: bold;
 font-size: large;
}

In the above code:

  • height” property allocates height to the selected element.
  • color” is used to specify the element text’s color.
  • background-color” is used for setting the element’s background color.
  • font” is set as “bold” to make it prominent.
  • font-size” specifies the size of the font. When the font size is modified it also changes the sizes of the font.

As a result, the element “age” will be styled as follows:

We have taught you about applying the CSS style to the element name.

Conclusion

Yes, the user can style the element name with the help of different CSS properties by applying them. To do so, first, create a form and add multiple fields. Then, access the “name” element from the “<input>” tag by utilizing the “input[name= “”]” syntax. Then, apply the required CSS properties. This post explained the method for styling the element name by applying CSS properties.

About the author

Hafsa Javed