What is HTML class Attribute?

HTML, HTML Attributes , , 0 Comments

The class attribute is very important as it is a part of global attribute in HTML and used to allow CSS and JavaScript to select the specific HTML element.

In CSS you can use CSS class selectors dot (.) and DOM method in JavaScript like: document.getElementsByClassName.

Tag Support

You can use class attribute on all the elements in HTML.

Example

<div class="tagcloud">
    <a href="https://buginit.com/tag/html/" class="tag-cloud-link">
        HTML
    </a>
    <a href="https://buginit.com/tag/html-attributes/" class="tag-cloud-link">
        HTML Attributes
    </a>
    <a href="https://buginit.com/tag/html-global-attributes/" class="tag-cloud-link">
        HTML Global Attributes
    </a>
</div>
<p class="important">Note that this is an important paragraph. :)</p>

Note: you can also use multiple classes

Multiple Classes Example

<div class="tagcloud">
    <a href="https://buginit.com/tag/html/" class="tag-cloud-link tag-link-4 tag-link-position-1">
        HTML
    </a>
    <a href="https://buginit.com/tag/html-attributes/" class="tag-cloud-link tag-link-6 tag-link-position-2">
        HTML Attributes
    </a>
    <a href="https://buginit.com/tag/html-global-attributes/" class="tag-cloud-link tag-link-7 tag-link-position-3">
        HTML Global Attributes
    </a>
</div>
<p class="important bold">Note that this is an important paragraph. :) and also bold</p>

Browser Support

Attribute
classYesYesYesYesYes

Spread the love

Leave a Reply

avatar
  Subscribe  
Notify of