zgrizzly_7
zgrizzly_7

Reputation: 803

Which kind of attribute can support a html element?

Can ALL html components (elements and tab) support ALL kind attributes? For example: Is it possible to add a attribute class to a <option> tab from a <select> element?

Upvotes: 2

Views: 135

Answers (4)

Araldy
Araldy

Reputation: 88

In HTML the are some global attributes that are accepted by almost all html tags, but there are some attributes that are especially for one kind of tag. For example you cant use the "autofocus" attribute in a "p" tag.

The tag could support the class attribute and the tag as well. Cause according to the W3SCHOOL both of them accept global attribute.

Heres some documentation that will help you a lot:

And for the next time if you will like to know what attributed could a tag support you just have to look the tag at the W3 SCHOOL And at the bottom of the page you will see what kind of attributed could the tag support(you will see a capture on this answers that will show you what im talking about).

For example:

Heres the select tag reference:SELECT.

As you can see at the bottom of the article you will see all the attribute(general attributes, global attributes, event attributes) for the select tag.ATTRIBUTES FOR SELECT

Upvotes: 0

A DEv
A DEv

Reputation: 340

Not all html components support all attributes. For option, you cannot add class... But still you can apply css...Please check this below post option css

Upvotes: 0

Guruprasad J Rao
Guruprasad J Rao

Reputation: 29683

You can see it here what kind of attributes are accepted by what type of elements.

and for your question - option can have class attribute since it is a Global_Attribute

Upvotes: 2

Luke
Luke

Reputation: 23690

No is the answer, they don't all accept every possible attribute, but there are global attributes such as class which do apply to all tags.

If you look at the specification for the elements on W3, you can see the attributes (including global attributes) that a tag can accept.

Here's the spec for <select>: http://dev.w3.org/html5/spec-preview/the-select-element.html

The attributes that a tag can have is dependent on the version of HTML that you're using (as defined within your <!DOCTYPE>) and I would imagine the browser compliance with the spec.

It's also worth noting that you can have your own custom attributes which start with data- in order to store your own values. EG:

<select data-animal-type="elephant">

As stated in the comments it isn't invalid to have additional attributes, but they don't necessarily serve a purpose other than how they are utilized by the developer.

Upvotes: 2

Related Questions