- HTML class Attribute
- Using The class Attribute
- Example
- London
- Paris
- Tokyo
- Example
- My Important Heading
- The Syntax For Class
- Example
- Multiple Classes
- Example
- London
- Different Elements Can Share Same Class Different HTML elements can point to the same class name. In the following example, both and point to the «city» class and will share the same style: Example Use of The class Attribute in JavaScript The class name can also be used by JavaScript to perform certain tasks for specific elements. JavaScript can access elements with a specific class name with the getElementsByClassName() method: Example Click on a button to hide all elements with the class name «city»: Don’t worry if you don’t understand the code in the example above. You will learn more about JavaScript in our HTML JavaScript chapter, or you can study our JavaScript Tutorial. Chapter Summary The HTML class attribute specifies one or more class names for an element Classes are used by CSS and JavaScript to select and access specific elements The class attribute can be used on any HTML element The class name is case sensitive Different HTML elements can point to the same class name JavaScript can access elements with a specific class name with the getElementsByClassName() method Источник : The Content Division element The HTML element is the generic container for flow content. It has no effect on the content or layout until styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like Flexbox is applied to its parent element). Try it As a «pure» container, the element does not inherently represent anything. Instead, it’s used to group content so it can be easily styled using the class or id attributes, marking a section of a document as being written in a different language (using the lang attribute), and so on. Attributes This element includes the global attributes. Note: The align attribute is obsolete; do not use it anymore. Instead, you should use CSS properties or techniques such as CSS Grid or CSS Flexbox to align and position elements on the page. Usage notes Accessibility concerns The element has an implicit role of generic , and not none. This may affect certain ARIA combination declarations that expect a direct descendant element with a certain role to function properly. Examples A simple example div > p > Any kind of content here. Such as < p> , < table> . You name it! p > div > Result A styled example This example creates a shadowed box by applying a style to the using CSS. Note the use of the class attribute on the to apply the style named «shadowbox» to the element. HTML div class = " shadowbox" > p > Here's a very interesting note displayed in a lovely shadowed box.p > div > CSS .shadowbox width : 15em; border : 1px solid #333; box-shadow : 8px 8px 5px #444; padding : 8px 12px; background-image : linear-gradient ( 180deg, #fff, #ddd 40%, #ccc) ; > Result Technical summary Content categories Flow content, palpable content. Permitted content Flow content. Or (in WHATWG HTML): If the parent is a element: one or more elements followed by one or more elements, optionally intermixed with and elements. Tag omission None, both the starting and ending tag are mandatory. Permitted parents Any element that accepts flow content. Or (in WHATWG HTML): element. Implicit ARIA role No corresponding role Permitted ARIA roles Any DOM interface HTMLDivElement Specifications Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 17, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник What are valid attributes for the DIV element in HTML? 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 ? I’m really disappointed that this got answered. With the w3c out there, easily searchable and easily discoverable. We are just proliferating this kind of lazy question by providing answers. p.s. to those who answered, this isn’t even a programming question! @Lazarus — I think the best comment would be to educate JasonK on the proper place to find this information like Sinan Ünür has done. Rather than calling his question lazy. He may be new to web development and not actually know where to find the answer. @Lazarus — Sinan Ünür did educate him on how to find this information. «See W3C specs:» He was also helpful in providing the information in his answer rather than blindly linking to the W3C spec. I’m sorry, but this site becomes useless when one answers with «Search using Google». or refuses to answer at all when they know the information. @Lazarus This is the first search result from google, «non-lazy» people in the future searching for this will come here. 4 Answers 4 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. 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. Источник
- Different Elements Can Share Same Class Different HTML elements can point to the same class name. In the following example, both and point to the «city» class and will share the same style: Example Use of The class Attribute in JavaScript The class name can also be used by JavaScript to perform certain tasks for specific elements. JavaScript can access elements with a specific class name with the getElementsByClassName() method: Example Click on a button to hide all elements with the class name «city»: Don’t worry if you don’t understand the code in the example above. You will learn more about JavaScript in our HTML JavaScript chapter, or you can study our JavaScript Tutorial. Chapter Summary The HTML class attribute specifies one or more class names for an element Classes are used by CSS and JavaScript to select and access specific elements The class attribute can be used on any HTML element The class name is case sensitive Different HTML elements can point to the same class name JavaScript can access elements with a specific class name with the getElementsByClassName() method Источник : The Content Division element The HTML element is the generic container for flow content. It has no effect on the content or layout until styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like Flexbox is applied to its parent element). Try it As a «pure» container, the element does not inherently represent anything. Instead, it’s used to group content so it can be easily styled using the class or id attributes, marking a section of a document as being written in a different language (using the lang attribute), and so on. Attributes This element includes the global attributes. Note: The align attribute is obsolete; do not use it anymore. Instead, you should use CSS properties or techniques such as CSS Grid or CSS Flexbox to align and position elements on the page. Usage notes Accessibility concerns The element has an implicit role of generic , and not none. This may affect certain ARIA combination declarations that expect a direct descendant element with a certain role to function properly. Examples A simple example div > p > Any kind of content here. Such as < p> , < table> . You name it! p > div > Result A styled example This example creates a shadowed box by applying a style to the using CSS. Note the use of the class attribute on the to apply the style named «shadowbox» to the element. HTML div class = " shadowbox" > p > Here's a very interesting note displayed in a lovely shadowed box.p > div > CSS .shadowbox width : 15em; border : 1px solid #333; box-shadow : 8px 8px 5px #444; padding : 8px 12px; background-image : linear-gradient ( 180deg, #fff, #ddd 40%, #ccc) ; > Result Technical summary Content categories Flow content, palpable content. Permitted content Flow content. Or (in WHATWG HTML): If the parent is a element: one or more elements followed by one or more elements, optionally intermixed with and elements. Tag omission None, both the starting and ending tag are mandatory. Permitted parents Any element that accepts flow content. Or (in WHATWG HTML): element. Implicit ARIA role No corresponding role Permitted ARIA roles Any DOM interface HTMLDivElement Specifications Browser compatibility BCD tables only load in the browser See also Found a content problem with this page? This page was last modified on Jul 17, 2023 by MDN contributors. Your blueprint for a better internet. MDN Support Our communities Developers Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation. Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license. Источник What are valid attributes for the DIV element in HTML? 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 ? I’m really disappointed that this got answered. With the w3c out there, easily searchable and easily discoverable. We are just proliferating this kind of lazy question by providing answers. p.s. to those who answered, this isn’t even a programming question! @Lazarus — I think the best comment would be to educate JasonK on the proper place to find this information like Sinan Ünür has done. Rather than calling his question lazy. He may be new to web development and not actually know where to find the answer. @Lazarus — Sinan Ünür did educate him on how to find this information. «See W3C specs:» He was also helpful in providing the information in his answer rather than blindly linking to the W3C spec. I’m sorry, but this site becomes useless when one answers with «Search using Google». or refuses to answer at all when they know the information. @Lazarus This is the first search result from google, «non-lazy» people in the future searching for this will come here. 4 Answers 4 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. 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. Источник
- Different Elements Can Share Same Class
- Example
- Use of The class Attribute in JavaScript
- Example
- Chapter Summary
- : The Content Division element
- Try it
- Attributes
- Usage notes
- Accessibility concerns
- Examples
- A simple example
- Result
- A styled example
- HTML
- CSS
- Result
- Technical summary
- Specifications
- Browser compatibility
- See also
- Found a content problem with this page?
- MDN
- Support
- Our communities
- Developers
- What are valid attributes for the DIV element in HTML?
- 4 Answers 4
HTML class Attribute
The HTML class attribute is used to specify a class for an HTML element.
Multiple HTML elements can share the same class.
Using The class Attribute
The class attribute is often used to point to a class name in a style sheet. It can also be used by a JavaScript to access and manipulate elements with the specific class name.
In the following example we have three elements with a class attribute with the value of «city». All of the three elements will be styled equally according to the .city style definition in the head section:
Example
London
London is the capital of England.
Paris
Paris is the capital of France.
Tokyo
Tokyo is the capital of Japan.
In the following example we have two elements with a class attribute with the value of «note». Both elements will be styled equally according to the .note style definition in the head section:
Example
My Important Heading
This is some important text.
Tip: The class attribute can be used on any HTML element.
Note: The class name is case sensitive!
Tip: You can learn much more about CSS in our CSS Tutorial.
The Syntax For Class
To create a class; write a period (.) character, followed by a class name. Then, define the CSS properties within curly braces <>:
Example
Create a class named «city»:
London is the capital of England.
Paris is the capital of France.
Tokyo is the capital of Japan.
Multiple Classes
HTML elements can belong to more than one class.
To define multiple classes, separate the class names with a space, e.g. . The element will be styled according to all the classes specified.
In the following example, the first element belongs to both the city class and also to the main class, and will get the CSS styles from both of the classes:
Example
London
Different Elements Can Share Same Class
Different Elements Can Share Same Class
Different HTML elements can point to the same class name.
In the following example, both and
point to the «city» class and will share the same style:
Example
Use of The class Attribute in JavaScript
The class name can also be used by JavaScript to perform certain tasks for specific elements.
JavaScript can access elements with a specific class name with the getElementsByClassName() method:
Example
Click on a button to hide all elements with the class name «city»:
Don’t worry if you don’t understand the code in the example above.
You will learn more about JavaScript in our HTML JavaScript chapter, or you can study our JavaScript Tutorial.
Chapter Summary
- The HTML class attribute specifies one or more class names for an element
- Classes are used by CSS and JavaScript to select and access specific elements
- The class attribute can be used on any HTML element
- The class name is case sensitive
- Different HTML elements can point to the same class name
- JavaScript can access elements with a specific class name with the getElementsByClassName() method
: The Content Division element
The HTML element is the generic container for flow content. It has no effect on the content or layout until styled in some way using CSS (e.g. styling is directly applied to it, or some kind of layout model like Flexbox is applied to its parent element).
Try it
As a «pure» container, the element does not inherently represent anything. Instead, it’s used to group content so it can be easily styled using the class or id attributes, marking a section of a document as being written in a different language (using the lang attribute), and so on.
Attributes
This element includes the global attributes.
Note: The align attribute is obsolete; do not use it anymore. Instead, you should use CSS properties or techniques such as CSS Grid or CSS Flexbox to align and position elements on the page.
Usage notes
Accessibility concerns
The element has an implicit role of generic , and not none. This may affect certain ARIA combination declarations that expect a direct descendant element with a certain role to function properly.
Examples
A simple example
div> p> Any kind of content here. Such as <p>, <table>. You name it! p> div>
Result
A styled example
This example creates a shadowed box by applying a style to the using CSS. Note the use of the class attribute on the to apply the style named «shadowbox» to the element.
HTML
div class="shadowbox"> p>Here's a very interesting note displayed in a lovely shadowed box.p> div>
CSS
.shadowbox width: 15em; border: 1px solid #333; box-shadow: 8px 8px 5px #444; padding: 8px 12px; background-image: linear-gradient(180deg, #fff, #ddd 40%, #ccc); >
Result
Technical summary
Content categories | Flow content, palpable content. |
---|---|
Permitted content | Flow content. Or (in WHATWG HTML): If the parent is a element: one or more elements followed by one or more elements, optionally intermixed with and elements. |
Tag omission | None, both the starting and ending tag are mandatory. |
Permitted parents | Any element that accepts flow content. Or (in WHATWG HTML): element. |
Implicit ARIA role | No corresponding role |
Permitted ARIA roles | Any |
DOM interface | HTMLDivElement |
Specifications
Browser compatibility
BCD tables only load in the browser
See also
Found a content problem with this page?
This page was last modified on Jul 17, 2023 by MDN contributors.
Your blueprint for a better internet.
MDN
Support
Our communities
Developers
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998– 2023 by individual mozilla.org contributors. Content available under a Creative Commons license.
What are valid attributes for the DIV element in HTML?
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 ?
I’m really disappointed that this got answered. With the w3c out there, easily searchable and easily discoverable. We are just proliferating this kind of lazy question by providing answers. p.s. to those who answered, this isn’t even a programming question!
@Lazarus — I think the best comment would be to educate JasonK on the proper place to find this information like Sinan Ünür has done. Rather than calling his question lazy. He may be new to web development and not actually know where to find the answer.
@Lazarus — Sinan Ünür did educate him on how to find this information. «See W3C specs:» He was also helpful in providing the information in his answer rather than blindly linking to the W3C spec. I’m sorry, but this site becomes useless when one answers with «Search using Google». or refuses to answer at all when they know the information.
@Lazarus This is the first search result from google, «non-lazy» people in the future searching for this will come here.
4 Answers 4
- 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.
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.