---
schema_version: "1"
id: 074af325c38ed2eeb05f6707c9dc14ad5e33c505d7ae0d6dc0eaaa959abcfb11
title: Use a Custom Stylesheet in a Visualforce Email Template
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/platform/salesforce-pages-developers-guide/guides/pages/email-and-templates/pages-email-templates-stylesheets.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/guide/pages-email-templates-stylesheets.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 92d4fe03929d7b73c77c5ef402923890dbb5b3fd0fd9a4ae3e2ca1ee2f815957
products:
  - Visualforce Developer Guide
  - Platform Developer Content
---

# Use a Custom Stylesheet in a Visualforce Email Template

By default, Visualforce email templates always use the standard look and feel of other Salesforce components. However, you can extend or overwrite these styles by defining your own stylesheet.

Unlike other Visualforce pages, Visualforce email templates cannot use referenced [page styles](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/styling/pages-styling.md) or [static resources](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/resources/pages-resources.md). Although the CSS appears to render in the email template preview pane, it does not appear the same to the recipients of your email. You must define your style using CSS within `<style>` tags.

**note:** Email clients can limit CSS styling. Always test Visualforce email templates with your company’s email client on both web and mobile platforms.

This example changes the font of your email to Courier, adds a border to the table, and changes the color of the table rows.

<!-- otherprops: set_clipboard -->
```apex_page
<messaging:emailTemplate recipientType="Contact"
	relatedToType="Account"
	subject="Case report for Account: {!relatedTo.name}"
	replyTo="support@acme.com">

	<messaging:htmlEmailBody>
		<html>
			<head>
				<style type="text/css">
					body {font-family: Courier; size: 12pt;}
			
					table {
						border-width: 5px;
						border-spacing: 5px;
						border-style: dashed;
						border-color: #FF0000;
						background-color: #FFFFFF;
					}
			
					td {
						border-width: 1px;
						padding: 4px;
						border-style: solid;
						border-color: #000000;
						background-color: #FFEECC;
					}
			
					th { 
						color: #000000;
						border-width: 1px ;
						padding: 4px ;
						border-style: solid ;
						border-color: #000000;
						background-color: #FFFFF0;
					}
				</style>
			</head>
			<body>
				<p>Dear {!recipient.name},</p>
				<table border="0" >
					<tr>
						<th>Case Number</th><th>Origin</th>
						<th>Creator Email</th><th>Status</th>
					</tr>
					<apex:repeat var="cx" value="{!relatedTo.Cases}">
						<tr>
							<td>
								<a href="https://MyDomain_login_URL/{!cx.id}">
									{!cx.CaseNumber}
								</a>
							</td>
							<td>{!cx.Origin}</td>
							<td>{!cx.Contact.email}</td>
							<td>{!cx.Status}</td>
						</tr>
					</apex:repeat> 
				</table>
			</body>
		</html>
	</messaging:htmlEmailBody>
</messaging:emailTemplate>
```

![An example of the HTML preview of an email template](https://developer.salesforce.com/media/salesforce-pages-developers-guide/pages_email_templates_stylesheet.jpg "Example of the Rendered Visualforce Email Template")

## Define Visualforce Stylesheets in a Custom Component

Although you cannot reference an external stylesheet in a Visualforce email template, you can place the style definitions within a [custom component](https://developer.salesforce.com/docs/platform/salesforce-pages-developers-guide/comp-cust/pages-comp-cust.md) that can be referenced in other places. For example, you can modify the previous example to place the style information in a component named `EmailStyle`.

<!-- otherprops: apex_page -->
```markup
<apex:component access="global">
	<head>
		<style type="text/css">
			body {font-family: Courier; size: 12pt;}
	
			table {
				border-width: 5px;
				border-spacing: 5px;
				border-style: dashed;
				border-color: #FF0000;
				background-color: #FFFFFF;
			}
	
			td {
				border-width: 1px;
				padding: 4px;
				border-style: solid;
				border-color: #000000;
				background-color: #FFEECC;
			}
	
			th { 
				color: #000000;
				border-width: 1px ;
				padding: 4px ;
				border-style: solid ;
				border-color: #000000;
				background-color: #FFFFF0;
			}
		</style>
	</head>
</apex:component>
```

Then, in the Visualforce email template, you can reference just that component:

```visualforce
<messaging:htmlEmailBody>
	<html>
		<c:EmailStyle />
		<body>
			<p>Dear {!recipient.name},</p>
			...
		</body>
	</html>
</messaging:htmlEmailBody>
```

**note:** Any `<apex:component>` tags used within a Visualforce email template must have an access level of `global`.

