Basic Selectors

Element, Class, Id and Universal

SelectorExampleSelects
elementpall <p> elements
.class.introall elements with class="intro"
#id#firstnamethe element with id="firstname"
**all elements
element.classp.introonly <p> elements with class intro
groupingh1, h2, pall h1, h2 and p elements

Example

Example

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
  <style>
    p { color: #555; }
    .highlight { background: yellow; }
    #main-title { color: #04AA6D; }
    h2, h3 { font-family: Georgia, serif; }
  </style>
</head>
<body>

<h1 id="main-title">Selectors</h1>
<h2>A heading 2</h2>
<p>A normal paragraph.</p>
<p class="highlight">A highlighted paragraph.</p>
<h3 class="highlight">Classes work on any element</h3>

</body>
</html>

Result