JSF - h:outputStylesheet


The h:outputStylesheet tag renders an HTML element of the type "link" with type "text/css". This tag is used to add external stylesheet file to JSF page.


<h:outputStylesheet library = "css" name = "styles.css" /> 

Rendered Output

<link type = "text/css" rel = "stylesheet"  
   href = "/helloworld/javax.faces.resource/styles.css.jsf?ln = css" /> 

Example Application

Let us create a test JSF application to test the above tag.

Step Description
1 Create a project with a name helloworld under a package com.tutorialspoint.test as explained in the JSF - First Application chapter.
2 Create resources folder under src → main folder.
3 Create css folder under src → main → resources folder.
4 Create styles.css file under src → main → resources → css folder.
5 Modify styles.css file as explained below.
6 Modify pom.xml as explained below.
7 Modify home.xhtml as explained below. Keep rest of the files unchanged.
8 Compile and run the application to make sure business logic is working as per the requirements.
9 Finally, build the application in the form of war file and deploy it in Apache Tomcat Webserver.
10 Launch your web application using appropriate URL as explained below in the last step.




<project xmlns = "http://maven.apache.org/POM/4.0.0" 
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0
   <name>helloworld Maven Webapp</name>


<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns = "http://www.w3.org/1999/xhtml"
   xmlns:f = "http://java.sun.com/jsf/core"    
   xmlns:h = "http://java.sun.com/jsf/html">
      <title>JSF Tutorial!</title>
      <h:outputStylesheet library = "css" name = "styles.css"  /> 
      <h2>h:outputStylesheet example</h2>
      <hr />
         <div class = "message">Hello World!</div>


Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce the following result.

JSF h:outputStylesheet