HTML - attributes - class

revision:


Content

"class" attribute: specifies one or more class names for an element syntax some examples


"class" attribute: specifies one or more class names for an element

top

The class attribute is mostly used to point to a class in a style sheet. However, it can also be used by JavaScript (via the HTML DOM) to make changes to HTML elements with a specified class.
It can be used on any HTML element.s The class name is case sensitive! Name of a class can be used with multiple elements in an HTML document.


syntax

top

<element class="classname">

classname specifies one or more class names for an element. To specify multiple classes, separate the class names with a space, e.g. <span class="left important">. This allows to combine several CSS classes for one HTML element.
Naming rules are as follows: must begin with a letter A-Z or a-z, and can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), and underscores ("_")


some examples

top

Header 4

A paragraph.

Note that this is an important paragraph. :)

codes:
                    <h4 class="intro" style="margin-left:3vw;">Header 4</h4>
                    <p class="spec">A paragraph.</p>
                    <p class="important spec">Note that this is an important paragraph. :)</p>
                    <style>
                        h4.intro {color: blue;}
                        p.important {color: green;}       
                    </style>
                

London

Paris

Tokyo

codes:
                    <h4 style="margin-left:3vw;" class="city main">London</h4>
                    <h4 style="margin-left:3vw;" class="city">Paris</h4>
                    <h4 style="margin-left:3vw;" class="city">Tokyo</h4>
                    <style>
                        .city { background-color: tomato; color: white; padding: 10px;} 
                        .main { text-align: center;}       
                    </style>