What is the difference between id and class in CSS?

Looking forward for a detailed explanation with reference to current trends

  • Abhishek Kumar
  • Abhishek Kumar
  • |
  • 16 May
  • |
  • |
  • 5 Answers

text limit upto 4000

  • 0

    No is not to diffrent but some satution and calling method makes it diffrent .

  • 0

    The difference between an ID and a class is that an ID can be used to identify one element, whereas a class can be used to identify more than one. You can also apply a selector to a specific HTML element by simply stating the HTML selector first, so p.jam { /* whatever */ } will only be applied to paragraph elements that have the class “jam”.

  • 0

    #id and .class are selectors used to target specific element(s) in your HTML for CSS styling. Where a .class can be assigned to multiple elements in your HTML; ids MUST be unique (multiple elements cannot have the same id).
    In HTML, you declare your id or class on the element like any other attribute: <div class="special"> . An element can have both Id and class. In CSS, a class selector is a name preceded by a full stop (“.”) and an ID selector is a name preceded by a hash character (“#”).

    <h2 id="title" class="recipe">My Recipe</h2>
    <p class="recipe">This is my recipe for making chocolate purely with salt.</p>
    <p class="recipe">Mmm mm mmmmm</p>

    <a href="#title">Go to Top</a>

    #title{font-size: 32px;}
    .recipe{color: grey;}

  • 0

    Id selector define with a hash(#) sign but class selector define with a dot(.) ID is used for identify one element but class is used for identify multiple elemets.

  • 0

    id and class both are selectors in CSS. An id is always unique while a class can be the same in different HTML elements. While applying the CSS, you can use ids by a hash (#) followed by id and classes can be used by a dot(.) followed by a class name.

    <p id="p1">Youth4work</p>
    <p id="p2">Best Site to gain and share knowledge.</p>
    <span class="sp"> Youth4work </span>
    <div class="sp"> Youth4work </div>

    #p1{ color:red;}
    #p2 { color:blue;}
    .sp{ background-color:yellow }

Did Not Get The Answer? 
Contact people of Talent-CSS directly from here