Software Development

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


Mostly, this is a generic CSS/HTML tip, but this article demonstrates how to display a red asterisk for labels in JSF for required fields.

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
    • 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 in a normal HTML file. Alternatively, you can put this in an external CSS file and simply reference it from your page.

Using Your Inline CSS

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

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like