why is # used in css code example

Example 1: what is a css selector

h1 {
  color: red;
}

In this CSS code example that sets the color of all h1s to red 
the "h1" is the selctor because we are applying this style to 
the h1s.

Example 2: . and # in css

<!DOCTYPE html>
<html>
<head>
<style>
.classname {
  background-color: green;
  color: white;
}
#idname {
  background-color: pink;
  color: white;
}
</style>
</head>
<body>
<div class="classname">I am  green colour<div>
<div id="idname">I am  pink colour</div>
</body>
</html>