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.

   CSS properties;

Note: The id name is case sensitive and it should not contain whitespaces . Each html element should have a unique id.

<!DOCTYPE html>
#food {
      text-align: center;
      background-color: blue;

border: 2px solid black;


<div id="food">
  <p>Mixture of milk cream and delicious flavors.</p>
<p  id="para"> I love to eat icecream</p>


Note: You can also assign a class instead of html id.

Comments are closed.