CSS ::before Selector

What is CSS ::before Selector?

CSS ::before element selector add the content to the beginning of parent element.
Added new content will inherited of parent properties.

Syntax

General syntax of ::before selector,

/* CSS2 syntax */
element:before {
  property: value;
  property: value;
  ...
}

/* CSS3 syntax */
element::before {
  property: value;
  property: value;
  ...
}

Example

CSS :before selector add the content to the beginning of parent element.

<!DOCTYPE html>
<html>
<head>
  <title>CSS ::after Selector</title>
  <style>
    p.image::after{
      content: " - After word";
      color: #FF0000;
    }
  </style>
</head>
<body>
  <p class="image">This example for ::after pseudo element</p>
</body>
</html>

Run it...   »

Browser Compatibility

  • Google Chrome 2+
  • Mozilla Firefox 3.5+
  • Internet Explorer 9+
  • Opera 9.5+
  • Safari 1.3+

Note: Here details of browser compatibility with version number may be this is bug and not supported. But recommended to always use latest Web browser.