What is Class attribute and how it use in HTML?
Today I will tell you the use of class attribute in html.
So let’s start.....
Today I will tell you the use of class attribute in html.
So let’s start.....
Class Attribute
Every HTML element can
also carry a class attribute. Sometimes, rather than uniquely identifying one
element within a document, you will want a way to identify several elements as
being different from the other elements on the page. If you want to make change
in one paragraph like style color etc not affected the whole page just these
particular paragraphs then you have to use class attribute for achieving this
purpose. Then use this class name in css languages to make it different from
other.
For example, you might have some paragraphs of
text that contain information that is more important than others and want to
distinguish these elements, or you might want to differentiate between links
that point to other pages on your own site and links that point to external sites.
To do this you can use the class attribute. Its value should describe the class
it belongs to. In the example on the left, key paragraphs have a class
attribute whose value is important.
Mostly class attribute
used in div tag to separate the text format using css. by using class attribute
inside div tag we are able to change the particular paragraph to give it
specific format like color, background , text color which is different to the sounding
paragraphs.
The class attribute on
any element can share the same value. So, in this example, the value of
important could be
Used on headings and
links, too.
By default, using these attributes does not affect the
presentation of an element. It will only change their appearance if there is a
CSS rule that indicates it should be displayed differently.
In this example, CSS has been applied to
make elements with a class attribute whose value is important uppercase and
elements with a class attribute whose value is admittance red
If you would like to indicate that an
element belongs to several classes, you can separate class names with a space.