+ 4
What is the use of 'id' and 'class' tag???
Plzzz someone explain me in simple words
16 Respuestas
+ 4
If you are creating 12 buttons, and the first 4 should have a red background, other 4 should have a green background, and the remaining four should have a yellow background, you would give a class of your own choice to each button that you wanna style, so i would give the first four buttons a class of "red-button", and inside css, i can grab these 4 buttons with a single class, and give it some styles, which would apply to each button with that class.
.red-button {
background-color: red;
}
Now, if i wanna change the styles of a particular red button, i can give that button an id, lets suppose "different-red-button"
#different-red-button {
/* some styles */
}
Keep in mind, we use dots (.) to grab classes, and # to grab ids.
+ 3
Id's and classes are created for the purpose of identification when it comes to applying a style (CSS) and or adding some behavior (JavaScript) to a particular field, section, or what so ever in the HTML document.
+ 2
- id is unique for every HTML Tag
- id is denoted by #idName
- class is may or may not be the same for HTML Tag
- class is denoted by .className
- ID & Class are use to apply CSS on selected tag using id & class
+ 2
One Id is use only time.
Example: <div id="one"> this is content </div> // this is correct
<div id="one"> this is 2nd content </div> // this is an error
//single Id is use only one time if you use id in the html document then you need to make multiple id for each tag
OR
single id use single time in tag
But class can use multiple times
<div class="one"> this is content </div> // this is correct
<div class="one"> this is 2nd content </div>
//Here "one" is class and we are using single class in multiple tag
+ 1
Mohammad Danish Id and class are an attribute not tag!
In Html for an element ID name starts with the “#” symbol followed by a unique name assigned to it. On the other hand class assigned to an element has its name starts with “.” followed by class name. Only one ID selector can be attached to an element. Multiple class selectors can be attached to an element.
Hope it helps you.
I accept any request.
+ 1
Mohammad Danish yeah, giving id or class wont make any difference, UNLESS you have applied some styles on that id or class.
+ 1
Id and class are attributes you can use them in css for example when you have lot of tags with same name , like this <h1> and <h1> you use class or id to distinguish between them
+ 1
They are attributes to value of a variable
+ 1
Basically id is used for javascript and the class is used in css .But you can also use it alternatively as your wish but it is convenient to use the first one.
0
So, basically 'id' & 'class' attributes will not make any change to your HTML file (only html file)???
0
Id work as unique but class can use multiple if u want group a set of element class is better
Use id in paticular element
0
In html 'id' is for only one tag from which we can style the innerhtml of tag and class can be common for many tags
0
Using of id is to make that as unique it will help you to select while doing style and class is similar to id but it is more than that a class may contain many id
To define "id" in css we use '#id_name' where as for "class" in css we use '.classname'
0
id is a unique identifier to the html element, no more than one element can have the same id, whereas class is mainly used for css to apply styles (rules) to multiple elements which are sharing the same class name, both id and class names can be used to trigger events on those elemnts using javascript and so on ...