Display a Red Asterisk before a Label in JSF for Required Fields

Last Updated on


For the most part, this is a generic CSS/HTML tip but this article demonstrates how to display a red asterisk for labels in JSF for required fileds.

Software Environment

  • Windows 7 Professional SP1
  • Eclipse – Kepler Release
  • Java 1.7 (1.7.0_67 – Windows x86)
  • JSF 2.2
    • Downloaded, and referenced as part of a Dynamic Web Project in Eclipse
  • Primefaces 4.0
    • Downloaded fromĀ www.primefaces.org
    • Place it in the project in WebContent\WEB-INF\lib and reference it

The Red Asterisk

To create a red asterisk that displays before any labels in JSF for required fields, simply create an inline CSS.

You may place this in your .xhtml file just like you would in a normal html file. Alternatively, you can put this in an external CSS file and simply reference it from you page.

Using Your Inline CSS

Just below your inline CSS, use styleClass to reference the style class.

Karl San Gabriel

Karl San Gabriel

Professional Software Developer