In HTML and CSS, an ID (identifier) is a unique attribute used to identify an individual element on a webpage. Each ID must be unique within the document, distinguishing one element from all others.
In HTML, the ID attribute uniquely identifies an element.
<div id="uniqueID">This is a box with a border and padding.</div>
id
attribute is placed inside an HTML tag to give that element a unique identifier.In CSS, you can use IDs to target and style specific HTML elements:
#uniqueID { /*CSS styles for the element with the ID "uniqueID"*/ border: 1px solid #000; padding: 10px; }
#
) is used followed by the ID name.Example:-
<html>
<head>
<style>
#highlight {
color: red;
font-weight: bold;
}
#uniqueID {
/*CSS styles for the element with the ID "uniqueID"*/
border: 1px solid #000;
padding: 10px;
}
</style>
</head>
<body>
<!-- HTML content with applied classes -->
<p id="highlight">This text is styled using the 'highlight' class.</p>
<div id="uniqueID">This is a box with a border and padding.</div>
</body>
</html>
Result:-