CSS Selectors
Normal selector
<head>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<h3>This is h3</h3>
<p>Satheesh Pandian</p>
</body>
Class selector(.)
You can select any HTML element as a normal selector
<head>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<h3>This is h3</h3>
<p class="class-name">Satheesh Pandian</p>
</body>
In the above example, though p
element is defined in CSS file, class-name
value has been applied due to high priority.
class selector starts with .
in the CSS file. You can apply class name to multiple HTML elements.
<head>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<p class="class-name">Satheesh Pandian</p>
<h3>This is h3</h3>
<h5 class="class-name">This is h5</h5>
</body>
ID selector (#)
<head>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<h3>This is h3</h3>
<p id="satheesh-id">Satheesh Pandian</p>
</body>
ID selector starts with #
in the CSS file. This is unique, and you CANNOT apply id more than one HTML element.
Attribute selector
<head>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<p class="class-name" draggable="true">Satheesh Pandian</p>
<h3>This is h3</h3>
<p draggable="true">This is draggable</p>
</body>
Here, draggable is an attribute. You can select any attribute