+ 3
what is the differences between "id", "class" and "span"?
please explain the difference between" id", "class" and "span" in HTML, CSS, JS
5 Réponses
+ 10
An ID is a unique element there can only be one element with that particular ID. You can apply a class to many elements at the same time so that they will all be styled according to the class.
+ 7
A span is an html tag. ex. <span></span> class and Id are tag attributes for css identification. Tag names like span can also be used to identify an element in css. An id has to be unique there can only be one of that element with a given id. For a class it can be placed on multiple elements to style them all in a particular way through css.
+ 4
The differences are pretty big!
for example, the <span> tag is used as a container for text, class is used to connect to the css code, and the one in its charm adds styles to your page!
id, is needed in order for some languages such as javascript, and php could directly contact the html code :)
+ 2
Id and class is attributes of element, span is element itself. So you can have such html
<span class="yo" id="mate">Text</span> only "Text" will be displayed in browser, but you can refer to this element in your css or Js by it id or class.
+ 1
If I had to choose between using "id" or "class" in my code, what would be a deciding factor? Do they play the same role?