Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are valid attributes for the DIV element in HTML?

Tags:

What are all the valid DIV attributes?

Based on this link, it appears only class, id, title. Is that correct? Meaning, the for attribute and others is not valid for DIV?

like image 201
JasonK Avatar asked Feb 02 '10 16:02

JasonK


People also ask

What are the attributes of div tag in HTML?

The <div> tag defines a division or a section in an HTML document. The <div> tag is used as a container for HTML elements - which is then styled with CSS or manipulated with JavaScript. The <div> tag is easily styled by using the class or id attribute. Any sort of content can be put inside the <div> tag!

Is div A valid HTML tag?

The <div> tag is an empty container that is used to define a division or a section. It does not affect the content or layout and is used to group HTML elements to be styled with CSS or manipulated with scripts.


1 Answers

See W3C specs:

  • id, class (document-wide identifiers)
  • lang (language information), dir (text direction)
  • title (element title)
  • style (inline style information)
  • align (alignment)
  • onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

for is for label and specifies the id attribute of the input element to which the label applies.

See also the HTML5 specs:

The div element has no special meaning at all. It represents its children. It can be used with the class, lang, and title attributes to mark up semantics common to a group of consecutive elements.

Note: Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

like image 56
Sinan Ünür Avatar answered Sep 30 '22 18:09

Sinan Ünür