Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
Selects the element with id="tutorials" with CSS
The CSS ID selector uses the hash symbol (#) followed by an ID name to select a specific element. Since IDs must be unique within a page, this selector targets exactly one element.
Syntax
#id-name {
property: value;
}
Example
The following example selects the element with id="tutorials" and applies a red border −
<!DOCTYPE html>
<html>
<head>
<style>
#tutorials {
border: 3px solid red;
padding: 15px;
background-color: #f9f9f9;
}
</style>
</head>
<body>
<h1>Tutorialspoint</h1>
<h2>Learning</h2>
<p id="tutorials">Tutorials on web dev, programming, database, networking, etc.</p>
<p>Every tutorial has lessons with illustrations and figures.</p>
</body>
</html>
The paragraph with id="tutorials" displays with a red border, gray background, and 15px padding. Other paragraphs remain unchanged.
Conclusion
The ID selector (#) targets a specific element using its unique ID attribute. Remember that each ID should only be used once per HTML document.
Advertisements
