In this tutorial you will learn about the CSS ID Selector and its application with practical example.
HTML Entities can be accessed using their ID attribute. So we can use ID as a selector for the HTML Entities, and we can create a set of styling rules for the HTML entity having the defined value for their ID attribute.
Table Of Contents−
Syntax:
1 |
#[ID Name] { property:value; ...} |
Example:
1 2 3 |
#nav{ color:red; } |
This CSS rule be applied to HTML Element having ID attribute value “nav”
1 |
<p id="nav">This is an ID selector example.</p> |
We can define styling rules for a selected HTML Tag having specific value for their ID attribute
1 2 3 |
p#nav{ color: #ccc; } |
Means this CSS can be applied only on <p></p> tag having ID=”nav”