HTML id attribute is used to define a unique id for a html element. This id can be further use to identify the element when linking with CSS.
HTML Id Syntax
The id attribute is written in html element tag. Then it is used in head section within <style> tag to link the element with css properties.
<style> #idname { CSS properties; } </style>
Note: The id name is case sensitive and it should not contain whitespaces . Each html element should have a unique id.
<!DOCTYPE html> <html> <head> <style> #food { text-align: center; background-color: blue; } #para{ border: 2px solid black; } </style> </head> <body> <div id="food"> <h2>Icecream</h2> <p>Mixture of milk cream and delicious flavors.</p> </div> <p id="para"> I love to eat icecream</p> </body> </html>
Comments are closed.