In the Cascading Style sheet (CSS), we can easily select an element with the specific id by using the # symbol followed by id.
JavaScript can access an element with the given ID by using the "getElementById()" method.
The id attribute is used to specify the unique ID for an element of the HTML document.
It allocates the unique identifier which is used by the CSS and the JavaScript for performing certain tasks.
In the Cascading Style sheet (CSS), we can easily select an element with the specific id by using the # symbol followed by id.
JavaScript can access an element with the given ID by using the "getElementById()" method.
<tagname id="id-value"> Content goes here.... </tagname>
<!DOCTYPE html> <html> <head> <title> Example of Id attribute in CSS </title> <style> #Cars { padding: 10px; background-color: lightblue; color: black; text-align: center; } #Bikes { padding: 10px; background-color: lightGreen; text-align: center; } </style> </head> <body> <p> Use CSS to style an element with the id: </p> <h2 id="Cars"> Cars </h2> <h2 id="Bikes"> Bikes </h2> </body> </html>
Use CSS to style an element with the id:
Cars
Bikes