CSS class selectors – define style by class name

The CSS class selector matches element having a specific class name as one of the classes in attribute class. This can be used to specify CSS style based on class name.

Here is the syntax for defining style using class selector.

.classname { style properties } /*all elements having class classname*/

div.classname { style properties } /*div element having class classname*/

Example – style using class selector

/* div.box can also be used to be more specific */
.box {
  width: 100px; height:100px;
  background-color: lightgreen;

<div class="box foo bar">
  Hello world



Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments