A class name can be shared among multiple HTML elements, whereas an id name must be unique and assigned to only one HTML element on the page.
Example
<style> /* Style the element with the id “myHeader” */ #myHeader { background-color: lightblue; color: black; padding: 40px; text-align: center; } /* Style all elements with the class name “city” */ <!– An element with a unique id –> <h1 id=”myHeader”>My Cities</h1> <!– Multiple elements with same class –> <h2 class=”city”>London</h2> <p>London is the capital of England.</p> <h2 class=”city”>Paris</h2> <p>Paris is the capital of France.</p> <h2 class=”city”>Tokyo</h2> <p>Tokyo is the capital of Japan.</p> |